C#通过WMI获取系统信息

How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...)

 

Introduction

For numerous reasons, you may need to access system hardware information. One example is when you have created a software and you want to put a lock on that software.

One of the most efficient ways to do so is to get one of the IDs of a piece of hardware in the target machine and then plan your software so that it can just work with the computer that has the same ID. Since some hardware IDs (and not all of them) are unique, you have very simply created a lock!

Notice

In the first versions of this article, I thought that the Processor ID was unique, but some other users told me that they had tested the Processor ID in different computers and sometimes they give the same result. So you should consider this and not try to just rely on Processor ID. I suggest that you combine it with some other IDs such as Motherboard, USB Controller, Bios, CD-ROM Drive and so on.

Another example is the need to get hard disk information, its partitions, and the free space on each partition. You may also require the hardware information while working on a multimedia application when you need to have complete information about the sound device and the VGA device of the target machine. An excellent use of this application is getting information about the memory of the system and valuable information such as the device memory address, memory device and so on.

Using the Code

First of all, you have to know that the application function is using some System.Management classes. So you need to add this line of code:

To get hardware information, you need to create an object of ManagementObjectSearcher class.

The Key on the code above, is a variable that is replaced with appropriate data. For example, to get the information of the CPU, you have to replace the Key with Win32_Processor. A complete list of these keys is given below:

First, call the Get() method of the ManagementObjectSearcher object that this application calls the searcher object. This will fill the object with the information you need. After that, you need to process the data that is in the searcher object.

Each ManagementObject has some Properties that are useful for us. Of course the Data of those properties is needed and we can process them like this:

The other parts of this application are nothing but working with the ListView control and that is really easy!

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

 

原文网址:http://www.codeproject.com/KB/system/GetHardwareInformation.aspx

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值