c獲取硬件信息_第1頁
c獲取硬件信息_第2頁
c獲取硬件信息_第3頁
c獲取硬件信息_第4頁
c獲取硬件信息_第5頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、System.Management 命名空間計算機軟件 2008-01-18 20:36:43 閱讀220 評論0  字號:大中小 訂閱提供對大量管理信息和管理事件集合的訪問,這些信息和事件是與根據 Windows 管理規范 (WMI) 結構對系統、設備和應用程序設置檢測點有關的。應用程序和服務可以使用從 ManagementObjectSearcher 和ManagementQuery 派生的類,查詢感興趣的管理信息(例如在磁盤上還剩多少可用空間、當前 CPU 利用率是多少、某一應用程序正連接到哪一數據

2、庫等等);或者應用程序和服務可以使用 ManagementEventWatcher 類預訂各種管理事件。這些可訪問的數據可以來自分布式環境中托管的和非托管的組件。.net下對WMI的操作,非常方便了,記得以前VC6.0下弄,那簡直是痛苦ManagementClass  用法class Program            public static void GetInfo()        &#

3、160;           string cpuInfo = ""/cpu序列號            ManagementClass cimobject = new ManagementClass("Win32_Processor");         &

4、#160;  ManagementObjectCollection moc = cimobject.GetInstances();            foreach (ManagementObject mo in moc)                      

5、      cpuInfo = mo.Properties"ProcessorId".Value.ToString();                Console.WriteLine("CPU序列號:" + cpuInfo.ToString();         &

6、#160;              /獲取硬盤ID            String HDid;            ManagementClass cimobject1 = new ManagementClass("Win32_DiskDri

7、ve");            ManagementObjectCollection moc1 = cimobject1.GetInstances();            foreach (ManagementObject mo in moc1)          

8、;                  HDid = (string)mo.Properties"Model".Value;                Console.WriteLine("硬盤序列號:" + HDid.ToString();

9、60;                       /獲取網卡硬件地址            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); 

10、;           ManagementObjectCollection moc2 = mc.GetInstances();            foreach (ManagementObject mo in moc2)              

11、60;             if (bool)mo"IPEnabled" = true)                    Console.WriteLine("MAC addresst0", mo"MacAddress"

12、.ToString();                mo.Dispose();                            static void Main(string args)&#

13、160;                   GetInfo();            Console.Read();          ManagementObjectSearcher用法/主板  

14、0;     public static void GetMainBoradInfo()                    Console.WriteLine("獲取主板信息");            ManagementObjectSearc

15、her sear = new ManagementObjectSearcher("select * from Win32_baseboard");            foreach (ManagementBaseObject b in sear.Get()                  &#

16、160;         Console.WriteLine("Caption: " + b"Caption".ToString();                Console.WriteLine("CreationClassName : " + b"CreationClassName"

17、;.ToString();                Console.WriteLine("ConfigOptions : " + (string)b"ConfigOptions")0.ToString();                Console.

18、WriteLine("Description  : " + b"Description".ToString();                Console.WriteLine("HostingBoard  : " + b"HostingBoard".ToString();      &

19、#160;         Console.WriteLine("Manufacturer     : " + b"Manufacturer".ToString();                Console.WriteLine("Name   

20、 : " + b"Name".ToString();                Console.WriteLine("Product      : " + b"Product".ToString();          

21、60;     Console.WriteLine("SerialNumber     : " + b"SerialNumber".ToString();                Console.WriteLine("Version       : &q

22、uot; + b"Version".ToString();                Console.WriteLine("PoweredOn   : " + b"PoweredOn".ToString();             &

23、#160;  Console.WriteLine("PoweredOn   : " + b"PoweredOn".ToString();                                 

24、0;         /CPU        public static void GetCPUInfo()                    Console.WriteLine("獲取CPU信息");    

25、60;       ManagementObjectSearcher sear = new ManagementObjectSearcher("select * from Win32_Processor");            foreach (ManagementBaseObject b in sear.Get()       &#

26、160;                    Console.WriteLine("AddressWidth : " + b"AddressWidth".ToString();                Console.Wr

27、iteLine("Architecture  : " + b"Architecture".ToString(); /0 =x86                Console.WriteLine("Availability  : " + b"Availability".ToString(); /3=Running/Full Power &

28、#160;              Console.WriteLine("Caption  : " + b"Caption".ToString();                Console.WriteLine("CpuStatus  

29、;  : " + b"CpuStatus".ToString(); /1=CPU Enabled                Console.WriteLine("CreationClassName   : " + b"CreationClassName".ToString();     

30、0;          Console.WriteLine("CurrentClockSpeed   : " + b"CurrentClockSpeed".ToString();                Console.WriteLine("CurrentVoltage &

31、#160; : " + b"CurrentVoltage".ToString();                Console.WriteLine("DataWidth   : " + b"DataWidth".ToString();          &#

32、160;     Console.WriteLine("Description    : " + b"Description".ToString();                Console.WriteLine("DeviceID    : " + b"DeviceID&q

33、uot;.ToString();                Console.WriteLine("Family     : " + b"Family".ToString();  /2=Unknown             &

34、#160;  Console.WriteLine("L2CacheSize     : " + b"L2CacheSize".ToString();                Console.WriteLine("Manufacturer       : " + b"

35、;Manufacturer".ToString();                Console.WriteLine("MaxClockSpeed      : " + b"MaxClockSpeed".ToString();          &

36、#160;     Console.WriteLine("Level      : " + b"Level".ToString();                Console.WriteLine("Name      : " + b"N

37、ame".ToString();                Console.WriteLine("ProcessorId         : " + b"ProcessorId".ToString();         

38、60;      Console.WriteLine("ProcessorType       : " + b"ProcessorType".ToString(); /3=Central Processor                Console.WriteLine("Revisio

39、n       : " + b"Revision".ToString();                Console.WriteLine("Role       : " + b"Role".ToString();   

40、0;            Console.WriteLine("SocketDesignation       : " + b"SocketDesignation".ToString();                Console.WriteLine("Status        : " + b"Status".ToString();

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論