WMI使用集锦

WMI使用集锦

1.WMI简介
WMI是英文Windows Management Instrumentation的简写,它的功能主要是:访问本地主机的一些信息和服务,可以管理远程计算机(当然你必须要拥有足够的权限),比如:重启,关机,关闭进程,创建进程等。
2.使用时首先添加System.Management.dll,然后引用

using  System.Management;
using  System.Threading; 
3.示例代码
3.1 html代码
< HTML >
    
< HEAD >
        
< title > WMITest </ title >
        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
    
</ HEAD >
    
< body  MS_POSITIONING ="GridLayout" >
        
< form  id ="Form1"  method ="post"  runat ="server" >
            
< FONT  face ="宋体" >
                
< asp:Button  id ="Button1"  style ="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 16px"  runat ="server"
                    Text
="获得本地磁盘的信息"  Width ="152px" ></ asp:Button >
                
< asp:Button  id ="Button2"  style ="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 56px"  runat ="server"
                    Text
="获得指定磁盘的容量"  Width ="144px" ></ asp:Button >
                
< asp:Button  id ="Button3"  style ="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 96px"  runat ="server"
                    Text
="列出机器中所有的共享资源"  Width ="192px" ></ asp:Button >
                
< asp:Button  id ="Button4"  style ="Z-INDEX: 104; LEFT: 8px; POSITION: absolute; TOP: 128px"  runat ="server"
                    Text
="控制让系统中的某个文件夹共享或取消共享"  Width ="264px" ></ asp:Button >
                
< asp:Button  id ="Button5"  style ="Z-INDEX: 105; LEFT: 48px; POSITION: absolute; TOP: 160px"  runat ="server"
                    Text
="获得系统服务的运行状态" ></ asp:Button >
                
< asp:Button  id ="Button6"  style ="Z-INDEX: 106; LEFT: 40px; POSITION: absolute; TOP: 192px"  runat ="server"
                    Text
="通过WMI修改IP,而实现不用重新启动"  Width ="248px" ></ asp:Button >
                
< asp:Button  id ="Button7"  style ="Z-INDEX: 107; LEFT: 24px; POSITION: absolute; TOP: 224px"  runat ="server"
                    Text
="如何利用WMI远程重启远程计算机"  Width ="232px" ></ asp:Button >
                
< asp:Button  id ="Button8"  style ="Z-INDEX: 108; LEFT: 40px; POSITION: absolute; TOP: 264px"  runat ="server"
                    Text
="利用WMI创建一个新的进程"  Width ="192px" ></ asp:Button >
                
< asp:Button  id ="Button9"  style ="Z-INDEX: 109; LEFT: 32px; POSITION: absolute; TOP: 296px"  runat ="server"
                    Text
="如何通过WMI终止一个进程"  Width ="192px" ></ asp:Button >
                
< asp:Button  id ="Button10"  style ="Z-INDEX: 110; LEFT: 32px; POSITION: absolute; TOP: 328px"  runat ="server"
                    Text
="如何用WMI 来获取远程机器的目录以及文件"  Width ="280px" ></ asp:Button >
                
< asp:Button  id ="Button11"  style ="Z-INDEX: 111; LEFT: 424px; POSITION: absolute; TOP: 24px"  runat ="server"
                    Text
="网卡的MAC地址"  Width ="120px" ></ asp:Button >
                
< asp:Button  id ="Button12"  style ="Z-INDEX: 112; LEFT: 456px; POSITION: absolute; TOP: 64px"  runat ="server"
                    Text
="CPU的系列号 "  Width ="104px" ></ asp:Button >
                
< asp:Button  id ="Button13"  style ="Z-INDEX: 113; LEFT: 448px; POSITION: absolute; TOP: 120px"
                    runat
="server"  Text ="主板的系列号" ></ asp:Button >
                
< asp:Button  id ="Button14"  style ="Z-INDEX: 114; LEFT: 472px; POSITION: absolute; TOP: 160px"
                    runat
="server"  Text ="获取硬盘ID" ></ asp:Button >
                
< asp:Button  id ="Button15"  style ="Z-INDEX: 115; LEFT: 448px; POSITION: absolute; TOP: 208px"
                    runat
="server"  Text ="获取本机的用户列表"  Width ="144px" ></ asp:Button ></ FONT >
        
</ form >
    
</ body >
</ HTML >
3.2cs代码
public   class  WMITest : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.Button Button2;
        
protected System.Web.UI.WebControls.Button Button3;
        
protected System.Web.UI.WebControls.Button Button4;
        
protected System.Web.UI.WebControls.Button Button5;
        
protected System.Web.UI.WebControls.Button Button6;
        
protected System.Web.UI.WebControls.Button Button7;
        
protected System.Web.UI.WebControls.Button Button8;
        
protected System.Web.UI.WebControls.Button Button9;
        
protected System.Web.UI.WebControls.Button Button10;
        
protected System.Web.UI.WebControls.Button Button11;
        
protected System.Web.UI.WebControls.Button Button12;
        
protected System.Web.UI.WebControls.Button Button13;
        
protected System.Web.UI.WebControls.Button Button14;
        
protected System.Web.UI.WebControls.Button Button15;
        
protected System.Web.UI.WebControls.Button Button1;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// Put user code to initialize the page here
        }


        
Web Form Designer generated code

        
1.如何用WMI获得指定磁盘的容量

        
2.如何用WMI获得指定磁盘的容量

        
3.如何列出机器中所有的共享资源

        
4.怎样写程控制让系统中的某个文件夹共享或取消共享

        
5.如何获得系统服务的运行状态

        
6.通过WMI修改IP,而实现不用重新启动

        
7.如何利用WMI远程重启远程计算机

        
8.利用WMI创建一个新的进程

        
9.如何通过WMI终止一个进程

        
10.如何用WMI 来获取远程机器的目录以及文件

        
11.网卡的MAC地址

        
12.CPU的系列号

        
13.主板的系列号

        
14.获取硬盘ID

        
15.获取本机的用户列表
    }

你可能感兴趣的:(使用)