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#使用Gembox.SpreadSheet向Excel写入数据及图表的实例

    C#使用Gembox.SpreadSheet向Excel写入数据及图表的实例

    下面小编就为大家分享一篇C#使用Gembox.SpreadSheet向Excel写入数据及图表的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2017-12-12
  • C#实现获取鼠标句柄的方法

    C#实现获取鼠标句柄的方法

    这篇文章主要介绍了C#实现获取鼠标句柄的方法,详细的讲述了实现获取鼠标句柄的具体步骤及实现方法,并附有完整的实例源码供大家参考,需要的朋友可以参考下
    2014-09-09
  • C#实现日期操作类DateTime的方法示例

    C#实现日期操作类DateTime的方法示例

    C#中日期和时间操作主要通过System.DateTime类实现,提供了创建、格式化、比较和计算等功能,下面就来具体介绍一下,感兴趣的可以了解一下
    2025-03-03
  • 基于Unity实现2D边缘检测

    基于Unity实现2D边缘检测

    这篇文章主要介绍了如何利用Unity实现2D边缘检测,从而达到人物描边效果。文中的示例代码讲解详细,感兴趣的小伙伴可以了解一下
    2022-04-04
  • C#面向切面编程之AspectCore用法详解

    C#面向切面编程之AspectCore用法详解

    AspectCore 是Lemon名下的一个国产Aop框架,提供了一个全新的轻量级和模块化的Aop解决方案,下面我们就来深入了解下AspectCore在C#中的具体使用吧
    2024-01-01
  • C#监测IPv4v6网速及流量的实例代码

    C#监测IPv4v6网速及流量的实例代码

    这篇文章主要介绍了C#监测IPv4v6网速及流量的实例代码,文中讲解非常细致,帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-07-07
  • C#网站生成静态页面的实例讲解

    C#网站生成静态页面的实例讲解

    今天小编就为大家分享一篇关于C#网站生成静态页面的实例讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-01-01
  • 深入学习C#多线程

    深入学习C#多线程

    本文详细讲解了C#多线程编程的相关技术,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-02-02
  • treeview递归绑定的两种方法

    treeview递归绑定的两种方法

    这篇文章主要介绍了treeview递归绑定的两种方法,需要的朋友可以参考下
    2014-04-04
  • C#实现通过程序自动抓取远程Web网页信息的代码

    C#实现通过程序自动抓取远程Web网页信息的代码

    C#实现通过程序自动抓取远程Web网页信息的代码...
    2007-04-04

最新评论