远程重启计算机(C#)

80酷酷网    80kuku.com

  远程重启计算机(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
{

}




分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: