C# 获取硬件参数的实现方法
程序员文章站
2023-12-18 10:00:28
c# 获取硬件参数的实现方法
示例代码:
private static string getidentifier(string wmiclass, string...
c# 获取硬件参数的实现方法
示例代码:
private static string getidentifier(string wmiclass, string wmiproperty, string wmimustbetrue) { string result = ""; system.management.managementclass mc = new system.management.managementclass(wmiclass); system.management.managementobjectcollection moc = mc.getinstances(); foreach (system.management.managementobject mo in moc) { if (mo[wmimustbetrue].tostring() == "true") { //only get the first one if (result == "") { try { result = mo[wmiproperty].tostring(); break; } catch { } } } } return result; } private static string getidentifier(string wmiclass, string wmiproperty) { string result = ""; system.management.managementclass mc = new system.management.managementclass(wmiclass); system.management.managementobjectcollection moc = mc.getinstances(); foreach (system.management.managementobject mo in moc) { //only get the first one if (result == "") { try { result = mo[wmiproperty].tostring(); break; } catch { } } } return result; } // cpu id getidentifier("win32_processor", "uniqueid"); //processor id getidentifier("win32_processor", "processorid"); //processor name getidentifier("win32_processor", "name"); //manufacturer getidentifier("win32_processor", "manufacturer"); //bios identifier private static string getbiosid() { return getidentifier("win32_bios", "manufacturer") + getidentifier("win32_bios", "smbiosbiosversion") + getidentifier("win32_bios", "identificationcode") + getidentifier("win32_bios", "serialnumber") + getidentifier("win32_bios", "releasedate") + getidentifier("win32_bios", "version"); } //main physical hard drive id private static string getdiskid() { return getidentifier("win32_diskdrive", "model") + getidentifier("win32_diskdrive", "manufacturer") + getidentifier("win32_diskdrive", "signature") + getidentifier("win32_diskdrive", "totalheads"); } //motherboard id private static string getbaseid() { return getidentifier("win32_baseboard", "model") + getidentifier("win32_baseboard", "manufacturer") + getidentifier("win32_baseboard", "name") + getidentifier("win32_baseboard", "serialnumber"); } //primary video controller id private static string getvideoid() { return getidentifier("win32_videocontroller", "driverversion") + getidentifier("win32_videocontroller", "name"); } //first enabled network card id private static string getmacid() { return getidentifier("win32_networkadapterconfiguration", "macaddress", "ipenabled"); }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!