Creating a Single .EXE when you need a separate .EXE to run on x86 and x64 Platforms

Sometimes you may have separate .EXEs to run whether on x86 (32-bit) or x64 (64-bit) platforms. Reasons for this are often around the need to access the native 64-bit registry location i.e. HKLM\SOFTWARE without getting redirected to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node…But sometimes having 2 separate .EXEs can be inconvenient…and to follow in the footsteps of my 2 favourite tools ProcExp and ProcMon which combine the 32-bit & 64-bit EXEs together, then extract and run the appropriate version, though I would come up with a very simple framework to do this. To make this as simple as possible I’ve decided to use AutoIT for this task, freely available from

The first thing I needed was a simple way to check if we are running under 64-bit OS. A simple way for a 32-bit process to know this is the PROCESSOR_ARCHITEW6432 environment variable, which is only ever set for 32-bit processes on 64-bit Windows. We can see this by launching the 32-bit version of cmd.exe (c:\windows\syswow64\cmd.exe)



The process is simple

– We create an AutoIT script in SciTE, the script editor for AutoIT

– Check if PROCESSOR_ARCHITEW6432 environment variable is blank…

– If it is extract x86 version and run it, after it’s run, delete it. If we’re on 64-bit system extract and run the x64 version, then delete it.

To extract the .EXE we use the AutoIT function FileInstall. The first parameter is to the file on the system where you compile the AutoIT script, this file will automatically can bundled into the EXE when you compile it. The 2nd parameter is where you want to copy the file to. Replace the .EXE filenames with your own.

; Check if we’re on 64-bit OS…
If EnvGet(“PROCESSOR_ARCHITEW6432″)=”” Then
    ; No we’re not – run x86 version…
    FileInstall(“D:\Support\ETrustCheck_x86.exe”,@TempDir & “\ETrustCheck_x86.exe”)
    RunWait(“D:\Support\ETrustCheck_x86.exe”,@TempDir & “\ETrustCheck_x86.exe”)
    FileDelete(@TempDir & “\ETrustCheck_x86.exe”)
    ; Yes we are – run x64 version..
    FileInstall(“D:\Support\ETrustCheck_x64.exe”,@TempDir & “\ETrustCheck_x64.exe”)
    RunWait(“D:\Support\ETrustCheck_x86.exe”,@TempDir & “\ETrustCheck_x64.exe”)
    FileDelete(@TempDir & “\ETrustCheck_x64.exe”)

; The END



Now when we go to compile it hit Ctrl+F7 or Tool > Compile to Compile.

-Ensure it is x86 version

-If it is a command line program you’re running, ensure you select CUI

-If your program has icon, make sure you specify the icon for it here



You now have a single EXE that will run on both platforms.

About chentiangemalc

specializes in end-user computing technologies. disclaimer 1) use at your own risk. test any solution in your environment. if you do not understand the impact/consequences of what you're doing please stop, and ask advice from somebody who does. 2) views are my own at the time of posting and do not necessarily represent my current view or the view of my employer and family members/relatives. 3) over the years Microsoft/Citrix/VMWare have given me a few free shirts, pens, paper notebooks/etc. despite these gifts i will try to remain unbiased.
This entry was posted in 64-bit, AutoIT, Scripting and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s