Restart/shut down remote computer

Source: Internet
Author: User

using system;

Using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. text; using system. windows. forms; using system. management; namespace restart Remote Computer {public partial class form1: FORM {public form1 () {initializecomponent ();} private void btn_reboot_click (Object sender, eventargs E) {// define some options for connecting to the remote computer connectionoptions = new connectionoptions (); options. username = textbox2.text; options. password = textbox3.text; managementscope scope = new managementscope ("//" + textbox1.text + "// root // cimv2", options ); try {// connect to the remote computer scope with the given administrator username and password. connect (); objectquery OQ = new objectquery ("select * From win32_operatingsystem"); descriquery1 = new managementobjectsearcher (scope, OQ); managementobjectcollection querycollection1 = query1.get (); foreach (managementobject Mo in querycollection1) {string [] Ss = {""}; If (combobox1.text = "restart") {Mo. invokemethod ("reboot", SS);} If (combobox1.text = "Disable computer") {Mo. invokemethod ("shutdown", SS);} // If (combobox1.text = "deregister") // {// Mo. invokemethod ("logoff", SS); // }}} catch (exception ER) {MessageBox. show ("connection" + textbox1.text + "error, error message:" + er. message) ;}} private void form=load (Object sender, eventargs e) {combobox1.items. add ("restart"); combobox1.items. add ("Disable computer"); // combobox1.items. add ("logout ");}}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.