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

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

VB中使WMI获取系统硬件软件有关信息

简介:

      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管理的类的信息在

WMIsdk/WMI/accessing_hardware_and_software_through_WMI.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/WMIsdk/WMI/accessing_hardware_and_software_through_WMI.asp

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

简单Win_32类表

WMI.win32_classes>Win32 Classes

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

CategoryDescriptionWMIsdk/WMI/computer_system_hardware_classes.asp">Computer system hardwareClasses that represent hardware related objects.WMIsdk/WMI/operating_system_classes.asp">Operating systemClasses that represent operating system related objects.WMIsdk/WMI/installed_applications_classes.asp">Installed applicationsClasses that represent software related objects.WMIsdk/WMI/WMI_service_management_classes.asp">WMI service managementClasses used to manage WMI.WMIsdk/WMI/performance_counter_classes.asp">Performance counters

Classes that represent formatted and raw performance data.

 

WMI.computer_system_hardware_classes> 

硬件类

Computer System Hardware Classes

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

ClassDescriptionWMIsdk/WMI/win32_fan.asp">Win32_FanRepresents the properties of a fan device in the computer system.WMIsdk/WMI/win32_heatpipe.asp">Win32_HeatPipeRepresents the properties of a heat pipe cooling device.WMIsdk/WMI/win32_refrigeration.asp">Win32_RefrigerationRepresents the properties of a refrigeration device.WMIsdk/WMI/win32_temperatureprobe.asp">Win32_TemperatureProbeRepresents the properties of a temperature sensor (electronic thermometer).

Input Device Classes

The Input Devices subcategory groups classes that represent keyboards and pointing devices.

ClassDescriptionWMIsdk/WMI/win32_keyboard.asp">Win32_KeyboardRepresents a keyboard installed on a Windows system.WMIsdk/WMI/win32_pointingdevice.asp">Win32_PointingDeviceRepresents 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.

ClassDescriptionWMIsdk/WMI/win32_autochksetting.asp">Win32_AutochkSettingRepresents the settings for the autocheck operation of a disk.WMIsdk/WMI/win32_cdromdrive.asp">Win32_CDROMDriveRepresents a CD-ROM drive on a Windows computer system.WMIsdk/WMI/win32_diskdrive.asp">Win32_DiskDriveRepresents a physical disk drive as seen by a computer running the Windows operating system.WMIsdk/WMI/win32_floppydrive.asp">Win32_FloppyDriveManages the capabilities of a floppy disk drive.WMIsdk/WMI/win32_physicalmedia.asp">Win32_PhysicalMediaRepresents any type of documentation or storage medium.WMIsdk/WMI/win32_tapedrive.asp">Win32_TapeDriveRepresents a tape drive on a Windows computer.

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.

ClassDescriptionWMIsdk/WMI/win32_1394controller.asp">Win32_1394ControllerRepresents the capabilities and management of a 1394 controller.WMIsdk/WMI/win32_1394controllerdevice.asp">Win32_1394ControllerDeviceRelates the high-speed serial bus (IEEE 1394 Firewire) Controller and the CIM_LogicalDevice instance connected to it.WMIsdk/WMI/win32_allocatedresource.asp">Win32_AllocatedResourceRelates a logical device to a system resource.WMIsdk/WMI/win32_associatedprocessormemory.asp">Win32_AssociatedProcessorMemoryRelates a processor and its cache memory.WMIsdk/WMI/win32_baseboard.asp">Win32_BaseBoardRepresents a baseboard (also known as a motherboard or system board).WMIsdk/WMI/win32_bios.asp">Win32_BIOSRepresents the attributes of the computer system's basic input/output services (BIOS) that are installed on the computer.WMIsdk/WMI/win32_bus.asp">Win32_BusRepresents a physical bus as seen by a Windows operating system.WMIsdk/WMI/win32_cachememory.asp">Win32_CacheMemoryRepresents cache memory (internal and external) on a computer system.WMIsdk/WMI/win32_controllerhashub.asp">Win32_ControllerHasHubRepresents the hubs downstream from the universal serial bus (USB) controller.WMIsdk/WMI/win32_devicebus.asp">Win32_DeviceBusRelates a system bus and a logical device using the bus.WMIsdk/WMI/win32_devicememoryaddress.asp">Win32_DeviceMemoryAddressRepresents a device memory address on a Windows system.WMIsdk/WMI/win32_devicesettings.asp">Win32_DeviceSettingsRelates a logical device and a setting that can be applied to it.WMIsdk/WMI/win32_dmachannel.asp">Win32_DMAChannelRepresents a direct memory access (DMA) channel on a Windows computer system.WMIsdk/WMI/win32_floppycontroller.asp">Win32_FloppyControllerRepresents the capabilities and management capacity of a floppy disk drive controller.WMIsdk/WMI/win32_idecontroller.asp">Win32_IDEControllerRepresents the capabilities of an Integrated Drive Electronics (IDE) controller device.WMIsdk/WMI/win32_idecontrollerdevice.asp">Win32_IDEControllerDeviceAssociation class that relates an IDE controller and the logical device.WMIsdk/WMI/win32_infrareddevice.asp">Win32_InfraredDeviceRepresents the capabilities and management of an infrared device.WMIsdk/WMI/win32_irqresource.asp">Win32_IRQResourceRepresents an interrupt request line (IRQ) number on a Windows computer system.WMIsdk/WMI/win32_memoryarray.asp">Win32_MemoryArrayRepresents the properties of the computer system memory array and mapped addresses.WMIsdk/WMI/win32_memoryarraylocation.asp">Win32_MemoryArrayLocationRelates a logical memory array and the physical memory array upon which it exists.WMIsdk/WMI/win32_memorydevice.asp">Win32_MemoryDeviceRepresents the properties of a computer system's memory device along with it's associated mapped addresses.WMIsdk/WMI/win32_memorydevicearray.asp">Win32_MemoryDeviceArrayRelates a memory device and the memory array in which it resides.WMIsdk/WMI/win32_memorydevicelocation.asp">Win32_MemoryDeviceLocationAssociation class that relates a memory device and the physical memory on which it exists.WMIsdk/WMI/win32_motherboarddevice.asp">Win32_MotherboardDeviceRepresents a device that contains the central components of the Windows computer system.WMIsdk/WMI/win32_onboarddevice.asp">Win32_OnBoardDeviceRepresents common adapter devices built into the motherboard (system board).WMIsdk/WMI/win32_parallelport.asp">Win32_ParallelPortRepresents the properties of a parallel port on a Windows computer system.WMIsdk/WMI/win32_pcmciacontroller.asp">Win32_PCMCIAControllerManages the capabilities of a Personal Computer Memory Card Interface Adapter (PCMCIA) controller device.WMIsdk/WMI/win32_physicalmemory.asp">Win32_PhysicalMemoryRepresents a physical memory device located on a computer as available to the operating system.WMIsdk/WMI/win32_physicalmemoryarray.asp">Win32_PhysicalMemoryArrayRepresents details about the computer system's physical memory.WMIsdk/WMI/win32_physicalmemorylocation.asp">Win32_PhysicalMemoryLocationRelates an array of physical memory and its physical memory.WMIsdk/WMI/win32_pnpallocatedresource.asp">Win32_PNPAllocatedResourceRepresents an association between logical devices and system resources.WMIsdk/WMI/win32_pnpdevice.asp">Win32_PNPDeviceRelates a device (known to Configuration Manager as a PNPEntity), and the function it performs.WMIsdk/WMI/win32_pnpentity.asp">Win32_PNPEntityRepresents the properties of a Plug and Play device.WMIsdk/WMI/win32_portconnector.asp">Win32_PortConnectorRepresents physical connection ports, such as DB-25 pin male, Centronics, and PS/2.WMIsdk/WMI/win32_portresource.asp">Win32_PortResourceRepresents an I/O port on a Windows computer system.WMIsdk/WMI/win32_processor.asp">Win32_ProcessorRepresents a device capable of interpreting a sequence of machine instructions on a Windows computer system.WMIsdk/WMI/win32_scsicontroller.asp">Win32_SCSIControllerRepresents a small computer system interface (SCSI) controller on a Windows system.WMIsdk/WMI/win32_scsicontrollerdevice.asp">Win32_SCSIControllerDeviceRelates a SCSI controller and the logical device (disk drive) connected to it.WMIsdk/WMI/win32_serialport.asp">Win32_SerialPortRepresents a serial port on a Windows system.WMIsdk/WMI/win32_serialportconfiguration.asp">Win32_SerialPortConfigurationRepresents the settings for data transmission on a Windows serial port.WMIsdk/WMI/win32_serialportsetting.asp">Win32_SerialPortSettingRelates a serial port and its configuration settings.WMIsdk/WMI/win32_smbiosmemory.asp">Win32_SMBIOSMemoryRepresents the capabilities and management of memory-related logical devices.WMIsdk/WMI/win32_sounddevice.asp">Win32_SoundDeviceRepresents the properties of a sound device on a Windows computer system.WMIsdk/WMI/win32_systembios.asp">Win32_SystemBIOSRelates 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).WMIsdk/WMI/win32_systemdriverpnpentity.asp">Win32_SystemDriverPNPEntityRelates a Plug and Play device on the Windows computer system and the driver that supports the Plug and Play device.WMIsdk/WMI/win32_systemenclosure.asp">Win32_SystemEnclosureRepresents the properties associated with a physical system enclosure.WMIsdk/WMI/win32_systemmemoryresource.asp">Win32_SystemMemoryResourceRepresents a system memory resource on a Windows system.WMIsdk/WMI/win32_systemslot.asp">Win32_SystemSlotRepresents physical connection points including ports, motherboard slots and peripherals, and proprietary connections points.WMIsdk/WMI/win32_usbcontroller.asp">Win32_USBControllerManages the capabilities of a universal serial bus (USB) controller.WMIsdk/WMI/win32_usbcontrollerdevice.asp">Win32_USBControllerDeviceRelates a USB controller and the CIM_LogicalDevice instances connected to it.WMIsdk/WMI/win32_usbhub.asp">Win32_USBHubRepresents the management characteristics of a USB hub.

Networking Device Classes

The Networking Devices subcategory groups classes that represent the network interface controller, its configurations, and its settings.

ClassDescriptionWMIsdk/WMI/win32_networkadapter.asp">Win32_NetworkAdapterRepresents a network adapter on a Windows system.WMIsdk/WMI/win32_networkadapterconfiguration.asp">Win32_NetworkAdapterConfigurationRepresents the attributes and behaviors of a network adapter. The class is not guaranteed to be supported after the ratification of the Distributed Management Task Force (DMTF) CIM network specification.WMIsdk/WMI/win32_networkadaptersetting.asp">Win32_NetworkAdapterSettingRelates a network adapter and its configuration settings.

Power Classes

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

ClassDescriptionWMIsdk/WMI/win32_associatedbattery.asp">Win32_AssociatedBatteryRelates a logical device and the battery it is using.WMIsdk/WMI/win32_battery.asp">Win32_BatteryRepresents a battery connected to the computer system.WMIsdk/WMI/win32_currentprobe.asp">Win32_CurrentProbeRepresents the properties of a current monitoring sensor (ammeter).WMIsdk/WMI/win32_portablebattery.asp">Win32_PortableBatteryRepresents the properties of a portable battery, such as one used for a notebook computer.WMIsdk/WMI/win32_powermanagementevent.asp">Win32_PowerManagementEventRepresents power management events resulting from power state changes.WMIsdk/WMI/win32_uninterruptiblepowersupply.asp">Win32_UninterruptiblePowerSupplyRepresents the capabilities and management capacity of an uninterruptible power supply (UPS).WMIsdk/WMI/win32_voltageprobe.asp">Win32_VoltageProbeRepresents the properties of a voltage sensor (electronic voltmeter).

Printing Classes

The Printing subcategory groups classes that represent printers, printer configurations, and print jobs.

ClassDescriptionWMIsdk/WMI/win32_driverfordevice.asp">Win32_DriverForDeviceRelates a printer to a printer driver.WMIsdk/WMI/win32_printer.asp">Win32_PrinterRepresents a device connected to a Windows computer system that is capable of reproducing a visual image on a medium.WMIsdk/WMI/win32_printerconfiguration.asp">Win32_PrinterConfigurationDefines the configuration for a printer device.WMIsdk/WMI/win32_printercontroller.asp">Win32_PrinterControllerRelates a printer and the local device to which the printer is connected.WMIsdk/WMI/win32_printerdriver.asp">Win32_PrinterDriverRepresents the drivers for a Win32_Printer instance.WMIsdk/WMI/win32_printerdriverdll.asp">Win32_PrinterDriverDllRelates a local printer and its driver file (not the driver itself).WMIsdk/WMI/win32_printersetting.asp">Win32_PrinterSettingRelates a printer and its configuration settings.WMIsdk/WMI/win32_printjob.asp">Win32_PrintJobRepresents a print job generated by a Windows application.WMIsdk/WMI/win32_tcpipprinterport.asp">Win32_TCPIPPrinterPortRepresents a TCP/IP service access point.

Telephony Classes

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

ClassDescriptionWMIsdk/WMI/win32_potsmodem.asp">Win32_POTSModemRepresents the services and characteristics of a Plain Old Telephone Service (POTS) modem on a Windows system.WMIsdk/WMI/win32_potsmodemtoserialport.asp">Win32_POTSModemToSerialPortRelates a modem and the serial port the modem uses.

Video and Monitor Classes

The Video and Monitors subcategory groups classes that represent monitors, video cards, and their associated settings.

ClassDescriptionWMIsdk/WMI/win32_desktopmonitor.asp">Win32_DesktopMonitorRepresents the type of monitor or display device attached to the computer system.WMIsdk/WMI/win32_displayconfiguration.asp">Win32_DisplayConfigurationRepresents configuration information for the display device on a Windows system. This class is obsolete. In place of this class, use the properties in the WMIsdk/WMI/win32_videocontroller.asp">Win32_VideoController, Win32_DesktopMonitor, and WMIsdk/WMI/cim_videocontrollerresolution.asp">CIM_VideoControllerResolution classes.WMIsdk/WMI/win32_displaycontrollerconfiguration.asp">Win32_DisplayControllerConfigurationRepresents the video adapter configuration information of a Windows system. This class is obsolete. In place of this class, use the properties in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution classes.WMIsdk/WMI/win32_videoconfiguration.asp">Win32_VideoConfigurationThis class has been eliminated from Windows XP and later; attempts to use it will generate a fatal error. In place of this class, use the properties contained in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution classes.WMIsdk/WMI/win32_videocontroller.asp">Win32_VideoControllerRepresents the capabilities and management capacity of the video controller on a Windows computer system.WMIsdk/WMI/win32_videosettings.asp">Win32_VideoSettingsRelates a video controller and video settings that can be applied to it.

 

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

显卡

class Win32_VideoController : CIM_PCVideoController{  uint16 AcceleratorCapabilities[];  string AdapterCompatibility;  string AdapterDACType;  uint32 AdapterRAM;  uint16 Availability;  string CapabilityDescriptions[];  string Caption;  uint32 ColorTableEntries;  uint32 ConfigManagerErrorCode;  boolean ConfigManagerUserConfig;  string CreationClassName;  uint32 CurrentBitsPerPixel;  uint32 CurrentHorizontalResolution;  uint64 CurrentNumberOfColors;  uint32 CurrentNumberOfColumns;  uint32 CurrentNumberOfRows;  uint32 CurrentRefreshRate;  uint16 CurrentScanMode;  uint32 CurrentVerticalResolution;  string Description;  string DeviceID;  uint32 DeviceSpecificPens;  uint32 DitherType;  datetime DriverDate;  string DriverVersion;  boolean ErrorCleared;  string ErrorDescription;  uint32 ICMIntent;  uint32 ICMMethod;  string InfFilename;  string InfSection;  datetime InstallDate;  string InstalledDisplayDrivers;  uint32 LastErrorCode;  uint32 MaxMemorySupported;  uint32 MaxNumberControlled;  uint32 MaxRefreshRate;  uint32 MinRefreshRate;  boolean Monochrome;  string Name;  uint16 NumberOfColorPlanes;  uint32 NumberOfVideoPages;  string PNPDeviceID;  uint16 PowerManagementCapabilities[];  boolean PowerManagementSupported;  uint16 ProtocolSupported;  uint32 ReservedSystemPaletteEntries;  uint32 SpecificationVersion;  string Status;  uint16 StatusInfo;  string SystemCreationClassName;  string SystemName;  uint32 SystemPaletteEntries;  datetime TimeOfLastReset;  uint16 VideoArchitecture;  uint16 VideoMemoryType;  uint16 VideoMode;  string VideoModeDescription;  string VideoProcessor;};

声卡等

class Win32_SoundDevice : CIM_LogicalDevice
{
  uint16 Availability;
  string Caption;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  string CreationClassName;
  string Description;
  string DeviceID;
  uint16 DMABufferSize;
  boolean ErrorCleared;
  string ErrorDescription;
  datetime InstallDate;
  uint32 LastErrorCode;
  string Manufacturer;
  uint32 MPU401Address;
  string Name;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  string ProductName;
  string Status;
  uint16 StatusInfo;
  string SystemCreationClassName;
  string SystemName;
};

class Win32_PrintJob : CIM_Job
{
  string Caption;
  string DataType;
  string Description;
  string Document;
  string DriverName;
  datetime ElapsedTime;
  string HostPrintQueue;
  datetime InstallDate;
  uint32 JobId;
  string JobStatus;
  string Name;
  string Notify;
  string Owner;
  uint32 PagesPrinted;
  string Parameters;
  string PrintProcessor;
  uint32 Priority;
  uint32 Size;
  datetime StartTime;
  string Status;
  uint32 StatusMask;
  datetime TimeSubmitted;
  uint32 TotalPages;
  datetime UntilTime;
};

   Set WMIObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
                          InstancesOf("Win32_PrintJob")

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

 

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

 

 

 

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值