Click here to Skip to main content
Licence 
First Posted 7 Mar 2004
Views 299,221
Bookmarked 94 times

Retrieving hardware information with WMI

By | 7 Mar 2004 | Article
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

About the Author

Viatcheslav V. Vassiliev



Russian Federation Russian Federation

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to port this for the web? Pinmemberhartertobak2:56 7 Apr '11  
AnswerRe: How to port this for the web? PinmemberViatcheslav V Vassiliev3:16 7 Apr '11  
QuestionWMI HACK Pinmemberpushpei0:23 7 Apr '10  
AnswerRe: WMI HACK PinmemberViatcheslav V Vassiliev0:40 7 Apr '10  
GeneralRe: WMI HACK Pinmemberpushpendrak17:43 7 Apr '10  
GeneralWMI data to Access DB on the WEB server Pinmembermail4kanthan4:58 7 Nov '07  
GeneralRe: WMI data to Access DB on the WEB server PinmemberViatcheslav V Vassiliev6:48 7 Nov '07  
Questioncould this returned data be hacked? Pinmemberai.unit17:09 25 Jan '07  
AnswerRe: could this returned data be hacked? PinmemberViatcheslav V Vassiliev22:58 25 Jan '07  
Answer[Message Removed] Pinmembernompel0:06 5 Oct '08  
Generalto get installed software Pinmemberananth_r17:56 12 Nov '06  
GeneralRe: to get installed software PinmemberViatcheslav V Vassiliev22:09 12 Nov '06  
GeneralIP n MAC Address PinmemberSuhaimi Wagiman23:24 25 Apr '06  
GeneralRe: IP n MAC Address PinmemberViatcheslav V Vassiliev11:08 26 Apr '06  
GeneralRe: IP n MAC Address PinmemberxExTxCx6:36 25 May '07  
QuestionHow send data to Sql server? Pinmemberdd_tt_cc9:09 6 Apr '06  
AnswerRe: How send data to Sql server? PinmemberViatcheslav V Vassiliev9:20 6 Apr '06  
QuestionI have A similar Project My self Pinmemberujjvalp16:23 26 Feb '06  
AnswerRe: I have A similar Project My self PinmemberViatcheslav V Vassiliev20:42 26 Feb '06  
GeneralWin32_Processor & UniqueID PinmemberVitoto4:24 26 Jan '06  
GeneralRe: Win32_Processor & UniqueID PinmemberViatcheslav V Vassiliev11:30 28 Jan '06  
If you will base on hardware IDs, you will depend on will any hardware (CPU in your case) return this property. You may try to use volume serial for drive c:\ using GetVolumeInformation() from WinAPI.
 
Sincerely yours,
Viatcheslav V. Vassiliev
GeneralRe: Win32_Processor & UniqueID Pinmembermitchell5015:05 20 Dec '06  
GeneralWeb Porting PinmemberViper18234:39 12 Sep '05  
GeneralRe: Web Porting Pinmembersupport@www-sharp.com11:46 12 Sep '05  
GeneralRe: Web Porting PinmemberIan Cunningham0:24 21 Sep '05  

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

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

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