WMI实现查询CPU序列号和硬盘ID
WMI实现查询CPU序列号和硬盘ID
首先,引用中添加.net组件 System.Management
接着,窗口放一个listbox组件,设置View属性为Details
添加两个列“名称”“ID”
然后添加代码(这份代码是用WMI实现的,具体可以参考MSDN)
接着,窗口放一个listbox组件,设置View属性为Details
添加两个列“名称”“ID”
然后添加代码(这份代码是用WMI实现的,具体可以参考MSDN)
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Management;
9
10namespace Systeminfo
11{
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17 }
18
19 private void Form1_Load(object sender, EventArgs e)
20 {
21 SelectQuery selectQuery = new
22 SelectQuery("CIM_DiskDrive");
23 ManagementObjectSearcher searcher =
24 new ManagementObjectSearcher(selectQuery);
25 int listviewsup = listView1.Items.Count;
26 foreach (ManagementObject disk in searcher.Get())
27 {
28 try
29 {
30 //listView1.Items.Add(disk.ToString());
31 listView1.Items.Add(disk.Properties["Caption"].Value.ToString());
32 listView1.Items[listviewsup].SubItems.Add(disk.Properties["DeviceID"].Value.ToString());
33 listviewsup++;
34 }
35 catch { };
36 }
37 SelectQuery selectQuery1 = new
38 SelectQuery("Win32_Processor");
39 ManagementObjectSearcher searcher1 =
40 new ManagementObjectSearcher(selectQuery1);
41 int listviewsup1 = listView1.Items.Count;
42 foreach (ManagementObject disk in searcher1.Get())
43 {
44 try
45 {
46 //listView1.Items.Add(disk.ToString());
47 listView1.Items.Add(disk.Properties["Name"].Value.ToString());
48 listView1.Items[listviewsup1].SubItems.Add(disk.Properties["ProcessorId"].Value.ToString());
49 listviewsup1++;
50 }
51 catch { };
52 }
53 }
54 }
55
56}
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Management;
9
10namespace Systeminfo
11{
12 public partial class Form1 : Form
13 {
14 public Form1()
15 {
16 InitializeComponent();
17 }
18
19 private void Form1_Load(object sender, EventArgs e)
20 {
21 SelectQuery selectQuery = new
22 SelectQuery("CIM_DiskDrive");
23 ManagementObjectSearcher searcher =
24 new ManagementObjectSearcher(selectQuery);
25 int listviewsup = listView1.Items.Count;
26 foreach (ManagementObject disk in searcher.Get())
27 {
28 try
29 {
30 //listView1.Items.Add(disk.ToString());
31 listView1.Items.Add(disk.Properties["Caption"].Value.ToString());
32 listView1.Items[listviewsup].SubItems.Add(disk.Properties["DeviceID"].Value.ToString());
33 listviewsup++;
34 }
35 catch { };
36 }
37 SelectQuery selectQuery1 = new
38 SelectQuery("Win32_Processor");
39 ManagementObjectSearcher searcher1 =
40 new ManagementObjectSearcher(selectQuery1);
41 int listviewsup1 = listView1.Items.Count;
42 foreach (ManagementObject disk in searcher1.Get())
43 {
44 try
45 {
46 //listView1.Items.Add(disk.ToString());
47 listView1.Items.Add(disk.Properties["Name"].Value.ToString());
48 listView1.Items[listviewsup1].SubItems.Add(disk.Properties["ProcessorId"].Value.ToString());
49 listviewsup1++;
50 }
51 catch { };
52 }
53 }
54 }
55
56}
by:wangbin5542
http://www.wowpc.n/
以上可以举列出更多。信息,具体可以查看CIM_ WIM32_