Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if wscript/cscript runs on x64 host OS?

I'm running a VBScript that may run under x64 Windows. I need to read a registry key from the 32-bit part of the registry. For that I use path HKLM\Software\Wow6432Node\xyz instead of HKLM\Software\xyz. How can I check if the script is executed under x64?

like image 277
vividos Avatar asked Feb 17 '09 10:02

vividos


People also ask

Is VBScript 64-bit?

By default, on 64-bit Windows operating systems, VBScript files are associated with the 64-bit script hosts. However, Rational ClearQuest COM components are 32 bit.

How do I run a VBScript in 32 bit mode on a 64-bit machine?

Changing the registry key on a 64-bit computer from "System32" to "SysWow64" will indeed lead VBScript to run GUI scripts in 32-bit. You are correct that the default registry key points to System32\WScript.exe which is the 64-bit binary.


1 Answers

Even on 64-bit version of Windows you script can execute in 32-bit mode.

You can use following code to determine real bit mode, you script running on:

option explicit

function Determine64BitMode
    dim Shell, Is64BitOs
    set Shell = CreateObject("WScript.Shell")
    on error resume next
    Shell.RegRead "HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir (x86)"
    Is64BitOs = Err.Number = 0
    on error goto 0
    if Is64BitOs then
        Determine64BitMode = InStr(Shell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir"), "(x86)") = 0
    else
        Determine64BitMode = false
    end if
end function

dim ExecutingIn64BitMode
ExecutingIn64BitMode = Determine64BitMode
if ExecutingIn64BitMode then
    MsgBox "64 bit"
else
    MsgBox "32 bit"
end if
like image 109
Michael Vlasov Avatar answered Sep 27 '22 20:09

Michael Vlasov