C# 获取硬件参数的实现方法
作者:lqh 发布时间:2023-11-04 21:30:38
标签: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");
}
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/lan_liang/article/details/52554464


猜你喜欢
- 前言Java 语言很强大,但是,有人的地方就有江湖,有猿的地方就有 bug,Java 的核心代码并非十全十美。比如在 JDK 中居然也有反模
- Android Studio安装后发现所有的中文,不管是界面上的还是输出的log中的中文都变成小框框 可以肯定是字体的问题 解决
- 一、为什么需要服务网关:1、什么是服务网关:
- 本文实例讲述了Java使用自定义注解实现为事件源绑定事件 * 操作。分享给大家供大家参考,具体如下:一 定义注解import java.la
- cmd调用phantomjs官方资料:http://phantomjs.org/quick-start.html手动执行从官方下载phant
- 这几天在上海出差,忙里偷闲学习了一下Apk的反编译工具的基本使用。下面就简单介绍一下如何将我们从网上下载的Apk文件进行反编译得到我们想要获
- 前言:在 Java 语言中,保证线程安全性的主要手段是加锁,而 Java 中的锁主要有两种:synchronized 和 Lock,我们今天
- Model与Session区别什么是Session:Session:在计算机中,尤其是在网络应用中,称为“会话”。它具体是指一个终端用户与交
- 一、题目描述题目:同步锁出现的目的就是为了解决多线程安全问题。同步锁的几种方式synchronized1、同步代码块2、同步方法jdk1.5
- 文档中可通过应用不同的字体来呈现不一样的视觉效果,通过字体来实现文档布局、排版等设计需要。应用字体时,可在创建文档时指定字体,也可以用新字体
- 介绍TextView 是 Android 开发中最常用的小部件之一。它用于在屏幕上显示文本。但是,TextView 有几个较少为人知的功能,
- 引言CardView是Android 5.0系统之后引入的众多控件之一,实现之后的效果也是比较酷的,它经常被用在RecyclerView和L
- 在应用C#进行Winform窗体程序编写的时候,经常需要编写工具栏。下面小编给大家分享一下C#如何应用ToolSctrip控件编写工具栏。1
- G1 – Garbage First(垃圾优先算法)G1最主要的设计目标是: 将STW停顿的时间和分布变成可预期以及可配
- 老大让我check out 一个分支,可我在idea 右下角找了半天也没找到最后才发现:因为是刚创建的分支,我得先更新一下项目,连这个都不懂
- Flyway是一款开源的数据库版本管理工具,它更倾向于规约优于配置的方式。第一步:pom.xml添加maven依赖<!-- https
- public interface ArraySQL 类型 ARRAY 在 java 编程语言中的映射关系。默认情况下,Array 值是对 S
- 最近面试时,面试官问了一个列表倒计时效果如何实现,现在记录一下。运行效果图实现思路实现方法主要有两个:1.为每个开始倒计时的item启动一个
- 在VF、VB、PB的应用中,有些无法通过语言工具本身来完成的或者做得不理想的功能,我们会考虑通过Windows的API来完成。在那个年代,熟
- 关于 swagger 本文不再赘述,网上文章很多。本文要讲的是Knife4j3.0.3 整合SpringBoot 2.6.4,因为 knif