public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//实例化公共信息模型,这里用于管理与进程相关的信息
ManagementClass mc = new ManagementClass("win32_processor");
//获取公共信息模型中的所有的实例
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
//取出实例中表示CPU的唯一标识
textBox1.Text+=mo["processorid"].ToString()+"\n";
//销毁实例对象
mo.Dispose();
}
}
private void button2_Click(object sender, EventArgs e)
{
//实例化公共信息模型,这里用于管理与网络适配器相关的信息
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
//对于启用的网卡
if ((bool)mo["IPEnabled"] == true)
{
//取出MAC地址的唯一标识
textBox2.Text += mo["MacAddress"].ToString() + "\n";
}
mo.Dispose();
}
}
}