在VB中使用WMI获取系统硬件和软件有关信息
http://dev.csdn.net/develop/article/23/23371.shtm
简介:
WMI是英文Windows Management
Instrumentation的简写,它的功能主要是:访问本地主机的一些信息和服务,可以管理远程计算机(当然你必须要拥有足够的权限),比如:重启,关机,关闭进程,创建进程等。
实例如下:
'用WMI,先工程-引用 Microsoft WMI Scripting V1.1 Library
获取显卡/声卡/内存/操作系统的信息
声卡信息
Private Sub wmiSoundDeviceInfo()
Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_SoundDevice")
On Local Error Resume Next
For Each obj In wmiObjSet
MsgBox obj.ProductName
Next
End Sub
显卡信息
Private Sub wmiVideoControllerInfo()
Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_VideoController")
On Local Error Resume Next
For Each obj In wmiObjSet
MsgBox obj.VideoProcessor
Next
End Sub
内存信息
Private Sub wmiPhysicalMemoryInfo()
Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_PhysicalMemory")
On Local Error Resume Next
For Each objItem In wmiObjSet
Debug.Print "BankLabel: " & objItem.BankLabel
Debug.Print "Capacity: " & objItem.Capacity
Debug.Print "Caption: " & objItem.Caption
Debug.Print "CreationClassName: " & objItem.CreationClassName
Debug.Print "DataWidth: " & objItem.DataWidth
Debug.Print "Description: " & objItem.Description
Debug.Print "DeviceLocator: " & objItem.DeviceLocator
Debug.Print "FormFactor: " & objItem.FormFactor
Debug.Print "HotSwappable: " & objItem.HotSwappable
Debug.Print "InstallDate: " & objItem.InstallDate
Debug.Print "InterleaveDataDepth: " & objItem.InterleaveDataDepth
Debug.Print "InterleavePosition: " & objItem.InterleavePosition
Debug.Print "Manufacturer: " & objItem.Manufacturer
Debug.Print "MemoryType: " & objItem.MemoryType
Debug.Print "Model: " & objItem.Model
Debug.Print "Name: " & objItem.name
Debug.Print "OtherIdentifyingInfo: " & objItem.OtherIdentifyingInfo
Debug.Print "PartNumber: " & objItem.PartNumber
Debug.Print "PositionInRow: " & objItem.PositionInRow
Debug.Print "PoweredOn: " & objItem.PoweredOn
Debug.Print "Removable: " & objItem.Removable
Debug.Print "Replaceable: " & objItem.Replaceable
Debug.Print "SerialNumber: " & objItem.SerialNumber
Debug.Print "SKU: " & objItem.SKU
Debug.Print "Speed: " & objItem.Speed
Debug.Print "Status: " & objItem.Status
Debug.Print "Tag: " & objItem.Tag
Debug.Print "TotalWidth: " & objItem.TotalWidth
Debug.Print "TypeDetail: " & objItem.TypeDetail
Debug.Print "Version: " & objItem.Version
Next
End Sub
操作系统信息
Private Sub Command1_Click()
Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject
Dim msg As String
Dim dtb As String
Dim d As String
Dim t As String
Dim bias As Long
On Local Error Resume Next
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_OperatingSystem")
For Each obj In wmiObjSet
MsgBox "你当前使用的系统是 " & obj.Caption
Next
End Sub
说明:
大家可能会发现一个规律,实际上WMI对信息的提取都是使用了WIN32_类库名这样的规律,下列表格就是微软的操作系统各种硬件类的描述
其它WMI管理的类的信息在
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/accessing_hardware_and_software_through_wmi.asp
可以找到,其中也还有部分示例代码
简单Win_32类表
Win32 Classes
Microsoft? Windows? classes give you the means to manipulate a variety of objects. The following table identifies the categories of Windows classes.
硬件类
Computer System Hardware Classes
he Cooling Devices subcategory groups classes that represent instrumentable fans, temperature probes, and refrigeration devices.
Class |
Description |
Win32_Fan |
Represents the properties of a fan device in the computer system. |
Win32_HeatPipe |
Represents the properties of a heat pipe cooling device. |
Win32_Refrigeration |
Represents the properties of a refrigeration device. |
Win32_TemperatureProbe |
Represents the properties of a temperature sensor (electronic thermometer). |
Input Device Classes
The Input Devices subcategory groups classes that represent keyboards and pointing devices.
Class |
Description |
Win32_Keyboard |
Represents a keyboard installed on a Windows system. |
Win32_PointingDevice |
Represents an input device used to point to and select regions on the display of a Windows computer system. |
Mass Storage Classes
Classes in the Mass Storage subcategory represent storage devices such as hard disk drives, CD-ROM drives, and tape drives.
Motherboard, Controller, and Port Classes
The Motherboard, Controllers, and Ports subcategory groups classes that represent system devices. Examples include system memory, cache memory, and controllers.
Class |
Description |
Win32_1394Controller |
Represents the capabilities and management of a 1394 controller. |
Win32_1394ControllerDevice |
Relates the high-speed serial bus (IEEE 1394 Firewire) Controller and the CIM_LogicalDevice instance connected to it. |
Win32_AllocatedResource |
Relates a logical device to a system resource. |
Win32_AssociatedProcessorMemory |
Relates a processor and its cache memory. |
Win32_BaseBoard |
Represents a baseboard (also known as a motherboard or system board). |
Win32_BIOS |
Represents the attributes of the computer system's basic input/output services (BIOS) that are installed on the computer. |
Win32_Bus |
Represents a physical bus as seen by a Windows operating system. |
Win32_CacheMemory |
Represents cache memory (internal and external) on a computer system. |
Win32_ControllerHasHub |
Represents the hubs downstream from the universal serial bus (USB) controller. |
Win32_DeviceBus |
Relates a system bus and a logical device using the bus. |
Win32_DeviceMemoryAddress |
Represents a device memory address on a Windows system. |
Win32_DeviceSettings |
Relates a logical device and a setting that can be applied to it. |
Win32_DMAChannel |
Represents a direct memory access (DMA) channel on a Windows computer system. |
Win32_FloppyController |
Represents the capabilities and management capacity of a floppy disk drive controller. |
Win32_IDEController |
Represents the capabilities of an Integrated Drive Electronics (IDE) controller device. |
Win32_IDEControllerDevice |
Association class that relates an IDE controller and the logical device. |
Win32_InfraredDevice |
Represents the capabilities and management of an infrared device. |
Win32_IRQResource |
Represents an interrupt request line (IRQ) number on a Windows computer system. |
Win32_MemoryArray |
Represents the properties of the computer system memory array and mapped addresses. |
Win32_MemoryArrayLocation |
Relates a logical memory array and the physical memory array upon which it exists. |
Win32_MemoryDevice |
Represents the properties of a computer system's memory device along with it's associated mapped addresses. |
Win32_MemoryDeviceArray |
Relates a memory device and the memory array in which it resides. |
Win32_MemoryDeviceLocation |
Association class that relates a memory device and the physical memory on which it exists. |
Win32_MotherboardDevice |
Represents a device that contains the central components of the Windows computer system. |
Win32_OnBoardDevice |
Represents common adapter devices built into the motherboard (system board). |
Win32_ParallelPort |
Represents the properties of a parallel port on a Windows computer system. |
Win32_PCMCIAController |
Manages the capabilities of a Personal Computer Memory Card Interface Adapter (PCMCIA) controller device. |
Win32_PhysicalMemory |
Represents a physical memory device located on a computer as available to the operating system. |
Win32_PhysicalMemoryArray |
Represents details about the computer system's physical memory. |
Win32_PhysicalMemoryLocation |
Relates an array of physical memory and its physical memory. |
Win32_PNPAllocatedResource |
Represents an association between logical devices and system resources. |
Win32_PNPDevice |
Relates a device (known to Configuration Manager as a PNPEntity), and the function it performs. |
Win32_PNPEntity |
Represents the properties of a Plug and Play device. |
Win32_PortConnector |
Represents physical connection ports, such as DB-25 pin male, Centronics, and PS/2. |
Win32_PortResource |
Represents an I/O port on a Windows computer system. |
Win32_Processor |
Represents a device capable of interpreting a sequence of machine instructions on a Windows computer system. |
Win32_SCSIController |
Represents a small computer system interface (SCSI) controller on a Windows system. |
Win32_SCSIControllerDevice |
Relates a SCSI controller and the logical device (disk drive) connected to it. |
Win32_SerialPort |
Represents a serial port on a Windows system. |
Win32_SerialPortConfiguration |
Represents the settings for data transmission on a Windows serial port. |
Win32_SerialPortSetting |
Relates a serial port and its configuration settings. |
Win32_SMBIOSMemory |
Represents the capabilities and management of memory-related logical devices. |
Win32_SoundDevice |
Represents the properties of a sound device on a Windows computer system. |
Win32_SystemBIOS |
Relates a computer system (including data such as startup properties, time zones, boot configurations, or administrative passwords) and a system BIOS (services, languages, system management properties). |
Win32_SystemDriverPNPEntity |
Relates a Plug and Play device on the Windows computer system and the driver that supports the Plug and Play device. |
Win32_SystemEnclosure |
Represents the properties associated with a physical system enclosure. |
Win32_SystemMemoryResource |
Represents a system memory resource on a Windows system. |
Win32_SystemSlot |
Represents physical connection points including ports, motherboard slots and peripherals, and proprietary connections points. |
|