WMI is used in VB to get system hardware and software related information

zhaozj2021-02-17  49

Use WMI to obtain system hardware and software related information in VB

Introduction:

WMI is a short written in English, which is mainly: access to some information and services to the local host, you can manage remote computers (of course you have to have enough permissions), such as: restart, shutdown, shut down process, create process Wait.

Examples are as follows:

'Use WMI, first engineering - Reference Microsoft WMI Scripting V1.1 Library

Get information on graphics / sound card / memory / operating system

Sound card information

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 NextEnd Sub

Graphics information

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 NextEnd Sub

Memory information

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 "Manufacture Debug.print" Manufactural urer: "& 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 nextend Sub operating system information

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_Operatyingsystem ") for Each Obj IN WMIOBJSET MSGBOX" Your current system is "& obj.caption nextend Sub

Description:

Everyone may find a law, in fact, WMI's extraction of information is the rules such as the Win32_ class library name, the following table is a description of various hardware classes of Microsoft operating systems.

Information about the class of other WMI management

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/accessing_hardware_and_software_through_wmi.asp

Can be found, there is also some sample code

Simple WIN_32 Table

Win32 Classes

Microsoft® Windows® Classes Give You The Means To Manipulate A Variety of Objects. The Following Table Identifies The Categories of Windows Classes.

CategoryDescriptionComputer system hardwareClasses that represent hardware related objects.Operating systemClasses that represent operating system related objects.Installed applicationsClasses that represent software related objects.WMI service managementClasses used to manage WMI.Performance counters Classes that represent formatted and raw performance data. Hardware

Computer System Hardware Classes

He Cooling Devices Subcategory Groups Classes That Represent Instrumentable Fans, Temperature Probes, and Refrigeration Devices.

ClassDescriptionWin32_FanRepresents the properties of a fan device in the computer system.Win32_HeatPipeRepresents the properties of a heat pipe cooling device.Win32_RefrigerationRepresents the properties of a refrigeration device.Win32_TemperatureProbeRepresents the properties of a temperature sensor (electronic thermometer).

Input Device Classes

The INPUT Devices Subcategory Groups Classes That Repesent Keyboards and Pointing Devices.

ClassDescriptionWin32_KeyboardRepresents a keyboard installed on a Windows system.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.

ClassDescriptionWin32_AutochkSettingRepresents the settings for the autocheck operation of a disk.Win32_CDROMDriveRepresents a CD-ROM drive on a Windows computer system.Win32_DiskDriveRepresents a physical disk drive as seen by a computer running the Windows operating system.Win32_FloppyDriveManages the capabilities of a floppy disk drive.Win32_PhysicalMediaRepresents any Type of Documentation or Storage Medium.Win32_TaPedriveRIverepresents a Tape Drive ON A Windows Computer.Motherboard, Controller, And Port Classes

The Motherboard, Controllers, And Ports Subcategory Groups Classes That Repesent System Devices. Examples include System Memory, Cache Memory, And Controllers.

ClassDescriptionWin32_1394ControllerRepresents the capabilities and management of a 1394 controller.Win32_1394ControllerDeviceRelates the high-speed serial bus (IEEE 1394 Firewire) Controller and the CIM_LogicalDevice instance connected to it.Win32_AllocatedResourceRelates a logical device to a system resource.Win32_AssociatedProcessorMemoryRelates a processor and its cache memory.Win32_BaseBoardRepresents a Baseboard (Also Known As a Motherboard or System Board) .win32_biosrepresents The attributes of the computer system '

s basic input / output services (BIOS) that are installed on the computer.Win32_BusRepresents a physical bus as seen by a Windows operating system.Win32_CacheMemoryRepresents cache memory (internal and external) on a computer system.Win32_ControllerHasHubRepresents the hubs downstream from the universal serial bus (USB) controller.Win32_DeviceBusRelates a system bus and a logical device using the bus.Win32_DeviceMemoryAddressRepresents a device memory address on a Windows system.Win32_DeviceSettingsRelates a logical device and a setting that can be applied to it.Win32_DMAChannelRepresents a direct memory access (DMA) channel on a Windows computer system.Win32_FloppyControllerRepresents the capabilities and management capacity of a floppy disk drive controller.Win32_IDEControllerRepresents the capabilities of an Integrated Drive Electronics (IDE) controller device.Win32_IDEControllerDeviceAssociation class that relates an IDE controller and the logical device.Win32_InfraredDeviceRepresent s the capabilities and management of an infrared device.Win32_IRQResourceRepresents an interrupt request line (IRQ) number on a Windows computer system.Win32_MemoryArrayRepresents the properties of the computer system memory array and mapped addresses.Win32_MemoryArrayLocationRelates a logical memory array and the physical memory array upon which IT EXISTS.WIN32_MEMORYDEVICEREPRESENTS The Properties of a Computer System's Memory Device Along with it '

s associated mapped addresses.Win32_MemoryDeviceArrayRelates a memory device and the memory array in which it resides.Win32_MemoryDeviceLocationAssociation class that relates a memory device and the physical memory on which it exists.Win32_MotherboardDeviceRepresents a device that contains the central components of the Windows computer system.Win32_OnBoardDeviceRepresents common adapter devices built into the motherboard (system board) .Win32_ParallelPortRepresents the properties of a parallel port on a Windows computer system.Win32_PCMCIAControllerManages the capabilities of a Personal Computer Memory Card Interface Adapter (PCMCIA) controller device.Win32_PhysicalMemoryRepresents a physical memory device located on a computer as available to the operation system.win32_physicalmemoryArrayrepresents details about the computer system '

s physical memory.Win32_PhysicalMemoryLocationRelates an array of physical memory and its physical memory.Win32_PNPAllocatedResourceRepresents an association between logical devices and system resources.Win32_PNPDeviceRelates a device (known to Configuration Manager as a PNPEntity), and the function it performs.Win32_PNPEntityRepresents the properties of a Plug and Play device.Win32_PortConnectorRepresents physical connection ports, such as DB-25 pin male, Centronics, and PS / 2.Win32_PortResourceRepresents an I / O port on a Windows computer system.Win32_ProcessorRepresents a device capable of interpreting a sequence of machine instructions on a Windows computer system.Win32_SCSIControllerRepresents a small computer system interface (SCSI) controller on a Windows system.Win32_SCSIControllerDeviceRelates a SCSI controller and the logical device (disk drive) connected to it.Win32_SerialPortRepresents a serial port on a Windows system.Win32_SerialPortConfigurationRepresents the settings for data transmission on a Windows serial port.Win32_SerialPortSettingRelates a serial port and its configuration settings.Win32_SMBIOSMemoryRepresents the capabilities and management of memory-related logical devices.Win32_SoundDeviceRepresents the properties of a sound device on a Windows computer system.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) .Win32_SystemDriverPNPEntityRelates a Plug and Play device on the Windows computer system and the driver that supports the Plug and Play device.

Win32_SystemEnclosureRepresents the properties associated with a physical system enclosure.Win32_SystemMemoryResourceRepresents a system memory resource on a Windows system.Win32_SystemSlotRepresents physical connection points including ports, motherboard slots and peripherals, and proprietary connections points.Win32_USBControllerManages the capabilities of a universal serial bus (USB) controller. Win32_usbcontrollerDeviceReLates a USB Controller and The CIM_LogicalDevice Instances Connected to it.win32_usbhubrepresents The Management Characteristics of A USB Hub.Networking Device Classes

The Networking Devices Subcategory Groups Classes That Repesent The Network Interface Controller, ITS Configurations, And ITS settings.

ClassDescriptionWin32_NetworkAdapterRepresents a network adapter on a Windows system.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.Win32_NetworkAdapterSettingRelates a network adapter and its configuration Settings.

Power Classes

The Power Subcategory Groups Classes That Repesent Power Supplies, Batteries, And Events Related to these Devices.

ClassDescriptionWin32_AssociatedBatteryRelates a logical device and the battery it is using.Win32_BatteryRepresents a battery connected to the computer system.Win32_CurrentProbeRepresents the properties of a current monitoring sensor (ammeter) .Win32_PortableBatteryRepresents the properties of a portable battery, such as one used for a notebook computer.Win32_PowerManagementEventRepresents power management events resulting from power state changes.Win32_UninterruptiblePowerSupplyRepresents the capabilities and management capacity of an uninterruptible power supply (UPS) .Win32_VoltageProbeRepresents the properties of a voltage sensor (electronic voltmeter) .Printing Classes

The Printing Subcategory Groups Classes That Repesent Printers, Printer Configurations, and Print Jobs.

ClassDescriptionWin32_DriverForDeviceRelates a printer to a printer driver.Win32_PrinterRepresents a device connected to a Windows computer system that is capable of reproducing a visual image on a medium.Win32_PrinterConfigurationDefines the configuration for a printer device.Win32_PrinterControllerRelates a printer and the local device to which the printer is connected .Win32_PrinterDriverRepresents the drivers for a Win32_Printer instance.Win32_PrinterDriverDllRelates a local printer and its driver file (not the driver itself) .Win32_PrinterSettingRelates a printer and its configuration settings.Win32_PrintJobRepresents a print job generated by a Windows application.Win32_TCPIPPrinterPortRepresents a TCP / IP service access point .

Telephony Classes

THETELEPHONY SUBCATEGORY GROUPS CLASS THAT REPRESENT "Plain Old Telephone" Modem Devices and Their Associated Serial Connections.

ClassDescriptionWin32_POTSModemRepresents the services and characteristics of a Plain Old Telephone Service (POTS) modem on a Windows system.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.

ClassDescriptionWin32_DesktopMonitorRepresents the type of monitor or display device attached to the computer system.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 Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution classes. . 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.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.Win32_VideoControllerRepresents the capabilities and management c Apacity of the Video Controller ON A Windows Computer System.win32_videosettingsreLates a Video Controller And Video Settings That Can Be Applied To IT.

And each class has a corresponding data structure such as

Graphics card

Class Win32_videoController: CIM_PCVIDEOCONTROLLER

{

Uint16 acceleratorcapabilities [];

String adaptercompatibility;

String adapterdactype;

Uint32 adapterram;

Uint16 Availability;

String CapabilityDescriptions []; String Caption;

Uint32 colortablentries;

Uint32 configmanagererrorcode;

Boolean configmanageruserConfig;

String CreationClassName;

Uint32 CurrentBitsPerpixel;

UINT32 CurrenthorizontalResolution;

UINT64 CurrentNumberofcolors;

Uint32 currentnumberofcolumns;

Uint32 currentnumberofrow;

Uint32 currentrefreshrate;

UINT16 CURRENTSCANMODE;

UINT32 CURRENTVERTICALRALRESOLUTION;

String description;

String DeviceId;

UINT32 DevicespecificPENS;

Uint32 Dithertype;

Datetime driverdate;

String driverversion;

Boolean errorclead;

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 videoitecture;

UINT16 VIDEMORYTYPE;

UINT16 VIDEOMODE;

String videomodedescription;

String videoprocessor;

}

Sound card, etc.

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;

Such as

Set wmiobjset = getObject ("WinMgmts: {ImpersonationLevel = Impersonate}"). _ Instancesof ("win32_printjob")

You can get information such as print task lists.

For VBs to get system hardware and software information, you use the API, and now use WMI to quickly implement our goal. If you get drive / graphics / sharing information, you will become convenient and effective.

转载请注明原文地址:https://www.9cbs.com/read-29795.html

New Post(0)