/// <summary>
/// 機器碼
/// </summary>
public class MachineCode
{
/// <summary>
/// 獲取cpu序列號
/// </summary>
/// <returns> string </returns>
public string GetCpuInfo()
{
string cpuInfo = ;
using (ManagementClass cimobject = new ManagementClass(Win_Processor))
{
ManagementObjectCollection moc = cimobjectGetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = moProperties[ProcessorId]ValueToString();
moDispose();
}
}
return cpuInfoToString();
}
/// <summary>
/// 獲取硬盤ID
/// </summary>
/// <returns> string </returns>
public string GetHDid()
{
string HDid = ;
using (ManagementClass cimobject = new ManagementClass(Win_DiskDrive))
{
ManagementObjectCollection moc = cimobjectGetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)moProperties[Model]Value;
moDispose();
}
}
return HDidToString();
}
/// <summary>
/// 獲取網卡硬件地址
/// </summary>
/// <returns> string </returns>
public string GetMoAddress()
{
string MoAddress = ;
using (ManagementClass mc = new ManagementClass(Win_NetworkAdapterConfiguration))
{
ManagementObjectCollection moc = mcGetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo[IPEnabled] == true)
MoAddress = mo[MacAddress]ToString();
moDispose();
}
}
return MoAddressToString();
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11438.html