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"); }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
总结以上是内存溢出为你收集整理的C# 获取硬件参数的实现方法全部内容,希望文章能够帮你解决C# 获取硬件参数的实现方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)