1、简介
通过C#可以很简易的得到计算机硬件的信息。具体步骤如下:
1)添加名为System.ManageMent的DLL。具体方法为:解决方案->添加引用-> .NET -> System.ManageMent。
2)在源文件中添加命名空间using System.Management。
3)创建ManagementObjectSearcher 对象。方法如下:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key);
其中,Key是WMI中的对象名。
4)调用ManagementObjectSearcher实例中的Get()方法,该方法将会把返回信息填在这个实例中,然后处理这个实例中的数据。
foreach (ManagementObject share in searcher.Get()){// Some Codes ...}
5)每个ManagementObject的对象中都有一些属性数据,处理这些数据即可:
feorach (PropertyData PC in share.Properties){//some codes ...}
2、WMI对象名
在WMI中对象名如下:
Win32_1394Controller
Win32_1394ControllerDevice
Win32_Account
Win32_AccountSID
Win32_ACE
Win32_ActionCheck
Win32_AllocatedResource
Win32_ApplicationCommandLine
Win32_ApplicationService
Win32_AssociatedBattery
Win32_AssociatedProcessorMemory
Win32_BaseBoard
Win32_BaseService
Win32_Battery
Win32_Binary
Win32_BindImageAction
Win32_BIOS
Win32_BootConfiguration
Win32_Bus
Win32_CacheMemory
Win32_CDROMDrive
Win32_CheckCheck
Win32_CIMLogicalDeviceCIMDataFile
Win32_ClassicCOMApplicationClasses
Win32_ClassicCOMClass
Win32_ClassicCOMClassSetting
Win32_ClassicCOMClassSettings
Win32_ClassInfoAction
Win32_ClientApplicationSetting
Win32_CodecFile
Win32_COMApplication
Win32_COMApplicationClasses
Win32_COMApplicationSettings
Win32_COMClass
Win32_ComClassAutoEmulator
Win32_ComClassEmulator
Win32_CommandLineAccess
Win32_ComponentCategory
Win32_ComputerSystem
Win32_ComputerSystemProcessor
Win32_ComputerSystemProduct
Win32_COMSetting
Win32_Condition
Win32_CreateFolderAction
Win32_CurrentProbe
Win32_DCOMApplication
Win32_DCOMApplicationAccessAl