'******************************************************************** '* '* Name: CSI_GetBitness.vbs '* Author: Darwin Sanoy '* Updates: http://csi-windows.com/community '* Bug Reports & ' Enhancement Req: http://csi-windows.com/contactus '* '* Built/Tested On: Windows 7 '* Requires: OS: Any '* '* Main Function: '* Standard Functions to Retrieve HW Bits, OS Bits and process Bits '* All of these values may be different from each other. '* The method used here for hardware and softare bits are not affected '* by running in a 32-bit subsystem under 64-bit Windows. '* A different method is used to detect 32-bit subsystem on 64-bi Windows. '* '* Syntax: '* OS Bits: Get_Bitness("OS"), Get_Bitness("Windows") '* HW Bits: Get_Bitness("HW"), Get_Bitness("Hardware") '* Process Bits: Get_Bitness("Process"), Get_Bitness("Proc") '* Implementation: '* Each case statement represents the similiest code to do the retrieve '* (one liners whenever possible) Const SCRIPTVERSION = 1.2 '* '* Revision History: '* 12/16/10 - 1.2 '* - added code for detecting 32-bit process running under 64bit windows. '* - consolidated functionality for all tree bitness retrievals into one '* one function that takes a parameter '* - Function parameter is case insensitive and promiscuous (takes '* several likely variants as valid syntax) '* - Many new comment to help in applying the code. '* - Changed name to CSI_GetBitness.vbs '* 12/13/10 - 1.1 - inital version (djs) '* '******************************************************************* wscript.echo "The CSI_GetHWBits function reports that your Hardware is " & CSI_GetBitness("Hardware") & " Bits" wscript.echo "The CSI_GetOSBits function reports that your Windows OS is " & CSI_GetBitness("OS") & " Bits" wscript.echo "The CSI_GetProcBits function reports that your process is running as " & CSI_GetBitness("Process") & " Bits" ' Test this by running the script on 32 bit windows running on 64 bit capable hardware If CSI_GetBitness("HW") = 64 and CSI_GetBitness("Windows") = 32 Then wscript.echo "VMWare workstation can run 64 Bit Guest OSes on your machine even though your Host OS is only 32 Bits!" End If ' Test this by starting cmd.exe from %SystemRoot%\SysWOW64\cmd.exe and running the script If CSI_GetBitness("Windows") > CSI_GetBitness("Proc") Then wscript.echo "Running in a subsystem whose bit-ness is lower than the base Windows OS." End If ' Test this by starting cmd.exe from %SystemRoot%\SysWOW64\cmd.exe and running the script If CSI_GetOSBits = 64 and CSI_GetProcBits = 32 Then wscript.echo "Running in the 32-bit subsystem of 64 bit Windows." End If Function CSI_GetBitness(Target) 'CSI_GetBitness Function - updates at http://csi-windows.com. ' All bitness checks in one function Select Case Ucase(Target) Case "OS", "WINDOWS", "OPERATING SYSTEM" CSI_GetBitness = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").AddressWidth Case "HW", "HARDWARE" CSI_GetBitness = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").DataWidth Case "PROCESS", "PROC" 'One liner to retrieve process architecture string which will reveal if running in 32bit subsystem ProcessArch = CreateObject("WScript.Shell").Environment("Process")("PROCESSOR_ARCHITECTURE") If lcase(ProcessArch) = "x86" Then CSI_GetBitness = 32 Else If instr(1,"AMD64,IA64",ProcessArch,1) > 0 Then CSI_GetBitness = 64 Else CSI_GetBitness = 0 'unknown processor architecture End If End If Case Else CSI_GetBitness = 99999 'unknown Target item (OS, Hardware, Process) End Select End Function