Rob van der Woude's Scripting Pages

Hardware Requirements

Before installing software we often need to know if a computer meets that software's minimum hardware requirements, like the type of processor, the amount of physical memory, the screen resolution or available harddisk space (rarely a hardware issue).

There are many alternative ways to determine installed software versions, but to check hardware nothing beats WMI.

On this page, I will show several sample WMI queries to check hardware requirements.
Some ready-to-run sample scripts are available as well, including some that don't use WMI.

To find out which WMI class you need, you can search MSDN's list of WMI Classes, or you can run one of many available tools to browse WMI:

Alternative Tools

Instead of using WMI, you can also retrieve system information from DMI, also known as SMBIOS.
Though the information available through SMBIOS is not as extensive as the information available through WMI, it is often much faster to retrieve.
There are no native commands to read SMBIOS information, however, so you will need a third party tool like DMIDecode.exe, or you can write and compile your own program.
Use the command dmidecode to list all available information.
Use the command dmidecode -t to see what categories of information are available, then select a category and use dmidecode -t category to list available information for that category.

For programmers, the WINAPI (user32.dll) GetSystemMetrics function may be a useful tool to retrieve information, especially on monitors and input devices.
I wrote a "wrapper" for this function, GetSystemMetrics.exe, which can be used in batch files to retrieve system information.

Microsoft's DEVCON (DEVice manager CONsole tool) can be used in batch files to detect, remove or install devices and drivers.

On this page, I will provide some alternatives to WMI, all requiring DMIDecode.exe or GetSystemMetrics.exe.

Categories

Processor

The following code lists some of the CPU properties that we may want to query before starting a software installation.
For the full list of available properties, use one of the WMI tools listed above and/or search MSDN.

Batch


KiXtart


PowerShell


VBScript

' List a selection of processor properties
On Error Resume Next
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_Processor" )
For Each objItem In colItems
	WScript.Echo "Architecture                 : " & objItem.Architecture
	WScript.Echo "Current Clock Speed          : " & objItem.CurrentClockSpeed & " MHz"
	WScript.Echo "Description                  : " & objItem.Description
	WScript.Echo "Device ID                    : " & objItem.DeviceID
	WScript.Echo "External Clock Speed         : " & objItem.ExtClock & " MHz"
	WScript.Echo "Family                       : " & objItem.Family
	WScript.Echo "Level                        : " & objItem.Level
	WScript.Echo "Manufacturer                 : " & objItem.Manufacturer
	WScript.Echo "Name                         : " & objItem.Name
	WScript.Echo "Number Of Cores              : " & objItem.NumberOfCores
	WScript.Echo "Number Of Logical Processors : " & objItem.NumberOfLogicalProcessors
	WScript.Echo "Other Family Description     : " & objItem.OtherFamilyDescription
	WScript.Echo "Processor Type               : " & objItem.ProcessorType
	WScript.Echo "Revision                     : " & objItem.Revision
	WScript.Echo "Status Info                  : " & objItem.StatusInfo
	WScript.Echo "Stepping                     : " & objItem.Stepping
	WScript.Echo "Version                      : " & objItem.Version
	WScript.Echo
Next

The NumberOfCores and NumberOfLogicalProcessors properties are available in Windows XP Professional SP3 and later, not in Windows XP SP2 and older versions.
If in doubt, you may want to count the For Each loop's iterations.

Full details on the Win32_Processor class' properties and their possible values and meaning can be found on MSDN.

 

To check for a 1GHz Intel Pentium 4 or better, we would have to list all processors of ProcessorType 3 (Central Processor), with StatusInfo 3 (Enabled), Architecture 0 (x86) and a CurrentClockSpeed value of 1000 (MHz) or more and then check for several "Family values".
AMD processors will have to be tested separately...

The following sample code exits with return code 0 if all of the requirements mentioned are met for at least one processor, or 1 if not:

Batch


KiXtart


PowerShell


VBScript

' Set return code to 1 (requirements not met)
intRC = 1

' Filter for the proper Architecture, ProcessorType and StatusInfo
strQuery = "SELECT * FROM Win32_Processor WHERE ProcessorType='3' AND StatusInfo='3' AND Architecture='0'"
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery )

' Check each processor
For Each objItem In colItems
	' Check the clock speed
	If objItem.CurrentClockSpeed > 999 Then
		' Is the ProcessorFamily value in the 178..183 range?
		If objItem.Family > 177 And objItem.Family < 184 Then
			' If all requirements are met, set the return code to 0
			intRC = 0
		End If
	End If
Next

' Exit with the proper return code
WScript.Quit intRC

Processor Info Without WMI

The command dmidecode -t processor will provide information like this:

# dmidecode 2.10
SMBIOS 2.5 present.

Handle 0x0004, DMI type 4, 40 bytes
Processor Information
        Socket Designation: AM3
        Type: Central Processor
        Family: Other
        Manufacturer: AMD
        ID: A0 0F 10 00 FF FB 8B 17
        Version: AMD Phenom(tm) II X6 1100T Processor
        Voltage: 1.5 V
        External Clock: 200 MHz
        Max Speed: 3700 MHz
        Current Speed: 3300 MHz
        Status: Populated, Enabled
        Upgrade: Other
        L1 Cache Handle: 0x0005
        L2 Cache Handle: 0x0006
        L3 Cache Handle: 0x0007
        Serial Number: To Be Filled By O.E.M.
        Asset Tag: To Be Filled By O.E.M.
        Part Number: To Be Filled By O.E.M.
        Core Count: 6
        Core Enabled: 6
        Characteristics:
                64-bit capable

Physical Memory

Without command line arguments, the following code displays the physical memory in MBs.
If a number is specified, nothing is displayed; the script will exit with return code 0 if the actual memory matches or exceeds the specified number of MBs, or 1 if it is less.

Batch


KiXtart


PowerShell


VBScript

intMem = 0
intRC  = 0

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_PhysicalMemory" )

' Sum the capacity of all memory modules
For Each objItem In colItems
	intMem = intMem + objItem.Capacity
Next

' If a minimum number of MB was specified, check if the actual
' amount of physical memory matches this minimum requirement;
' if no number is specified, just display the number of MBs
If WScript.Arguments.Unnamed.Count = 1 Then
	' Set return code to 1 (requirement not met)
	intRC  = 1
	intReq = WScript.Arguments.Unnamed(0)
	If IsNumeric( intReq ) Then
		' If the requirement is met, set return code to 0
		If intMem >= 1024 * 1024 * intReq Then intRC = 0
	End If
Else
	' Display the physical memory in MBs
	WScript.Echo intMem / ( 1024 * 1024 )
End If

' Exit with the appropriate return code
WScript.Quit intRC

More than 3GB in Windows XP: PAE

If more than 3GB of physical memory is required (some programs, like AutoCAD, really do) and installed in Windows XP, check if PAE is enabled: if it is, the registry DWORD value PhysicalAddressExtension in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management will be 0x1.

The following batch code will return this value:

Batch


KiXtart


PowerShell

$regpath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\"
( Get-ItemProperty -Path $regpath -Name "PhysicalAddressExtension" ).PhysicalAddressExtension | Select-Object -OutVariable PAE
$ENV:PAE = $PAE

VBScript

Set wshShell = CreateObject( "WScript.Shell" )

strHive = "HKEY_LOCAL_MACHINE"
strKey = "\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\"
strValue = "PhysicalAddressExtension"

If CInt( wshShell.RegRead( strHive & strKey & strValue ) ) = 1 Then
	blnPAE = True
Else
	blnPAE = False
End If

Set wshShell = Nothing

WScript.Echo "Physical Address Extension enabled: " & blnPAE

Memory Info Without WMI

The command dmidecode -t memory will provide information like this:

# dmidecode 2.10
SMBIOS 2.5 present.

Handle 0x003B, DMI type 16, 15 bytes
Physical Memory Array
	Location: System Board Or Motherboard
	Use: System Memory
	Error Correction Type: None
	Maximum Capacity: 16 GB
	Error Information Handle: Not Provided
	Number Of Devices: 2

Handle 0x003D, DMI type 17, 27 bytes
Memory Device
	Array Handle: 0x003B
	Error Information Handle: Not Provided
	Total Width: 64 bits
	Data Width: 64 bits
	Size: 8192 MB
	Form Factor: DIMM
	Set: None
	Locator: DIMM0
	Bank Locator: BANK0
	Type: DDR
	Type Detail: Synchronous
	Speed: 1333 MHz
	Manufacturer: Manufacturer00
	Serial Number: SerNum00
	Asset Tag: AssetTagNum0
	Part Number: ModulePartNumber00

Handle 0x003F, DMI type 17, 27 bytes
Memory Device
	Array Handle: 0x003B
	Error Information Handle: Not Provided
	Total Width: Unknown
	Data Width: Unknown
	Size: No Module Installed
	Form Factor: DIMM
	Set: None
	Locator: DIMM1
	Bank Locator: BANK1
	Type: Unknown
	Type Detail: None
	Speed: Unknown
	Manufacturer: Manufacturer01
	Serial Number: SerNum01
	Asset Tag: AssetTagNum1
	Part Number: ModulePartNumber01

Disk Space

Querying free disk space may be quite simple, as the batch file demonstrates.
The other scripts below may look intimidating, but they are more usefull to test for hardware requirements. They require a command line argument specifying the required free disk space in MBs or GBs, and list the drives that meet the requirement. They return an "ErrorLevel" 0 if at least one drive meets the requirement, or 1 if not.
The VBScript version also accepts a drive letter as an optional second argument.

Batch


KiXtart


PowerShell


VBScript

Option Explicit

Dim intFree, intMinReq, intRC, strDrive, strQuery, objWMIService, colItems, objItem

If WScript.Arguments.Count = 1 Then
	intMinReq = CLng( WScript.Arguments(0) )
	strQuery  = "SELECT * FROM Win32_LogicalDisk WHERE DriveType='3'"
ElseIf WScript.Arguments.Count = 2 Then
	strDrive  = WScript.Arguments(0)
	intMinReq = CLng( WScript.Arguments(1) )
	strQuery  = "SELECT * FROM Win32_LogicalDisk WHERE DriveType='3' AND DeviceID='" & strDrive & "'"
Else
	WScript.Echo "Usage:    " & WScript.ScriptName & "  [ drive ]  minfree" & vbCrLf & vbCrLf _
	           & "Where:    drive    is the drive to check for free space (default: all)" & vbCrLf _
	           & "          minfree  is the minimum amount of free space required, in MB" & vbCrLf & vbCrLf _
	           & "Returns:  return code 0 if the specified drive (or if not specified: ANY drive)" & vbCrLf _
	           & "          has the required amount of free space available, 1 if not, 2 on errors"
	WScript.Quit 2
End If

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery )
intRC = 1
For Each objItem In colItems
	intFree = CLng( objItem.FreeSpace / ( 1024 * 1024 ) )
	If intFree >= intMinReq Then
		WScript.Echo objItem.DeviceID & vbTab & intFree & " MB"
		intRC = 0
	End If
Next

WScript.Quit intRC

Full details on the Win32_LogicalDisk class' properties and their possible values and meaning can be found on MSDN.

Video

Screen resolutions are hardly ever a problem these days. However, you still may want to check it for some installations.
WMI makes this a snap:

Batch


KiXtart


PowerShell


VBScript

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_VideoController" )
For Each objItem In colItems
	WScript.Echo objItem.CurrentHorizontalResolution & " x " & objItem.CurrentVerticalResolution & ", " & objItem.CurrentNumberOfColors & " colors"
Next

The code above is fine to "manually" check the resolution, but for unattended installations a comparison is more useful.
The following code will display nothing unless invalid arguments are passed on the command line. It will exit with a return code 0 if the actual screen resolution meets the specified minimum requirements, or 1 if it doesn't.
Mandatory command line arguments are the minimum required horizontal and vertical resolution in pixels:

Batch


KiXtart


PowerShell


VBScript

intRC     = 0
intColors = 0
intHor    = 0
intVert   = 0

' Parse the command line arguments
With WScript.Arguments.Unnamed
	If .Count = 2 Or .Count = 3 Then
		If IsNumeric( .Item(0) ) Then
			intHor  = CInt( .Item(0) )
		Else
			Syntax
		End If
		If IsNumeric( .Item(1) ) Then
			intVert = CInt( .Item(1) )
		Else
			Syntax
		End If
		If .Count = 3 Then
			If IsNumeric( .Item(2) ) Then
				intColors = CInt( .Item(2) )
			Else
				Syntax
			End If
		End If
	Else
		Syntax
	End If
End With

' Read the actual screen resolution
strQuery = "SELECT * FROM Win32_VideoController"
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery )

' Compare the actual resolution with the minimum required values
For Each objItem In colItems
	If objItem.CurrentHorizontalResolution < intHor    Then intRC = 1
	If objItem.CurrentVerticalResolution   < intVert   Then intRC = 1
Next

Set colItems      = Nothing
Set objWMIService = Nothing

' Exit with the appropriate return code
WScript.Quit intRC


Sub Syntax
	With WScript
		.Echo "Check if the screen resolution meets your minimum requirements" & vbCrLf & vbCrLf _
			& "Usage:  " & UCase( .ScriptName ) & " min_hor min_vert" & vbCrLf & vbCrLf _
			& "Where:  ""min_hor""     is the minimum required horizontal resolution in pixels" & vbCrLf _
			& "        ""min_vert""    is the minimum required vertical resolution in pixels" & vbCrLf & vbCrLf _
			& "Note:   Return code 0 if requirements are met, 1 if not, 2 on errors"
		.Quit 2
	End With
End Sub

Video Info Without WMI

Use the command GetSystemMetrics.exe 0 to get the horizontal resolution of the primary display, GetSystemMetrics.exe 1 for the vertical resolution, or GetSystemMetrics.exe 80 to get the number of connected monitors.

More metrics can be found on MSDN.

Sample Scripts

Click the diskette icon to download the ZIPped source Click the floppy disk icons to download the ZIPped sources

 

Click the diskette icon to download the ZIPped source Name Description Technique Remarks
Click the diskette icon to download the ZIPped source BootDisk.bat Determine the boot disk, partition and drive letter WMI  
Click the diskette icon to download the ZIPped source BootDriv.bat (DOS)
BootDriv.bat (NT)
BootDriv.bat (XP)
BootDriv.rex
BootDriv.vbs
Return boot drive letter Environment
Environment
WMI
API
WMI
VBScript and XP versions created using script code found in TechNet Script Center: "Disks and File Systems" section (no longer available?)
Click the diskette icon to download the ZIPped source CDROM.bat
CDROMXP.bat
CDROM.kix
CDROM.rex
CDROM.vbs
Display all CD-ROM drive letters Registry
FileSystem
WMI
FileSystem
WMI
 
Click the diskette icon to download the ZIPped source CheckRes.vbs Check if the screen resolution meets a specified minimum requirement, and exit with return code 1 if not WMI  
Click the diskette icon to download the ZIPped source COMPorts.vbs Display serial ports information WMI  
Click the diskette icon to download the ZIPped source CPUSpeed.vbs Display CPU speed for each processor WMI  
Click the diskette icon to download the ZIPped source CPUSpeedTD.vbs Display CPU speed for each processor in tab delimited format WMI  
Click the diskette icon to download the ZIPped source CPUType.vbs Display CPU type WMI  
Click the diskette icon to download the ZIPped source CPUTypeTD.vbs Display CPU type in tab delimited format WMI  
Click the diskette icon to download the ZIPped source DiskSpc.bat Display harddisk summary for any WMI enabled computer or for a list of computers WMI  
Click the diskette icon to download the ZIPped source DispEDID.vbs Display the monitor's EDID asset information Registry Based on a script by Michael Baird (link no longer available)
Click the diskette icon to download the ZIPped source Drives.bat List local drive letters and types Registry  
Click the diskette icon to download the ZIPped source FreeSpace.rex
FreeSpace.vbs
Display a disk space summary API
WMI
 
Click the diskette icon to download the ZIPped source GetCDROMDrives.bat
GetCDROMDrivesXP.bat
GetFlashDrives.bat
GetFlashDrivesXP.bat
List all CDROM or removable "flash" drive letters Registry  
Click the diskette icon to download the ZIPped source GetPorts.bat
GetPorts.pl
GetPorts.rex
Show I/O addresses for serial and parallel ports DEBUG  
Click the diskette icon to download the ZIPped source GetRAM.bat (NT4)
GetRAM2K.bat (W2K)
GetRAM.vbs
Display the amount of physical memory installed WINMSD
WINMSD
WMI
VBScript version based on WMI Scripting Primer: Part 1 by Greg Stemp, Dean Tsaltas and Bob Wells.
Click the diskette icon to download the ZIPped source GetRes.bat
GetResXP.bat
GetRes.pl
GetRes.ps1
GetRes.vbs
Display Windows 2000's screen resolution and refresh rate Registry
Registry
WMI
WMI
WMI
 
Click the diskette icon to download the ZIPped source GetSystemMetrics 0
GetSystemMetrics 1
GetSystemMetrics 80
Display width (0) or height (1) of primary display, or number of connected monitors (80) GetSystemMetrics Requires my GetSystemMetrics.exe wrapper.
Click the diskette icon to download the ZIPped source HardDisk.bat List harddisks, their interfaces and revision numbers for any computer on the network DEVCON Requires Microsoft's DEVCON. The script will prompt you to download DEVCON if it isn't found.
Click the diskette icon to download the ZIPped source Hardware.bat
Hardware.kix
Hardware.vbs
Display a basic hardware summary for any WMI enabled computer on the network WMI  
Click the diskette icon to download the ZIPped source IsLaptop.kix
IsLaptop.vbs
Check if the script runs on a laptop or not WMI Based on Guy Thomas' CHASSIS.VBS script
Click the diskette icon to download the ZIPped source Memory.bat Show the amount of RAM in MB 3rd Party Use GetRAM.bat instead if you do not have the NT Resource Kit available
Click the diskette icon to download the ZIPped source Memory.ps1 Display a physical memory summary WMI  
Click the diskette icon to download the ZIPped source Modems List all modems installed on the computer DEVCON Requires Microsoft's command line device management utility DEVCON
Click the diskette icon to download the ZIPped source NICSpeed.bat
NICSpeed.kix
NICSpeed.vbs
Display ethernet adapters' link speed WMI  
Click the diskette icon to download the ZIPped source PhysMem.vbs Display a physical memory summary WMI  
Click the diskette icon to download the ZIPped source SCSI.bat
SCSI.kix
SCSI.rex
Enumerate disk drives (IDE and SCSI) Registry  
Click the diskette icon to download the ZIPped source ShowPRN.ps1
ShowPRN.vbs
Display all installed printers and their properties WMI  
Click the diskette icon to download the ZIPped source ShowPRNT.vbs Display all installed printers and their properties in TAB delimited format WMI  
Click the diskette icon to download the ZIPped source TouchDetect.exe Check if touch enabled input devices are available GetSystemMetrics  
Click the diskette icon to download the ZIPped source VideoROM.bat
VideoROM.kix
VideoROM.pl
VideoROM.rex
VideoROM.vbs
Display video adapter summary DEBUG
WMI
DEBUG
DEBUG
WMI
 

 

 


page last uploaded: 2016-07-15, 10:23