C#如何获取主机硬件品牌型号就像鲁大师硬件检测那种

2024-12-02 23:13:42
推荐回答(2个)
回答1:

LZ,我有这方面的代码.但是我自己也不熟悉.可以贴给你看看. ///


/// 获取pc硬件信息
///

///
///
///
public static string GetWMIInfo(string sInfoType, string sWin32_Database)
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select " + sInfoType + " From " + sWin32_Database);
string sResult = "";
foreach (ManagementObject mo in searcher.Get())
{
sResult = mo[sInfoType].ToString().Trim();
}
return sResult;
}
catch
{
return "";
}
}

sInfoType,sWin32_Database 这个参数真心不知道什么意思.但是下面有调用传递的参数,希望能帮到你.
//获取主板序列号
public static string GetBIOSSerialNumber()
{
return GetWMIInfo("SerialNumber", "Win32_BIOS");

}

//获取CPU序列号
public static string GetCPUSerialNumber()
{
return GetWMIInfo("ProcessorId", "Win32_Processor");
}

//获取硬盘序列号
public static string GetHardDiskSerialNumber()
{
return GetWMIInfo("SerialNumber", "Win32_PhysicalMedia");

}

//获取网卡地址
public static string GetNetCardMACAddress()
{
return GetWMIInfo("MACAddress", "Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))");

}

回答2:

你可以试试:WMI