用C#获取硬盘序列号,CPU序列号,网卡MAC地址
private string[] GetMoc()
{
string[] str = new string[3];
ManagementClass mcCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection mocCpu = mcCpu.GetInstances();
foreach(ManagementObject m in mocCpu)
{
str[0] = m["ProcessorId"].ToString();
}
ManagementClass mcHD = new ManagementClass("win32_logicaldisk");
ManagementObjectCollection mocHD = mcHD.GetInstances();
foreach(ManagementObject m in mocHD)
{
if(m["DeviceID"].ToString() == "C:")
{
str[1] = m["VolumeSerialNumber"].ToString();
break;
}
}
ManagementClass mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mocMAC = mcMAC.GetInstances();
foreach(ManagementObject m in mocMAC)
{
if((bool)m["IPEnabled"])
{
str[2] = m["MacAddress"].ToString();
break;
}
}
return str;
}
{
string[] str = new string[3];
ManagementClass mcCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection mocCpu = mcCpu.GetInstances();
foreach(ManagementObject m in mocCpu)
{
str[0] = m["ProcessorId"].ToString();
}
ManagementClass mcHD = new ManagementClass("win32_logicaldisk");
ManagementObjectCollection mocHD = mcHD.GetInstances();
foreach(ManagementObject m in mocHD)
{
if(m["DeviceID"].ToString() == "C:")
{
str[1] = m["VolumeSerialNumber"].ToString();
break;
}
}
ManagementClass mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mocMAC = mcMAC.GetInstances();
foreach(ManagementObject m in mocMAC)
{
if((bool)m["IPEnabled"])
{
str[2] = m["MacAddress"].ToString();
break;
}
}
return str;
}
http://u.huoban001.com/space.php