1. //獲取CPU名稱
2. private void button1_Click(object sender, EventArgs e)
3. {
4. string CPUName = "";
5. ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Processor");//Win32_Processor CPU處理器
6. foreach (ManagementObject mo in mos.Get())
7. {
8. CPUName = mo["Name"].ToString();
9. }
10. mos.Dispose();
11. label1.Text = CPUName;
12. }
13. //獲取顯卡數量,及顯卡名稱
14. private void button2_Click(object sender, EventArgs e)
15. {
16. string DisplayName = "";
17. ManagementClass m = new ManagementClass("Win32_VideoController");
18. ManagementObjectCollection mn = m.GetInstances();
19. DisplayName = "顯卡數量:" + mn.Count.ToString() + " ";
20. ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_VideoController");//Win32_VideoController 顯卡
21. int count = 0;
22. foreach (ManagementObject mo in mos.Get())
23. {
24. count++;
25. DisplayName += "第" + count.ToString() + "張顯卡名稱:" + mo["Name"].ToString() + " ";
26. }
27. mn.Dispose();
28. m.Dispose();
29. label2.Text = DisplayName;
30. }
31. //內存條數量,及大小
32. private void button3_Click(object sender, EventArgs e)
33. {
34. string PhysicalMemory = "";
35. ManagementClass m = new ManagementClass("Win32_PhysicalMemory");//內存條
36. ManagementObjectCollection mn = m.GetInstances();
37. PhysicalMemory = "物理內存條數量:" + mn.Count.ToString() + " ";
38. double capacity = 0.0;
39. int count = 0;
40. foreach (ManagementObject mo1 in mn)
41. {
42. count++;
43. capacity = ((Math.Round(Int64.Parse(mo1.Properties["Capacity"].Value.ToString()) / 1024 / 1024 / 1024.0, 1)));
44. PhysicalMemory += "第" + count.ToString() + "張內存條大小:" + capacity.ToString() + "G ";
45. }
46. mn.Dispose();
47. m.Dispose();
48. label3.Text = PhysicalMemory;
49. }
50. //硬盤大小
51. private void button4_Click(object sender, EventArgs e)
52. {
53. string DiskDrive = "硬盤為:";
54. ManagementClass m = new ManagementClass("win32_DiskDrive");//硬盤
55. ManagementObjectCollection mn = m.GetInstances();
56. double capacity = 0.0;
57. foreach (ManagementObject mo1 in mn)
58. {
59. capacity += Int64.Parse(mo1.Properties["Size"].Value.ToString()) / 1024 / 1024/ 1024;
60. }
61. mn.Dispose();
62. m.Dispose();
63. label4.Text = DiskDrive + capacity.ToString();
64. }