首页 > 开发 > 综合 > 正文

C#远程重启计算机

2024-07-21 02:27:17
字体:
来源:转载
供稿:网友


首先添加对 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
   {
   
   }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表