• Home
  • About 404TS
  • Contact

404 Tech Support

Where IT Help is Found

  • Articles
    • Code
    • Entertainment
    • Going Green
    • Hardware, Gadgets, and Products
    • Management
    • Network
    • News
    • Operating Systems
    • Security and Privacy
    • Software
    • System Administration
    • Talking Points
    • Tech Solutions
    • Web
    • Webmaster
  • Reviews
  • Media
    • Infographics
    • Videos
  • Tech Events
  • Tools
    • How do I find my IP address?
    • Browser and plugin tests
  • Get a Technical Consultation
You are here: Home / Articles / Code / Using scripts and WMI to ask a computer more about itself

Using scripts and WMI to ask a computer more about itself

2012-03-08 by Jason

When you sit down to a PC hoping to troubleshoot a problem, the more information you can have about it the better. Sometimes that means crawling under a desk, opening the case, or visiting various locations within Windows to find all the properties you are wanting. If you want to get fancy, you could write a script to get all your information from a single place. Of course, this is just a single use case and there are plenty of other ways this information could be used.

The key to getting this information from the computer is WMI, Windows Management Instrumentation, extensions to the Windows Driver Model that allows us to interface with the operating system and hardware.

There are various ways to utilize WMI. It offers its own command line tool on Windows XP Pro, Server 2003, Vista, Win7, and Server 2008 with WMIC. In the command prompt run WMIC /? for more information.

As an example, here I am querying the architecture (32-bit or 64-bit) of the operating system:

WMIC OS GET OSArchitecture

It returns a simple answer of 64-bit.

Scripting with PowerShell and VBScript are other ways to access the WMI and are more common. They offer a lot more flexibility of what to do with the results and with a better interface. To find the information you want, you will have to query the correct class. Each class has a variety of properties within them that might contain the values you seek. This table shows some of the common ones I used in the example scripts at the bottom.

ClassesDescription
Win32_ProductFinding out about software installed by Windows Installer, particularly Name and Version
Win32_BIOSQuery information from the BIOS like the PC’s serial number and manufacturer
Win32_ProcessorFind out about the CPU (Number of cores, name, clockspeed)
Win32_ComputerSystemFind out about the PC (Manufacturer, Model, and much more)
Win32_OperatingSystemFind out about the OS (active operating system’s name, version, etc)

The Windows Dev Center has a great collection of example scripts split into various areas of usefulness in theĀ WMI Tasks for Scripts and Applications. My scripts extend their examples for properties I found important and useful. The MSDN site has many more example scripts that work out of the box and are ready for tweaking. Just grab your favorite text editor (I use Notepad++) and save the file with a .vbs file extension.

One of the useful, impressive scripts follows. It queries the software installed by Windows Installer and returns the name and version of the software.
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” _
& strComputer & “rootcimv2”)
Set colSoftware = objWMIService.ExecQuery _
(“Select * from Win32_Product”)For Each objSoftware in colSoftware
Wscript.Echo “Name: ” & objSoftware.Name, vbCRLF & “Version: ” & objSoftware.Version
Next

My thought is that I could take this script, narrow it down to the key applications, and convert the script to write out to a file instead of a popup. I would have this script run at login and save the file to a centralized server share. This would allow me to aggregate the data and come up with a consensus of what percentage of computers are up to date and which computers need to be updated.

(To copy multiple .txt files into one, use the command ‘copy *.txt final.txt’ in a directory of the text files.)

I adjusted the query here to only get Adobe Reader and Adobe Flash Player:

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” _
& strComputer & “rootcimv2”)
Set colSoftware = objWMIService.ExecQuery _
(“Select * from Win32_Product Where (Name like ‘Adobe Reader%’) OR (Name like ‘Adobe Flash Player%’)”)For Each objSoftware in colSoftware
Wscript.Echo “Name: ” & objSoftware.Name, vbCRLF & “Version: ” & objSoftware.Version
Next

A longer script, this uses a variety of classes to bring up various information about the computer. You can just comment out the areas for information not needed by adding a ‘ to the left of the line.

‘Interrogate computer for a wide variety of self-identifying properties using Win32_ComputerSystem, Win32_BIOS, and other classes
‘Script written by Jason Hamilton, www.404techsupport.com

Dim objWMI
Set objWMI = GetObject(“winmgmts:”)
Dim colSettingsComp
Set colSettingsComp = objWMI.ExecQuery(“Select * from Win32_ComputerSystem”)
Dim colSettingsBios
Set colSettingsBios = objWMI.ExecQuery(“Select * from Win32_BIOS”)
Dim colSettingsRAM
Set colSettingsRAM = objWMI.ExecQuery(“Select * from Win32_PhysicalMemory”)
Dim colSettingsCPU
Set colSettingsCPU = objWMI.ExecQuery(“Select * from Win32_Processor”)
Dim colSettingsOS
Set colSettingsOS = objWMI.ExecQuery(“Select * from Win32_OperatingSystem”)

Dim objComputer

‘ Reports PC Manufacturer
Dim strManu
For Each objComputer in colSettingsBios
strManu = objComputer.Manufacturer
Next
wscript.echo “Manufacturer: ” & strManu

‘Reports computers identified Model name
Dim strModel
For Each objComputer in colSettingsComp
strModel = objComputer.Model
Next
wscript.echo “Model: ” & strModel

‘ Reports serial number
Dim strSerial
For Each objComputer in colSettingsBios
strSerial = objComputer.SerialNumber
Next
wscript.echo “Serial number: ” & strSerial

‘ Reports Physical Memory installed
‘ Capacity from Win32_PhysicalMemory is more accurate but only returns the value per stick
Dim strRAMB, strRAMKB, strRAMMB, strRAMGB
For Each objComputer in colSettingsComp
strRAM = objComputer.TotalPhysicalMemory
Next
‘ Dividing to convert from bytes to gigabytes
strRAMKB = strRAM / 1024
strRAMMB = strRAMkb / 1024
strRAMGB = strRAMMB / 1024
wscript.echo “Amount of RAM: ” & Round(strRAMGB,2) & “GB”

‘Reports info about CPU
Dim strCPU, numCPU, numCores, CPUManu, CPUName

‘Number of processors
For Each objComputer in colSettingsComp
numCPU = objComputer.NumberOfProcessors
Next

‘Processor manufacturer
For Each objComputer in colSettingsCPU
CPUManu = objComputer.Manufacturer
Next

‘Processor name
For Each objComputer in colSettingsCPU
CPUName = objComputer.Name
Next

‘Number of cores
For Each objComputer in colSettingsCPU
numCores = objComputer.NumberOfCores
Next

‘CPU clockspeed
For Each objComputer in colSettingsCPU
strCPU = objComputer.MaxClockSpeed
Next
strCPU = strCPU / 1000

‘CPU Report output
wscript.echo numCPU & ” ” & CPUManu & ” ” & CPUName, vbCRLF & numCores & ” cores @” & strCPU & “GHz”

‘Operating system information
Dim strOSName, strOSArch
For Each objComputer in colSettingsOS
strOSName = objComputer.Caption
Next
For Each objComputer in colSettingsComp
strOSArch = objComputer.SystemType
Next
wscript.echo “OS: ” & strOSName & ” ” & strOSArch

These scripts have been tested on Windows 7 x64.

Filed Under: Code

Trending

  • Product Review: ScreenDeck – A Shelf For Your HDTV Accessories
    In Hardware, Gadgets, and Products, Reviews
  • Lockheed Martin targeted with Adobe Acrobat vulnerability? Adobe schedules patch
    In Security and Privacy
  • Built-in browser functions prove server-side validation necessary
    In Featured, Security and Privacy, Software

Latest Media Posts

Find Out Where To Download SNES ROMs

Find Out Where To Download SNES ROMs

Multifunctional Video Conversion Tools – Wondershare Video Converter

Multifunctional Video Conversion Tools – Wondershare Video Converter

  • Popular
  • Latest
  • Today Week Month All
  • Access to the resource [servershare] has been disallowed Access to the resource [servershare] has been disallowed
  • Read the Event Logs on Windows Server Core Read the Event Logs on Windows Server Core
  • Increase IIS Private Memory Limit to improve WSUS availability Increase IIS Private Memory Limit to improve WSUS availability
  • How to ‘Unblock’ multiple files at a time with PowerShell How to 'Unblock' multiple files at a time with PowerShell
  • Setup your DFS namespace with DNS for compatibility in a mixed environment Setup your DFS namespace with DNS for compatibility in a mixed environment
  • How Virtual Reality Supports Mental Health Therapy How Virtual Reality Supports Mental Health Therapy
  • Key Strategies of Successful Coin Listing on Exchange Key Strategies of Successful Coin Listing on Exchange
  • Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting
  • Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams Making Distributed Software Development Work: Strategies and Best Practices for Managing Remote Teams
  • customer contactless payment for drink with mobile phon at cafe counter bar,seller coffee shop accept payment by mobile.new normal lifestyle concept The Latest Innovations In Payment Technology
Ajax spinner

Elevator Pitch

404 Tech Support documents solutions to IT problems, shares worthwhile software and websites, and reviews hardware, consumer electronics, and technology-related books.

Subscribe to 404TS articles by email.

Recent Posts

  • How Virtual Reality Supports Mental Health Therapy
  • Key Strategies of Successful Coin Listing on Exchange
  • Keeping Your Mac Healthy: A Comprehensive Guide to Maintenance and Troubleshooting

Search

FTC Disclaimer

404TechSupport is an Amazon.com affiliate; when you click on an Amazon link from 404TS, the site gets a cut of the proceeds from whatever you buy. This site also uses Skimlinks for smart monetization of other affiliate links.
Use of this site requires displaying and viewing ads as they are presented.

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in