语言吧技术网欢迎您投稿,程序员的世界我懂你!=====>点此登录投搞
当前位置: 首页 >>ASP.NET >>ASP.NET实战 >>C#获取机器码

C#获取机器码

2019/6/24 8:55:32 0人评论 192次 作者:admin

C#获取机器码…

/// <summary>/// 机器码

/// </summary>

public class MachineCode

{

///<summary>

/// 获取cpu序列号

///</summary>

///<returns> string </returns>

public string GetCpuInfo()

{

string cpuInfo = " ";

using (ManagementClass cimobject = new ManagementClass("Win32_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 cimobject1 = new ManagementClass("Win32_DiskDrive"))

{

ManagementObjectCollection moc1 = cimobject1.GetInstances();

foreach (ManagementObject mo in moc1)

{

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("Win32_NetworkAdapterConfiguration"))

{

ManagementObjectCollection moc2 = mc.GetInstances();

foreach (ManagementObject mo in moc2)

{

if ((bool)mo["IPEnabled"] == true)

MoAddress = mo["MacAddress"].ToString();

mo.Dispose();

}

}

return MoAddress.ToString();

}

}


相关文章

CopyRight:2007-2018 语言吧 备案ICP:湘ICP备09009000号-15 http://www.yuyanba.com
欢迎【康乃狄克州 】的朋友
内容与素材部分来源于网络,如有侵权请告知删除
分享按钮