Share via


Scripting: Detecting the host architecture vs the process architecture

I had some trouble lately with scripts running on a 64bit version of Vista, when they were run with a 32 bit parent host process.

After figuring out what was wrong, I wanted to be able to detect if I was running a 32-bit script engine under a 64-bit OS. With a bit of crafty (crufty?) coding, I came up with the following VBScript which I put at the top of my script:

sub EnsureNativeScriptEngine

    On Error resume next

    dim WshShell,WshProcEnv,system_architecture, process_architecture

    Set WshShell = CreateObject("WScript.Shell")

    Set WshProcEnv = WshShell.Environment("Process")

    process_architecture= WshProcEnv("PROCESSOR_ARCHITECTURE")

    if process_architecture = "x86" then

        system_architecture= WshProcEnv("PROCESSOR_ARCHITEW6432")

        if system_architecture = "" then

            system_architecture = "x86"

        end if

    else

        system_architecture = process_architecture

    end if

    if NOT system_architecture = process_architecture then

        WshShell.popup "This script should be run as a "& system_architecture & _

  "process, but is running as a "& process_architecture &" process."

        WScript.quit 1

    end if

end sub

EnsureNativeScriptEngine

Which is fine and dandy, except I’d really have liked to just transparently execute the script with the right version of the script host.

Ah well, at least this tells me what’s going on. J

g

Garrett Serack | Program Manager | Connected Identity and Directory| Microsoft Corporationblog: https://blogs.msdn.com/garretts