using System; using System.Management;
namespace WMI2 { /// /// Summary description for Class1. ///
class Class1 { static void Main(string[] args) { Console.WriteLine("Computer details retrieved using Windows Management Instrumentation (WMI)"); Console.WriteLine("mailto:Written%2001/23/02%20By%20John%20O'Donnell%20-%20csharpconsulting@hotmail.com"); Console.WriteLine("=========================================================================");
//连接远程计算机 ConnectionOptions co = new ConnectionOptions(); co.Username = "john"; co.Password = "john"; System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\192.168.1.4\\root\\cimv2", co);
//查询远程计算机 System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher query1 = new ManagementObjectSearcher(ms,oq); ManagementObjectCollection queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 ) { Console.WriteLine("Name : " + mo["name"].ToString()); Console.WriteLine("Version : " + mo["version"].ToString()); Console.WriteLine("Manufacturer : " + mo["Manufacturer"].ToString()); Console.WriteLine("Computer Name : " +mo["csname"].ToString()); Console.WriteLine("Windows Directory : " +mo["WindowsDirectory"].ToString()); }
oq = new System.Management.ObjectQuery("SELECT * FROM Win32_ComputerSystem"); query1 = new ManagementObjectSearcher(ms,oq) ; queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 ) { Console.WriteLine(mo["systemtype"].ToString()); Console.WriteLine("Total Physical Memory : " + mo["totalphysicalmemory"].ToString());
}
oq = new System.Management.ObjectQuery("SELECT * FROM Win32_processor") ;
query1 = new ManagementObjectSearcher(ms,oq) ; queryCollection1 = query1.Get(); foreach( ManagementObject mo in queryCollection1 ) { Console.WriteLine(mo["caption"].ToString()); }
oq = new System.Management.ObjectQuery("SELECT * FROM Win32_bios"); query1 = new ManagementObjectSearcher(ms,oq) ; queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 ) { Console.WriteLine(mo["version"].ToString()); } } } } |