实现效果:
知识运用:
WMI管理类中的ManagementObjectCollection类
ManagementObjectSearcher类的Get方法
和ManagementObject类
ManagementObjectCollection类表示通过WMI检索到的管理对象的不同集合
此集合中的对象为ManagementBaseObject派生类型 包括 ManagementObject和ManagementClass
例:通过使用ManagementClass对象的GetInstances方法获取管理对象集合
ManagementObjectCollection mo = mc.GetInstances();
实现代码:
private void Form1_Load(object sender, EventArgs e) { ManagementClass mc = new ManagementClass("Win32_processor"); ManagementObjectCollection mo = mc.GetInstances(); foreach (ManagementObject m in mo) { textBox1.Text=m["processorid"].ToString(); //textBox2.Text = m["Manufacturer"].ToString(); //textBox3.Text = m["Version"].ToString(); //textBox4.Text = m["Name"].ToString(); } ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_processor"); foreach(ManagementObject m in mos.Get()) { textBox2.Text = m["Manufacturer"].ToString(); //获取CPU制造商名称 textBox3.Text = m["Version"].ToString(); //获取CPU版本号 textBox4.Text = m["Name"].ToString(); //获取CPU产品名称 } }