vb.netwmi:VB中使用WMI获取系统硬件和软件有关信息-vb教程



RONG>在VB中使用WMI获取系统硬件和软件Software有关信息

介绍:

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\")
_disibledevent=> InstancesOf(\"Win32_VideoController\")

_disibledevent=> InstancesOf(\"Win32_PhysicalMemory\")

_disibledevent=>


Debug.Pr \"TypeDetail: \" & objItem.TypeDetail
Debug.Pr \"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
_disibledevent=> For Each obj In wmiObjSet
MsgBox \"你当前使用系统是 \" & obj.Caption
Next
End Sub

介绍说明:

大家可能会发现个规律,实际上WMI对信息提取都是使用了WIN32_类库名这样规律,下列表格就是微软操作系统各种硬件类描述

其它WMI管理信息在



可以找到,其中也还有部分举例代码

简单Win_32类表

Win32 Classes

Microsoft® Windows® es give you the means to manipulate a variety of objects. The following table identies the categories of Windows es.

Category Description
Classes that represent hardware related objects.
Classes that represent operating system related objects.
Classes that represent software related objects.
Classes used to manage WMI.
Classes that represent formatted and raw performance data.







硬件类

Computer Hardware Classes

he Cooling Devices subcategory groups es that represent instrumentable fans, temperature probes, and refrigeration devices.

Class Description
Represents the properties of a fan device in the computer system.
Represents the properties of a heat pipe cooling device.
Represents the properties of a refrigeration device.
Represents the properties of a temperature sensor (electronic thermometer).






Input Device Classes

The Input Devices subcategory groups es that represent keyboards and poing devices.

Class Description
Represents a keyboard ed _disibledevent=> Represents an input device used to po to and select regions _disibledevent=> Class Description
Represents the tings for the autocheck operation of a disk.
Represents a CD-ROM drive _disibledevent=> Represents a physical disk drive as seen by a computer running the Windows operating system.
Manages the capabilities of a floppy disk drive.
Represents any type of documentation or storage medium.
Represents a tape drive _disibledevent=> Class Description
Represents the capabilities and management of a 1394 controller.
Relates the high-speed serial bus (IEEE 1394 Firewire) Controller and the CIM_LogicalDevice instance connected to it.
Relates a logical device to a system resource.
Relates a processor and its cache memory.


Represents a baseboard (also known as a motherboard or system board).
Represents the attributes of the computer system´s basic input/output services (BIOS) that are ed _disibledevent=> Represents a physical bus as seen by a Windows operating system.
Represents cache memory (ernal and external) _disibledevent=> Represents the hubs downstream from the universal serial bus (USB) controller.
Relates a system bus and a logical device using the bus.
Represents a device memory address _disibledevent=> Relates a logical device and a ting that can be applied to it.
Represents a direct memory access (DMA) channel _disibledevent=> Represents the capabilities and management capacity of a floppy disk drive controller.
Represents the capabilities of an Integrated Drive Electronics (IDE) controller device.
Association that relates an IDE controller and the logical device.
Represents the capabilities and management of an infrared device.
Represents an errupt request line (IRQ) number _disibledevent=> Represents the properties of the computer system memory .gif' /> and mapped addresses.
Relates a logical memory .gif' /> and the physical memory .gif' /> upon which it exists.
Represents the properties of a computer system´s memory device along with it´s associated mapped addresses.
Relates a memory device and the memory .gif' /> in which it resides.
Association that relates a memory device and the physical memory _disibledevent=> Represents a device that contains the central components of the Windows computer system.
Represents common adapter devices built o the motherboard (system board).
Represents the properties of a parallel port _disibledevent=> Manages the capabilities of a Personal Computer Memory Card Interface Adapter (PCMCIA) controller device.
Represents a physical memory device located _disibledevent=> Represents details about the computer system´s physical memory.
Relates an .gif' /> of physical memory and its physical memory.
Represents an association between logical devices and system resources.
Relates a device (known to Configuration Manager as a PNPEntity), and the function it performs.
Represents the properties of a Plug and Play device.
Represents physical connection ports, such as DB-25 pin male, Centronics, and PS/2.
Represents an I/O port _disibledevent=> Represents a device capable of erpreting a sequence of machine instructions _disibledevent=> Represents a small computer system erface (SCSI) controller _disibledevent=> Relates a SCSI controller and the logical device (disk drive) connected to it.
Represents a serial port _disibledevent=> Represents the tings for data transmission _disibledevent=> Relates a serial port and its configuration tings.
Represents the capabilities and management of memory-related logical devices.


Represents the properties of a sound device _disibledevent=> 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).
Relates a Plug and Play device _disibledevent=> Represents the properties associated with a physical system enclosure.
Represents a system memory resource _disibledevent=> Represents physical connection pos including ports, motherboard slots and peripherals, and proprietary connections pos.
Manages the capabilities of a universal serial bus (USB) controller.
Relates a USB controller and the CIM_LogicalDevice instances connected to it.
Represents the management characteristics of a USB hub.






Networking Device Classes

The Networking Devices subcategory groups es that represent the network erface controller, its configurations, and its tings.

Class Description
Represents a network adapter _disibledevent=> Represents the attributes and behaviors of a network adapter. The is not guaranteed to be supported after the ratication of the Distributed Management Task Force (DMTF) CIM network specication.
Relates a network adapter and its configuration tings.






Power Classes

The Power subcategory groups es that represent power supplies, batteries, and events related to these devices.

Class Description
Relates a logical device and the battery it is using.
Represents a battery connected to the computer system.
Represents the properties of a current monitoring sensor (ammeter).
Represents the properties of a portable battery, such as _disibledevent=> Represents power management events resulting from power state changes.
Represents the capabilities and management capacity of an unerruptible power supply (UPS).
Represents the properties of a voltage sensor (electronic voltmeter).






Pring Classes

The Pring subcategory groups es that represent prers, prer configurations, and pr jobs.

Class Description
Relates a prer to a prer driver.
Represents a device connected to a Windows computer system that is capable of reproducing a visual image _disibledevent=> Defines the configuration for a prer device.
Relates a prer and the local device to which the prer is connected.
Represents the drivers for a Win32_Prer instance.
Relates a local prer and its driver file (not the driver itself).
Relates a prer and its configuration tings.
Represents a pr job generated by a Windows application.
Represents a TCP/IP service access po.






Telephony Classes

The Telephony subcategory groups es that represent \"plain old telephone\" modem devices and their associated serial connections.

Class Description
Represents the services and characteristics of a Plain Old Telephone Service (POTS) modem _disibledevent=>


Relates a modem and the serial port the modem uses.






Video and Monitor Classes

The Video and Monitors subcategory groups es that represent monitors, video cards, and their associated tings.

Class Description
Represents the type of monitor or display device attached to the computer system.
Represents configuration information for the display device _disibledevent=> Represents the video adapter configuration information of a Windows system. This is obsolete. In place of this , use the properties in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution es.
This has been eliminated from WindowsXP and later; attempts to use it will generate a fatal error. In place of this , use the properties contained in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution es.
Represents the capabilities and management capacity of the video controller _disibledevent=> Relates a video controller and video tings that can be applied to it.





而每个类都有对应数据结构如

显卡

Win32_VideoController : CIM_PCVideoController{ u16 ; ; ; u32 ; u16 ; ; ; u32 ; u32 ; boolean ; ; u32 ; u32 ; u64 ; u32 ; u32 ; u32 ; u16 ; u32 ; ; ; u32 ; u32 ; datetime ; ; boolean ; ; u32 ; u32 ; ; ; datetime ; ; u32 ; u32 ; u32 ; u32 ; u32 ; boolean ; ; u16 ; u32 ; ; u16 ; boolean ; u16 ; u32 ; u32 ; ; u16 ; ; ; u32 ; datetime ; u16 ; u16 ; u16 ; ; ;};声卡等

Win32_SoundDevice : CIM_LogicalDevice
{
u16 ;
;
u32 ;
boolean ;
;
;
;
u16 ;
boolean ;
;
datetime ;
u32 ;
;
u32 ;
;
;
u16 ;
boolean ;
;
;
u16 ;
;
;
};

Win32_PrJob : CIM_Job
{
;
;
;
;
;
datetime ;
;
datetime ;
u32 ;
;
;
;
;
u32 ;
;
;
u32 ;
u32 ;
datetime ;
;
u32 ;
datetime ;
u32 ;
datetime ;
};



Set wmiObjSet = GetObject(\"winmgmts:{impersonationLevel=impersonate}\"). _
InstancesOf(\"Win32_PrJob\")

可以获得打印任务列表等信息



对于VB来讲获得系统硬件和软件Software信息大都使用API,现在使用WMI可以快速实现我们目标.如获取驱动器/显卡/共享信息等等都会变得方便和有效








Tags:  vb.net教程 vb6.0教程 vb教程 vb.netwmi

延伸阅读

最新评论

发表评论