Csharp/C#教程:C# 获取硬件参数的实现方法分享

C#获取硬件参数的实现方法

示例代码:

privatestaticstringGetIdentifier(stringwmiClass,stringwmiProperty,stringwmiMustBeTrue) { stringresult=""; System.Management.ManagementClassmc=newSystem.Management.ManagementClass(wmiClass); System.Management.ManagementObjectCollectionmoc=mc.GetInstances(); foreach(System.Management.ManagementObjectmoinmoc) { if(mo[wmiMustBeTrue].ToString()=="True") { //Onlygetthefirstone if(result=="") { try { result=mo[wmiProperty].ToString(); break; } catch { } } } } returnresult; } privatestaticstringGetIdentifier(stringwmiClass,stringwmiProperty) { stringresult=""; System.Management.ManagementClassmc=newSystem.Management.ManagementClass(wmiClass); System.Management.ManagementObjectCollectionmoc=mc.GetInstances(); foreach(System.Management.ManagementObjectmoinmoc) { //Onlygetthefirstone if(result=="") { try { result=mo[wmiProperty].ToString(); break; } catch { } } } returnresult; } //cpuid GetIdentifier("Win32_Processor","UniqueId"); //processorid GetIdentifier("Win32_Processor","ProcessorId"); //processorname GetIdentifier("Win32_Processor","Name"); //Manufacturer GetIdentifier("Win32_Processor","Manufacturer"); //BIOSIdentifier privatestaticstringGetBiosId() { returnGetIdentifier("Win32_BIOS","Manufacturer") +GetIdentifier("Win32_BIOS","SMBIOSBIOSVersion") +GetIdentifier("Win32_BIOS","IdentificationCode") +GetIdentifier("Win32_BIOS","SerialNumber") +GetIdentifier("Win32_BIOS","ReleaseDate") +GetIdentifier("Win32_BIOS","Version"); } //MainphysicalharddriveID privatestaticstringGetDiskId() { returnGetIdentifier("Win32_DiskDrive","Model") +GetIdentifier("Win32_DiskDrive","Manufacturer") +GetIdentifier("Win32_DiskDrive","Signature") +GetIdentifier("Win32_DiskDrive","TotalHeads"); } //MotherboardID privatestaticstringGetBaseId() { returnGetIdentifier("Win32_BaseBoard","Model") +GetIdentifier("Win32_BaseBoard","Manufacturer") +GetIdentifier("Win32_BaseBoard","Name") +GetIdentifier("Win32_BaseBoard","SerialNumber"); } //PrimaryvideocontrollerID privatestaticstringGetVideoId() { returnGetIdentifier("Win32_VideoController","DriverVersion") +GetIdentifier("Win32_VideoController","Name"); } //FirstenablednetworkcardID privatestaticstringGetMacId() { returnGetIdentifier("Win32_NetworkAdapterConfiguration","MACAddress","IPEnabled"); }

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:详解C#使用AD(ActiveDirectory)验证内网用户名密码C#编写一个简单记事本功能C#集合类用法实例代码详解C#微信分享代码微信小程序支付之c#后台实现方法C#判断时间段是否相交的实现方法

标签: 参数 方法

详解C#使用AD(Active Directory)验证内网用户名密码

C#编写一个简单记事本功能

上述就是C#学习教程:C# 获取硬件参数的实现方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/908027.html

(0)
上一篇 2021年10月25日
下一篇 2021年10月25日

精彩推荐