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 http://www.autoitscript.com/site/autoit/
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.