命名空间:
using System.Management;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Microsoft.Win32;
/// <summary>
/// CPU序列号
/// </summary>
/// <returns></returns>
public string GetCpuInfo()
{
string cpuInfo = " ";
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
return cpuInfo.ToString();
}
///
/// 获取硬盘ID
///
/// string
public string GetHDid()
{
string HDid = " ";
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach (ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
}
return HDid.ToString();
}
///
/// 获取网卡硬件地址
///
/// string
public string GetMoAddress()
{
string MoAddress = " ";
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();
}
- 本文标题: ASp.NET 获取CUP序列号,硬盘ID,网卡地址
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.