有时候需要得到硬件信息绑定用户登录
代码如下:
private string GetProcessSerialNumber()
{
try
{
ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher(
new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"),
new System.Management.ObjectQuery("SELECT * FROM Win32_processor")
).Get();
if (ProcessCollection != null && ProcessCollection.Count > )
{
StringBuilder sb = new StringBuilder();
foreach (ManagementObject mo in ProcessCollection)
{
sb.Append(mo["ProcessorId"]);
}
return sb.ToString();
}
else
{
return "";
}
}
catch (Exception)
{
return "";
}
} private string GetMotherBoardSerialNumber()
{
try
{
ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher(
new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"),
new System.Management.ObjectQuery("SELECT * FROM Win32_bios")
).Get();
if (ProcessCollection != null && ProcessCollection.Count > )
{
StringBuilder sb = new StringBuilder();
foreach (ManagementObject mo in ProcessCollection)
{
sb.Append(mo["SerialNumber"]);
}
return sb.ToString();
}
else
{
return "";
}
}
catch (Exception)
{
return "";
}
} private string GetHardDisk0SerialNumber()
{
try
{
ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher(
new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"),
new System.Management.ObjectQuery("SELECT * FROM Win32_DiskDrive")
).Get();
if (ProcessCollection != null && ProcessCollection.Count > )
{
StringBuilder sb = new StringBuilder();
foreach (ManagementObject mo in ProcessCollection)
{
if(mo["Name"].ToString().IndexOf("DRIVE0")!=-)
sb.Append(mo["SerialNumber"]);
}
return sb.ToString();
}
else
{
return "";
}
}
catch (Exception)
{
return "";
}
} private string GetNetWorkMACSerialNumber()
{
try
{
ManagementObjectCollection ProcessCollection = new ManagementObjectSearcher(
new System.Management.ManagementScope("\\\\localhost\\root\\cimv2"),
new System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
).Get();
if (ProcessCollection != null && ProcessCollection.Count > )
{
StringBuilder sb = new StringBuilder();
foreach (ManagementObject mo in ProcessCollection)
{
if (mo["IPEnabled"].ToString() == "True")
sb.Append(mo["MacAddress"]);
}
return sb.ToString();
}
else
{
return "";
}
}
catch (Exception)
{
return "";
}
}