C#获取CPU等硬件ID(转载)
System.Management命名空间提供对大量管理信息和管理事件集合的访问,这些信息和事件是与根据 Windows 管理规范 (WMI) 结构对系统、设备和应用程序设置检测点有关的。应用程序和服务可以使用从 ManagementObjectSearcher 和 ManagementQuery 派生的类,查询感兴趣的管理信息(例如在磁盘上还剩多少可用空间、当前 CPU 利用率是多少、某一应用程序正连接到哪一数据库等等);或者应用程序和服务可以使用 ManagementEventWatcher 类预订各种管理事件。这些可访问的数据可以来自分布式环境中托管的和非托管的组件。
首先添加对System.Management类库的引用。然后添加下述代码,就可获得CPU、主板和硬盘等的编号。
1,获取CPU编号
System.Management.ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
MessageBox.Show(mo["processorid"].ToString());
}
2,获取主板ID
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
foreach (ManagementObject mo in searcher.Get())
{
MessageBox.Show( mo["SerialNumber"].ToString().Trim());
}
或者:
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_BaseBoard");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mx in moc)
{
MessageBox.Show( mx.Properties["SerialNumber"].Value.ToString());
}
3,获取硬盘ID
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
MessageBox.Show(mo.Properties["Model"].Value.ToString());
}
4,获取网卡地址
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if((bool)mo["IPEnabled"] == true)
MessageBox.Show(mo["MacAddress"].ToString());
mo.Dispose();
}
5,获取内存信息
System.Management.ManagementClass mcMemory = new System.Management.ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection mocMemory = mcMemory.GetInstances();
foreach (ManagementObject mo in mocMemory)
{
if (mo.Properties["TotalVisibleMemorySize"].Value != null)
{
MessageBox.Show(mo.Properties["TotalVisibleMemorySize"].Value.ToString());
}
}
来自:http://blog.csdn.net/redder_xu/article/details/6773999
C#获取CPU等硬件ID(转载)的更多相关文章
- C#获取cpu序列号 硬盘ID 网卡硬地址以及操作注册表 .
转:http://blog.csdn.net/smartsmile2012/article/details/8682295 #region 获取cpu序列号 硬盘ID 网卡硬地址 /**/ /// & ...
- C/C++获取CPU等硬件信息&&屏幕截图
打算练习Socket的时候用用,最近有点小事情,没时间继续完善,先把写的这些代码贴上来,有空了再完善一下. HardwareInfo.h #include <stdio.h> #inclu ...
- 转载:c# 获取CPU温度(非WMI,直接读取硬件)
c#获取cpu温度 很早一个项目做远控,所以需要用到获取cpu温度,但是就是不知从何下手,无意中发现了Open Hardware Monitor,令我的项目成功完成 亲测20台清装xp sp2的机器, ...
- 获取CPU ID ,disk ID, MAC ID (windows ARM linux Mac)
windows 命令行获取CPU ID,可以用ShellExecute wmic cpu get processorid ProcessorId BFEBFBFF000506E3 开源库: 查询CPU ...
- Java 获取CPU、内存、外网IP等硬件信息
import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.Input ...
- C# 获取CPU序列号、网卡MAC地址、硬盘序列号封装类,用于软件绑定电脑
using System.Management; namespace GLaLa { /// <summary> /// hardware_mac 的摘要说明. /// </summ ...
- C#获取CPU占用率、内存占用、磁盘占用、进程信息
代码: using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading ...
- java支持跨平台获取cpuid、主板id、硬盘id、mac地址 (兼容windows、Linux)
windows: package cn.net.comsys.helper.system.info; import java.io.BufferedReader; import java.io.F ...
- Atitit. 获取cpu占有率的 java c# .net php node.js的实现
Atitit. 获取cpu占有率的 java c# .net php node.js的实现 通过wmic接口获取cpu占有率 C:\Users\Administrator.ATTILAXPC188&g ...
随机推荐
- [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数
Built-in Operators Relational Operators The following operators compare the passed operands and gene ...
- algorithm@ Shortest Path in Directed Acyclic Graph (O(|V|+|E|) time)
Given a Weighted Directed Acyclic Graph and a source vertex in the graph, find the shortest paths fr ...
- MSSql得到表的结构和字段
得到数据库中所有的表 select name from sysobjects where xtype='u' and name='{0}' 1.获取表的基本字段属性 --获取SqlServer中表结构 ...
- Spark SQL概念学习系列之Spark SQL 架构分析(四)
Spark SQL 与传统 DBMS 的查询优化器 + 执行器的架构较为类似,只不过其执行器是在分布式环境中实现,并采用的 Spark 作为执行引擎. Spark SQL 的查询优化是Catalyst ...
- [转]解决百度统计 gzdecode(): insufficient memory
百度统计API gzdecode($preLogin->retData, strlen($preLogin->retData)) 这段代码会造成一个PHP警告内存不足,解决办法只要换个解压 ...
- HDU 5744 Keep On Movin (贪心)
Keep On Movin 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...
- codeforces 630D Hexagons!
D. Hexagons! time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input ...
- rqnoj-396-SY学语文-dp
纯动态规划. 注意初始化为-INF #include<stdio.h> #include<algorithm> #include<iostream> #includ ...
- java 数据库连接池 Oracle版
首先应加入连接池和数据库连接的配置文件:数据库连接包:ojdbc6.jar数据库连接池包:commons-pool2-2.2.jar commons-dbc ...
- 【不积跬步,无以致千里】linux下如何查看自己的外网IP
局域网的服务器是通过ADSL路由器连接外网的,但ADSL是从ISP运营商那儿通过动态获得IP的,那么我怎么知道自己的外网地址是多少呢?今天得到几个办法:curl -s http://whatismyi ...