Click here to Skip to main content
12,304,228 members (66,215 online)
Click here to Skip to main content
Add your own
alternative version

Stats

352.6K views
12.4K downloads
105 bookmarked
Posted

Retrieving hardware information with WMI

, 7 Mar 2004
Rate this:
Please Sign up or sign in to vote.
An article on using WMI to retrieve hardware information.

Introduction

Windows Management Instrumentation (WMI) is a scalable system management infrastructure that uses a single, consistent, standards-based, extensible, object-oriented interface. WMI provides you with a standard way to interact with system management information and the underlying WMI APIs. WMI is used primarily by system management application developers and administrators to access and manipulate system management information.

The purpose of WMI is to provide a standardized means for managing your computer system, be it a local computer or all the computers in an enterprise. In its simplest terms, management is little more than collecting data about the state of a managed object on the computer system and altering the state of the managed object by changing the data stored about the object. A managed object can be a hardware entity, such as a memory array, port, or disk drive. It can also be a software entity, such as a service, user account, or page file.

WMI can manage the many components of a computer system. In managing a hard disk, you can use WMI to monitor the amount of free space remaining on the disk. You could also use WMI to remotely alter the state of the drive by deleting files, changing file security, or partitioning or formatting the drive.

WMI is not only a powerful tool to collect system information, it is also very easy to use. Existing scripting WMI interface makes it possible to be used for system administrators and web-designers as well as for skilled programmers.

Presented application displays hardware information in HTML page and uses VBScript as back-end programming language.

First of all, we set strComputer (name of the computer to get information from) to "." - current computer, and write function GetWMIServices() - this function will be used in all procedures that get information from WMI and can be modified to get WMI services from another computer.

Then we define some function that will format output - WMIDateStringToDate(), DisplayOutputHeader(), DisplayOutput(), GetTableHeader(), GetTableFooter(), GetRow(). With these functions, we will have standardized output.

Code

For example, the code for retrieving and displaying processor(s) information is:

Function  ShowProcessorInfo()
  On  Error  Resume  Next
  DisplayOutputHeader("Processor  -  Win32_Processor")
  str  =  ""
  Set  objWMIService  =  GetWMIServices()
  Set  colItems  =  objWMIService.ExecQuery( _
    "Select  *  from  Win32_Processor")
  For  Each  objItem  in  colItems
          str  =  str  &  GetTableHeader()
          str  =  str  &  GetRow("Address  Width",  objItem.AddressWidth)
          str  =  str  &  GetRow("Architecture",  objItem.Architecture)
          str  =  str  &  GetRow("Availability",  objItem.Availability)
          str  =  str  &  GetRow("CPU  Status",  objItem.CpuStatus)
          str  =  str  &  GetRow("Current  Clock  Speed",  _
             objItem.CurrentClockSpeed)
          str  =  str  &  GetRow("Data  Width",  objItem.DataWidth)
          str  =  str  &  GetRow("Description",  objItem.Description)
          str  =  str  &  GetRow("Device  ID",  objItem.DeviceID)
          str  =  str  &  GetRow("Ext  Clock",  objItem.ExtClock)
          str  =  str  &  GetRow("Family",  objItem.Family)
          str  =  str  &  GetRow("L2  Cache  Size",  objItem.L2CacheSize)
          str  =  str  &  GetRow("L2  Cache  Speed",  objItem.L2CacheSpeed)
          str  =  str  &  GetRow("Level",  objItem.Level)
          str  =  str  &  GetRow("Load  Percentage",  objItem.LoadPercentage)
          str  =  str  &  GetRow("Manufacturer",  objItem.Manufacturer)
          str  =  str  &  GetRow("Maximum  Clock  Speed",  _
            objItem.MaxClockSpeed)
          str  =  str  &  GetRow("Name",  objItem.Name)
          str  =  str  &  GetRow("PNP  Device  ID",  objItem.PNPDeviceID)
          str  =  str  &  GetRow("Processor  Id",  objItem.ProcessorId)
          str  =  str  &  GetRow("Processor  Type",  objItem.ProcessorType)
          str  =  str  &  GetRow("Revision",  objItem.Revision)
          str  =  str  &  GetRow("Role",  objItem.Role)
          str  =  str  &  GetRow("Socket  Designation",  _
              objItem.SocketDesignation)
          str  =  str  &  GetRow("Status  Information",  objItem.StatusInfo)
          str  =  str  &  GetRow("Stepping",  objItem.Stepping)
          str  =  str  &  GetRow("Unique  Id",  objItem.UniqueId)
          str  =  str  &  GetRow("Upgrade  Method",  objItem.UpgradeMethod)
          str  =  str  &  GetRow("Version",  objItem.Version)
          str  =  str  &  GetRow("Voltage  Caps",  objItem.VoltageCaps)
          str  =  str  &  GetTableFooter()
  Next
  DisplayOutput(str)
End  Function

HardwareInfo retrieves also information about baseboard, batteries, BIOS, memory settings, PnP devices, ports and some others.

At the last point, customize look of the application with cascading style sheet - the easiest way to create good looking interface. Application can run as is - just double-click on index.hta file or it can be compiled into single file. Retrieving information about installed hardware items with Windows Management Instrumentation is very easy and requires minimal programming skills.

HardwareInformation application is written as HTA (HTML application) and compiled with compiler provided with www-Sharp.ClrHost that is available for free. www-Sharp includes WMI viewer that can be used to visually explore WMI classes and properties and write powerful WMI applications.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Viatcheslav V. Vassiliev
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

 
SuggestionMessage Automatically Removed Pin
15-May-14 6:59
memberkamleshgs15-May-14 6:59 
QuestionHow to port this for the web? Pin
hartertobak7-Apr-11 2:56
memberhartertobak7-Apr-11 2:56 
AnswerRe: How to port this for the web? Pin
Viatcheslav V Vassiliev7-Apr-11 3:16
memberViatcheslav V Vassiliev7-Apr-11 3:16 
QuestionWMI HACK Pin
pushpei7-Apr-10 0:23
memberpushpei7-Apr-10 0:23 
AnswerRe: WMI HACK Pin
Viatcheslav V Vassiliev7-Apr-10 0:40
memberViatcheslav V Vassiliev7-Apr-10 0:40 
GeneralRe: WMI HACK Pin
pushpendrak7-Apr-10 17:43
memberpushpendrak7-Apr-10 17:43 
GeneralWMI data to Access DB on the WEB server Pin
mail4kanthan7-Nov-07 4:58
membermail4kanthan7-Nov-07 4:58 
GeneralRe: WMI data to Access DB on the WEB server Pin
Viatcheslav V Vassiliev7-Nov-07 6:48
memberViatcheslav V Vassiliev7-Nov-07 6:48 
Questioncould this returned data be hacked? Pin
ai.unit25-Jan-07 17:09
memberai.unit25-Jan-07 17:09 
AnswerRe: could this returned data be hacked? Pin
Viatcheslav V Vassiliev25-Jan-07 22:58
memberViatcheslav V Vassiliev25-Jan-07 22:58 
Answer[Message Removed] Pin
nompel5-Oct-08 0:06
membernompel5-Oct-08 0:06 
Generalto get installed software Pin
ananth_r12-Nov-06 17:56
memberananth_r12-Nov-06 17:56 
GeneralRe: to get installed software Pin
Viatcheslav V Vassiliev12-Nov-06 22:09
memberViatcheslav V Vassiliev12-Nov-06 22:09 
GeneralIP n MAC Address Pin
Suhaimi Wagiman25-Apr-06 23:24
memberSuhaimi Wagiman25-Apr-06 23:24 
GeneralRe: IP n MAC Address Pin
Viatcheslav V Vassiliev26-Apr-06 11:08
memberViatcheslav V Vassiliev26-Apr-06 11:08 
GeneralRe: IP n MAC Address Pin
xExTxCx25-May-07 6:36
memberxExTxCx25-May-07 6:36 
QuestionHow send data to Sql server? Pin
dd_tt_cc6-Apr-06 9:09
memberdd_tt_cc6-Apr-06 9:09 
AnswerRe: How send data to Sql server? Pin
Viatcheslav V Vassiliev6-Apr-06 9:20
memberViatcheslav V Vassiliev6-Apr-06 9:20 
QuestionI have A similar Project My self Pin
ujjvalp26-Feb-06 16:23
memberujjvalp26-Feb-06 16:23 
AnswerRe: I have A similar Project My self Pin
Viatcheslav V Vassiliev26-Feb-06 20:42
memberViatcheslav V Vassiliev26-Feb-06 20:42 
GeneralWin32_Processor & UniqueID Pin
Vitoto26-Jan-06 4:24
memberVitoto26-Jan-06 4:24 
GeneralRe: Win32_Processor & UniqueID Pin
Viatcheslav V Vassiliev28-Jan-06 11:30
memberViatcheslav V Vassiliev28-Jan-06 11:30 
GeneralRe: Win32_Processor & UniqueID Pin
mitchell5020-Dec-06 15:05
membermitchell5020-Dec-06 15:05 
GeneralWeb Porting Pin
Viper182312-Sep-05 4:39
memberViper182312-Sep-05 4:39 
GeneralRe: Web Porting Pin
support@www-sharp.com12-Sep-05 11:46
membersupport@www-sharp.com12-Sep-05 11:46 
GeneralRe: Web Porting Pin
Ian Cunningham21-Sep-05 0:24
memberIan Cunningham21-Sep-05 0:24 
GeneralRe: Web Porting Pin
support@www-sharp.com21-Sep-05 0:46
membersupport@www-sharp.com21-Sep-05 0:46 
GeneralRe: Web Porting Pin
Ian Cunningham21-Sep-05 4:01
memberIan Cunningham21-Sep-05 4:01 
GeneralRe: Web Porting Pin
support@www-sharp.com21-Sep-05 4:33
membersupport@www-sharp.com21-Sep-05 4:33 
GeneralRe: Web Porting Pin
Ian Cunningham21-Sep-05 5:39
memberIan Cunningham21-Sep-05 5:39 
GeneralHDD Info Pin
brendon.pilott5-Sep-05 12:23
memberbrendon.pilott5-Sep-05 12:23 
GeneralRe: HDD Info Pin
Viper182312-Sep-05 4:31
memberViper182312-Sep-05 4:31 
GeneralRe: HDD Info Pin
mitchell5020-Dec-06 15:01
membermitchell5020-Dec-06 15:01 
QuestionRe: HDD Info Pin
DElwy13-Jan-07 22:56
memberDElwy13-Jan-07 22:56 
AnswerRe: HDD Info Pin
Shady14u3-Oct-07 13:46
memberShady14u3-Oct-07 13:46 
GeneralRe: HDD Info Pin
bensten20-Nov-07 9:45
memberbensten20-Nov-07 9:45 
GeneralRAM Manufacturer Pin
Sameers (theAngrycodeR )13-Aug-05 9:42
memberSameers (theAngrycodeR )13-Aug-05 9:42 
GeneralRe: RAM Manufacturer Pin
support@www-sharp.com14-Aug-05 4:53
membersupport@www-sharp.com14-Aug-05 4:53 
GeneralRe: RAM Manufacturer Pin
Sameers (theAngrycodeR )14-Aug-05 9:18
memberSameers (theAngrycodeR )14-Aug-05 9:18 
GeneralRe: RAM Manufacturer Pin
Gecko264818-Jan-06 15:33
memberGecko264818-Jan-06 15:33 
GeneralRe: RAM Manufacturer Pin
ckw20686-Mar-07 9:09
memberckw20686-Mar-07 9:09 
GeneralWin32_Fan Pin
Yeast2724-Apr-05 20:21
memberYeast2724-Apr-05 20:21 
GeneralRe: Win32_Fan Pin
support@www-sharp.com25-Apr-05 10:13
membersupport@www-sharp.com25-Apr-05 10:13 
GeneralRe: Win32_Fan Pin
Yeast2725-Apr-05 15:39
memberYeast2725-Apr-05 15:39 
GeneralRe: Win32_Fan Pin
support@www-sharp.com27-Apr-05 9:57
membersupport@www-sharp.com27-Apr-05 9:57 
Generalort Mnitoring in .Net using WMI Pin
Anonymous5-Apr-05 21:01
sussAnonymous5-Apr-05 21:01 
GeneralRe: ort Mnitoring in .Net using WMI Pin
support@www-sharp.com6-Apr-05 8:33
membersupport@www-sharp.com6-Apr-05 8:33 
GeneralWindows 98 Pin
RDavid201024-Mar-05 13:09
sussRDavid201024-Mar-05 13:09 
GeneralRe: Windows 98 Pin
support@www-sharp.com24-Mar-05 23:39
membersupport@www-sharp.com24-Mar-05 23:39 
GeneralI Have Problems Pin
Kabloc6-Oct-04 7:05
memberKabloc6-Oct-04 7:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160530.1 | Last Updated 8 Mar 2004
Article Copyright 2004 by Viatcheslav V. Vassiliev
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid