zoukankan      html  css  js  c++  java
  • 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
       {
       
       }

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    django虚拟环境中报E: 无法定位软件包 sqliteman
    创建django项目
    Django虚拟环境安装
    python学习笔记(三)
    python学习笔记(二)
    python学习笔记(一)
    python 类属性和实例属性
    决策树的基本ID3算法
    KNN算法的简单实现
    webClient
  • 原文地址:https://www.cnblogs.com/Athrun/p/824457.html
Copyright © 2011-2022 走看看