主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:217次
远程重启计算机(C#)
首先添加对 System.Management的引用
然后代码入下:
ConnectionOptions op = new ConnectionOptions ( ) ;
op.Username ="wgscd";'或者你的帐号(注意要有管理员的权限)
op.Password = "wgscd" ; '你的密码
ManagementScope scope = new ManagementScope( "\\\\" + "106.54.20.1" + "\\root\\wgscd",

op ) ;
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 mobj in queryCollection1 )
{
string [ ] str= { "" } ;
mobj.InvokeMethod ( "Reboot" , str ) ;
}
}
catch
{

}




关键字词: