计算机硬件信息 码,c# 获取计算机硬件信息的示例代码

///

/// 获取CPU的编号

///

/// CPU的编号

public static List GetCPUID()

{

List lstInfo =new List();

ManagementClass cimobject = new ManagementClass("Win32_Processor");

ManagementObjectCollection moc = cimobject.GetInstances();

foreach (ManagementObject mo in moc)

{

string cpuInfo = mo.Properties["ProcessorId"].Value.ToString();//cpu序列号

lstInfo.Add(cpuInfo);

}

return lstInfo;

}

///

/// 获取硬件信息

///

/// 硬件信息集合

public static List GetHardDiskInfo()

{

List lstInfo = new List();

ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");

ManagementObjectCollection moc1 = cimobject1.GetInstances();

foreach (ManagementObject mo in moc1)

{

string HDid = (string)mo.Properties["Model"].Value;

lstInfo.Add(HDid);

}

return lstInfo;

}

///

/// 获取Mac地址

///

/// Mac地址集合

public static List GetMacAddress()

{

List lstInfo = new List();

ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");

ManagementObjectCollection moc = mc.GetInstances();

foreach (ManagementObject mo in moc)

{

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

{

lstInfo.Add(mo["MacAddress"].ToString());

}

mo.Dispose();

}

return lstInfo;

}

///

/// 获取主板信息

///

/// 主板信息集合

public static List GetBoard()

{

List lstInfo = new List();

ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_baseboard");

foreach (ManagementObject mo in mos.Get())

{

lstInfo.Add(mo["SerialNumber"].ToString());

break;

}

return lstInfo;

}

以上就是c# 获取计算机硬件信息的示例代码的详细内容,更多关于c# 获取硬件信息的资料请关注我们其它相关文章!

时间: 2020-10-26

你可能感兴趣的:(计算机硬件信息,码)