WMI,ManagementObjectSearcher,Detecting Management Events,访问本地主机的一些信息和服务WMI.

更多关于WMI的用法:http://singlepine.cnblogs.com/articles/299457.html

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

WMI,ManagementObjectSearcher,Detecting Management Events,访问本地主机的一些信息和服务WMI.

//

WMI的应用:

 

using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;
using  System.IO;
using  System.IO.Compression;
using  System.Collections;
using  System.Collections.Specialized;
using  System.Xml.Serialization;
using  System.Threading;
using  System.ComponentModel;
using  System.Reflection;
using  System.Security.Policy;
using  System.Configuration;
using  System.Diagnostics;
using  System.Management;
namespace  ConsoleApplication1
{
    
class  Program
    {
        
public   const  String IP_Enabled  =   " IPEnabled " ;
        
public   const  String IP_Address  =   " IPAddress " ;
        
public   const  String IP_Subnet  =   " IPSubnet " ;
        
public   const  String DNS_HostName  =   " DNSHostName " ;
        
public   const  String DNS_Domain  =   " DNSDomain " ;
        
public   static   void  Main()
        {
            EnumerateAllNetworkAdapters();
            Console.Read();
        }
        
public   static   void  OutPutLines( object  obj)
        {
            Console.WriteLine(DateTime.Now.ToString());
        }
        
public   static   void  EnumerateAllNetworkAdapters()
        {
            ManagementObjectSearcher DemoQuery 
=
            
new  ManagementObjectSearcher( " SELECT * FROM Win32_NetworkAdapterConfiguration " );
            ManagementObjectCollection DemoQueryCollection 
=  DemoQuery.Get();
            
foreach  (ManagementObject DemoManager  in  DemoQueryCollection)
            {
                Console.WriteLine(
" Description :  "   +  DemoManager[ " Description " ]);
                Console.WriteLine(
" MacAddress :  "   +  DemoManager[ " MacAddress " ]);

                
if  (DemoManager[IP_Address]  is   string [])
                {
                    String[] IPAddresses 
=  DemoManager[IP_Address]  as  String[];
                    String[] IPSubnets 
=  DemoManager[IP_Subnet]  as  String[];
                    Console.WriteLine(DNS_HostName 
+   "  :  "   +  DemoManager[DNS_HostName]);
                    Console.WriteLine(DNS_Domain 
+   "  :  "   +  DemoManager[DNS_Domain]);
                    
foreach  (String IPAddress  in  IPAddresses)
                    {
                        Console.WriteLine(IP_Address 
+   "  :  "   +  IPAddress);
                    }
                    
foreach  (String IPSubnet  in  IPSubnets)
                    {
                        Console.WriteLine(IP_Subnet 
+   "  :  "   +  IPSubnet);
                    }
                }

            }
        }
    }
}

 

你可能感兴趣的:(object)