发布网友 发布时间:2024-10-02 11:55
共1个回答
热心网友 时间:2024-11-08 02:42
/// <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 = cimobject GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo Properties[ ProcessorId ] Value ToString();
mo Dispose();
}
}
return cpuInfo ToString();
}
/// <summary>
/// 获取硬盘ID
/// </summary>
/// <returns> string </returns>
public string GetHDid()
{
string HDid = ;
using (ManagementClass cimobject = new ManagementClass( Win _DiskDrive ))
{
ManagementObjectCollection moc = cimobject GetInstances();
foreach (ManagementObject mo in moc )
{
HDid = (string)mo Properties[ Model ] Value;
mo Dispose();
}
}
return HDid ToString();
}
/// <summary>
/// 获取网卡硬件地址
/// </summary>
/// <returns> string </returns>
public string GetMoAddress()
{
string MoAddress = ;
using (ManagementClass mc = new ManagementClass( Win _NeorkAdapterConfiguration ))
{
ManagementObjectCollection moc = mc GetInstances();
foreach (ManagementObject mo in moc )
{
if ((bool)mo[ IPEnabled ] == true)
MoAddress = mo[ MacAddress ] ToString();
mo Dispose();
}
}
return MoAddress ToString();
}
lishixinzhi/Article/program/net/201311/11438