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;
Restart Remote Computer in namespace
{
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 Options = new connectionoptions ();
Options. Username = textbox2.text;
Options. Password = textbox3.text;
Managementscope scope = new managementscope ("\\\\" + textbox1.text + "\\ Root \ cimv2", options );
Try
{
// Connect the remote computer with the given administrator username and password
Scope. Connect ();
Objectquery OQ = new objectquery ("select * From win32_operatingsystem ");
Managementobjectsearcher query1 = 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 = "logout ")
//{
// Mo. invokemethod ("logoff", SS );
//}
}
}
Catch (exception ER)
{
MessageBox. Show ("connection" + textbox1.text + "error, error message:" + Er. Message );
}
}
Private void form1_load (Object sender, eventargs E)
{
Combobox1.items. Add ("restart ");
Combobox1.items. Add ("Disable computer ");
// Combobox1.items. Add ("deregister ");
}
}
}