Click here to Skip to main content
Email Password   helpLost your password?

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralWMI data to Access DB on the WEB server
mail4kanthan
5:58 7 Nov '07  
It's the script that I have been looking for. You've done a great job for admins like me. Thanks a lot.

My Question: I am looking forward to getting this vbs script to run on user's laptops when they access it through a web site hosted on an Intranetwork. I would like to get the WMI data stored in an MS Access DB located on the Web Server with a unique ID of the Serial numbers.

How can this be accomplished? Is this too much to ask, please help.

Thanks
Sri K
GeneralRe: WMI data to Access DB on the WEB server
Viatcheslav V Vassiliev
7:48 7 Nov '07  
This script will probably not work on HTML page because of security reasons. You may need to run it from hta file (HTML application). To send information to web server I would create XML file on client computer (in memory) and upload it to server; then on server process it and write into MS Access database. As ID of client computers you may use their IPs if they are static.

Note that if your web server runs on x64 OS MS Access can not be used (there are no Access providers for x64) and you will probably need to write information into another DBMS, for example, to MS SQL Server.

Sincerely yours,
Viatcheslav V. Vassiliev
Questioncould this returned data be hacked?
ai.unit
18:09 25 Jan '07  
Could a hacker easily (e.g.: by replacing a DLL in the system) get the WMI to return specific data regardless of the system state?

say i want to check for a specific on board chipset, and prevent my application from running if the chipset wasn't there. and let's say my application's executable is encrypted so it's hard to trace. Couldn't a hacker find out that i'm using WMI to check for the chipset, and make a fake DLL to replace the original WMI functionality and return true always?

I know nothing is impossible, but how easy and likely this is to happen?

thanks Smile


ai.unit -/-
AnswerRe: could this returned data be hacked?
Viatcheslav V Vassiliev
23:58 25 Jan '07  
I do not know so good WMI internals, but I think that WMI enumerates hardware basing on drivers, i.e. it should be possible to write driver to simulate board chipset, but it is not easy. However I never tried to do something similar.

Sincerely yours,
Viatcheslav V. Vassiliev
Answer[Message Removed]
nompel
1:06 5 Oct '08  
Spam message removed
Generalto get installed software
ananth_r
18:56 12 Nov '06  
Hi,
i need a similar source code to get a list of installed software in a pc which is done through a an activex control
GeneralRe: to get installed software
Viatcheslav V Vassiliev
23:09 12 Nov '06  
To list installed software with WMI you may enumerate objects of type Win32_Product. To have it work as ActiveX you may use Windows Script Components (look http://msdn2.microsoft.com/en-us/library/07zhfkh8.aspx to see how it works).

Sincerely yours,
Viatcheslav V. Vassiliev
GeneralIP n MAC Address
Suhaimi Wagiman
0:24 26 Apr '06  
1)Unable to extract info on Networks such as IP Addrss n MAC Addrs.

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
str = str & "

Adapter Configuration

" & vbCRLF
For Each objNetwork in colItems
str = str & GetTableHeader()
str = str & GetRow("IP Address", objNetwork.IPAddress)
str = str & GetRow("MAC Address", objNetwork.MACAddress)
str = str & GetTableFooter()
Next

2) Any idea to pull info on serial no for Dell n HP ?
Thank u in adv
GeneralRe: IP n MAC Address
Viatcheslav V Vassiliev
12:08 26 Apr '06  
Code to enumerate network adapters with WScript:

strComputer = "."

Function GetWMIServices()
Set GetWMIServices = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
End Function

str = ""
Set objWMIService = GetWMIServices()
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
IP = objItem.IPAddress
strIP = ""
If Not IsNull(IP) And IsArray(IP) Then
For I = LBound(IP, 1) To UBound(IP, 1)
strIP = strIP & " " & IP(I)
Next
End If
WScript.Echo "" & objItem.MACAddress & " - " & strIP
Next


SCode to enumerate network adapters with WScript:

strComputer = "."

Function GetWMIServices()
Set GetWMIServices = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
End Function

str = ""
Set objWMIService = GetWMIServices()
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
IP = objItem.IPAddress
strIP = ""
If Not IsNull(IP) And IsArray(IP) Then
For I = LBound(IP, 1) To UBound(IP, 1)
strIP = strIP & " " & IP(I)
Next
End If
WScript.Echo "" & objItem.MACAddress & " - " & strIP
Next


Sincerely yours,
Viatcheslav V. Vassiliev
GeneralRe: IP n MAC Address
xExTxCx
7:36 25 May '07  
<blockquote class="FQ"><div class="FQA">Suhaimi Wagiman wrote:</div>Any idea to pull info on serial no for Dell n HP ?</blockquote>

Set colItems2 = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)

For Each objItem in colItems2
      strDellTag = objItem.SerialNumber
      strManu = objItem.Manufacturer
Next


BRian
QuestionHow send data to Sql server?
dd_tt_cc
10:09 6 Apr '06  
This application is great, wmi is really cool.
I want to know if it's possible to leave this .hta on my intranet, and each time a user visits it, the vbs send the gathered data to a sql server, so I have an updated repository of machines. How can I make that?
Thanks for any suggestion.
AnswerRe: How send data to Sql server?
Viatcheslav V Vassiliev
10:20 6 Apr '06  
The best way to send data to Sql Server (I suppose you mean MS SQL Server) form HTA is ADO. HTA starts as .exe from users computer, and user may see code, so it would be good to create special login on MS SQL Server with limited rights. In .hta you process body.onload and send any information in MS SQL Server. Or you may send information from .vbs script - this way information will be sent every time user request new information.

Sincerely yours,
Viatcheslav V. Vassiliev
QuestionI have A similar Project My self
ujjvalp
17:23 26 Feb '06  
I hav done a similar project.

i dont know about you but i have used the system.management name space to do it.
i have a small problem now.

i hav implemented the interface over the lan but my proffessor wants me to connect to the internet and he wants me to do this using sockets.

i am unalbe to do this.please help.

also i am not able to implement any data base functionality in my vs2003 plz help it gives some error regdb_db_classnotreg or some thing like that please help me in this regard also i am a bit new to the vb and .net world.

plz contact me over mail

ujjvalp@gmail.com

or yahoo messenger
groovy_252001

thanking you

Wink





Ujjval Parnandi
AnswerRe: I have A similar Project My self
Viatcheslav V Vassiliev
21:42 26 Feb '06  
For sockets - look description for class Socket (System.Net.Sockets.Socket) in help for .Net 1.1 SDK. "Class not registered" - one COM class is not registered, wich one is not possible to say without see your code.

Sincerely yours,
Viatcheslav V. Vassiliev
GeneralWin32_Processor & UniqueID
Vitoto
5:24 26 Jan '06  
Hi, you know some alternative for UniqueID ?

Not working in WMI, only SerialNumber but is not unique.

any idea ?

GeneralRe: Win32_Processor & UniqueID
Viatcheslav V Vassiliev
12: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
mitchell50
16:05 20 Dec '06  
See my posting below about VolumeID. (It's NOT a unique number and can be changed by the OS or by the user.)

The processor ID is only available about half the time. The OEM has to set the processor so it will give up that information; otherwise, you'll get "".

If you recall, a few years ago there was a big hubbub about "privacy" when one of the Intel chips came out with a unique processor ID on it. There were some lawsuits and now a user can decide whether or not they want to expose their processor ID. Most processors come with it disabled.

In other words, don't try to use the processor ID as a hardware key. You're better off with a hard disk serial number and manufacturer (NOT the VolumeID).
GeneralWeb Porting
Viper1823
5:39 12 Sep '05  
Great Script.

How do you get this to run via the web because it loads the core program but no info, it seems that hardwareinfo.vbs is not executing?

Help much appreciated.

Tx
JJ
GeneralRe: Web Porting
support@www-sharp.com
12:46 12 Sep '05  
This script runs on local computer, not via web. hardwareinfo.vbs is referenced from index.hta in line:

<SCRIPT language="VBScript" src="HardwareInfo.vbs">

and its procedures are called from onclick event handlers:


Thank you for answering previous question,
Viatcheslav V. Vassiliev
GeneralRe: Web Porting
Ian Cunningham
1:24 21 Sep '05  
Is it possible to make this run on the net at all, or is it impossible? I thought renaming the hta to an htm might work, but it doesn'tFrown
GeneralRe: Web Porting
support@www-sharp.com
1:46 21 Sep '05  
Look at function GetWMIServices() in HardwareInfo.vbs:

strComputer = "."
Function GetWMIServices()
Set GetWMIServices = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
End Function

strComputer is computer name, "." is local computer. This function returns WMI services object, set strComputer to computer name for which to return WMI services object, or change this function to return WMI services the way you need. But HTA or HTML will create WMI services object on computer where it (or IE that shows HTML) is started.

Regards,
Viatcheslav V. Vassiliev
GeneralRe: Web Porting
Ian Cunningham
5:01 21 Sep '05  
Thanks for the reply Viatcheslav.

Does that mean that this code should be able to work if it is renamed to html and uploaded?
GeneralRe: Web Porting
support@www-sharp.com
5:33 21 Sep '05  
It will show data for client computer. However it may have problems with security settings in IE. HTA has less security restrictions. And user should be IE, not any other browser because script is in VBScript.

Regards,
Viatcheslav V. Vassiliev
GeneralRe: Web Porting
Ian Cunningham
6:39 21 Sep '05  
Yes, that seems to be the problem. I've been trying to get the client information, but nothing shows - it must just be security settings. I might have to use an ActiveX control to get the system information I guess.
GeneralHDD Info
brendon.pilott
13:23 5 Sep '05  
Can you update the program to include HDD info, Manufacture, Serial Number, Free Space, Total Size, Logical Disk and Physical Disk info?


Last Updated 8 Mar 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010