Search This Blog

Monday, March 01, 2010

Detecting 32bit or 64bit OS in VBscript

As part of the process of updating some machines to 64bit this week, I realized that I'll have to adjust existing code to automate updates and service packs on the affected machines. I wrote previously about a similar function in lisp here.

Here is the VBScript version:

On Error Resume Next

Dim WshShell
Dim OsType

Set WshShell = CreateObject("WScript.Shell")

OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")

If OsType = "x86" then
wscript.echo "Windows 32bit system detected"
elseif OsType = "AMD64" then
wscript.echo "Windows 64bit system detected"
end if


Anonymous said...

I belive this method returns 64 bit when you have a 32-bit OS running on 64-bit capable hardware.

Here is a VBScript / WMI one-liner that retrieves the actuals bits number (32 or 64) of the OS or the Hardware, take a look at

Anonymous said...

I checked the reg keys on an x64 CPU with an x64 O/S (Windows 7, x64), key = AMD64. I also checked the reg keys for an x64 CPU with an x86 O/S (XP, 32 bit) = x86

Anonymous said...

Actually it seems to work OK.