Q:远程重启计算机
A;ConnectionOptions options = new ConnectionOptions ( ) ;
options.Username ="administrator";
options.Password = "" ;
ManagementScope scope = new ManagementScope( "\\\\" + "10.5.0.5" + "\\root\\cimv2", options ) ;
try
{
scope.Connect ( ) ;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;
ManagementObjectSearcher query1 = new ManagementObjectSearcher ( scope , oq ) ;
//得到WMI控制
ManagementObjectCollection queryCollection1 = query1.Get ( ) ;
foreach ( ManagementObject mo in queryCollection1 )
{
string [ ] ss= { "" } ;
mo.InvokeMethod ( "Reboot" , ss ) ;
}
}
catch
{
}