Every once in a while you need to execute a binaryfrom a batch file that will always be available 32-bits.
Examples include development tools (that usually are x86 hosts talking or encapsulating managed environments, and x64 debuggers) or office versions for which certain plugins are not available in x64 versions.
That’s why I wrote the below batch file to fill the
ProgramFilesX86 environment variable to point to the 32-bit Program Files directory on any system (x86, x64, or one that does not make a distinction).
Determining processor architecture
The batch file makes use of the flags mentioned in HOWTO: Detect Process Bitness – David Wang – Site Home – MSDN Blogs:
- There are 3 distinct cases and two outcomes
- We default to x86 just in case we run on a system that has none of the flags defined (for instance on legacy systems).
|Environment Variable \ Program Bitness||32bit Native||64bit Native||WOW64|
Source of 32-bit program files
The place of the 32-bit program files directory is determined by the environment variables mentioned in WOW64 Implementation Details (Windows):
|64-bit process||PROCESSOR_ARCHITECTURE=AMD64 or PROCESSOR_ARCHITECTURE=IA64
Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: The ProgramW6432 and CommonProgramW6432 environment variables were added starting with Windows 7 and Windows Server 2008 R2.
Boolean logic and case insensitive compare in batch files
Many things in batch files can be tricky including these two:
- Boolean logic: I formulated the logic using OR, based on tips at Boolean Logic in Batch Files.
- Comparision: for case insensitive compare, I used the /I trick mentioned at Batch files – IF statements.
The batch file
Finally: the batch file: Read the rest of this entry »