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

 更新时间:2017年10月25日 15:03:56   投稿:lqh  
这篇文章主要介绍了C# 获取硬件参数的实现方法的相关资料,希望通过本文能帮助到大家,让大家实现这样的功能,需要的朋友可以参考下

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#窗体关闭事件

    很多初学者都想把默认的C#关闭按钮事件弄明白,本文就介绍一下C#窗体关闭事件,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-10-10
  • C#使用GUID(全局统一标识符)

    C#使用GUID(全局统一标识符)

    这篇文章介绍了C#使用GUID(全局统一标识符)的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-04-04
  • C#实现学生成绩管理系统

    C#实现学生成绩管理系统

    这篇文章主要为大家详细介绍了C#实现学生成绩管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-08-08
  • C#如何控制IIS动态添加删除网站详解

    C#如何控制IIS动态添加删除网站详解

    这篇文章主要给大家介绍了关于C#如何控制IIS动态添加删除网站的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用C#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-11-11
  • C#面向对象设计原则之接口隔离原则

    C#面向对象设计原则之接口隔离原则

    这篇文章介绍了C#面向对象设计原则之接口隔离原则,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-03-03
  • C#根据http和ftp图片地址获取对应图片

    C#根据http和ftp图片地址获取对应图片

    这篇文章主要为大家详细介绍了C#根据http和ftp图片地址获取对应图片,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-06-06
  • C#实现金额转换成中文大写金额

    C#实现金额转换成中文大写金额

    这篇文章主要为大家详细介绍了C#实现金额转换成中文大写金额,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-08-08
  • c#执行excel宏模版的方法

    c#执行excel宏模版的方法

    这篇文章主要介绍了c#执行excel宏模版的方法,导出Excel模版的代码如下,大家参考使用吧
    2014-01-01
  • C#实现快递api接口调用方法

    C#实现快递api接口调用方法

    这篇文章主要介绍了C#实现快递api接口调用方法,主要是通过快递API网接口的服务,使用的时候直接申请个接口UID即可,有需要的小伙伴来参考下吧。
    2015-03-03
  • c#自带缓存使用方法 c#移除清理缓存

    c#自带缓存使用方法 c#移除清理缓存

    这篇文章主要介绍了c#自带缓存使用方法,包括获取数据缓存、设置数据缓存、移除指定数据缓存等方法,需要的朋友可以参考下
    2014-02-02

最新评论