首先添加對 system.management的引用
然后代碼入下:
connectionoptions op = new connectionoptions ( ) ;
op.username ="wgscd";’或者你的帳號(注意要有管理員的權限)
op.password = "wgscd" ; ’你的密碼
managementscope scope = new managementscope( "http:////" + "106.54.20.1" + "http://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
{
}
新聞熱點
疑難解答