#region 获得主机相关信息 // 得到主板序列号
private string GetMotherBoardSerialNumber()
{
string SerialNumber = "";
ManagementClass mc = new ManagementClass("WIN32_BaseBoard");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
SerialNumber = mo["SerialNumber"].ToString();
break;
}
return SerialNumber.Replace(" ","");
}
// 得到CPU序列号
private string GetMotherProcessorNumber()
{
string CPUCode = "";
ManagementClass mcCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection mocCpu = mcCpu.GetInstances();
foreach(ManagementObject m in mocCpu)
{
CPUCode = m["ProcessorId"].ToString();
}
return CPUCode.Replace(" ", "");
}
// 得到硬盘序列号
private string GetMotherLogicaldiskNumber()
{
string logicaldiskcode = "";
ManagementClass mcHD = new ManagementClass("win32_logicaldisk");
ManagementObjectCollection mocHD = mcHD.GetInstances();
foreach (ManagementObject m in mocHD)
{
if (m["DeviceID"].ToString() == "C:")
{
logicaldiskcode = m["VolumeSerialNumber"].ToString();
break;
}
}
return logicaldiskcode.Replace(" ", "");
}
// 得到网卡MAC地址
private string GetNetworkAdapterConfiguration()
{
string NetworkAdapterConfiguration = "";
ManagementClass mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection mocMAC = mcMAC.GetInstances();
foreach(ManagementObject m in mocMAC)
{
if((bool)m["IPEnabled"])
{
NetworkAdapterConfiguration = m["MacAddress"].ToString();
break;
}
}
return NetworkAdapterConfiguration;
}
#endregion