Scripting: Reliably Finding my 32bit EXEs on a 32bit & 64bit OS or Where is IronPython?

Having enough of not being able to use that last 1GB of the 4GB physically available on my machines, I used the recent release of the Windows 7 Release Candidate to move into the world of 64 bit computing. As a typical end-user the transition has been seamless. All the applications I use on a day-to-day basis “just work”. As someone who writes code and scripts, I’m still finding some friction. Nothing too difficult to overcome, but it is part of the learning that comes with any platform change.

This week’s adventure started off with IronPython. I have a script called start_ipy.cmd. All it does is launch the IronPython shell (IPY.EXE) with some options to turn on color in the shell and enable tab completion.

The script looks like this:

“%PROGRAMFILES%\IronPython 2.0.1\IPY.EXE” -D -X:TabCompletion -X:ColorfulConsole

Which of course works great on my 32 bit Windows machines And which fails to find IPY.EXE on my 64bit machines. That is to be expected, IronPython is installed under “Program Files (x86)” which is the location found in the PROGRAMFILES(x86) environment variable. So fixed my script to read something like this

“%PROGRAMFILES(x86)%\IronPython 2.0.1\IPY.EXE” -D -X:TabCompletion -X:ColorfulConsole

And it worked great on my 64 bit machines. But it failed on my 32-bit machines. Why? Because the PROGRAMFILES(x86) is only defined by default on 64bit OSes.  So the result of this is the script could find the IPY.EXE on either 32bit or 64 bit OSes both not both.


Also curiously, there is no environment variable called PROGRAMFILES(x64) that points to the specific location of 64 bit applications.

So let’s look at the situation in a table…


Environment variable Exists on 32 bit Windows Exists on 64 bit Windows
PROGRAMFILES YES – points to 32 bit apps YES – points to 64 bit apps
PROGRAMFILES(x86) NO – but I want it to exist YES – points to 32 bit apps
PROGRAMFILES(x64) NO – and it does not make sense to exist. NO – but I want it to exist


What wanted was simple: 2 things

  • PROGRAMFILES(x86) to point to the location of 32 bit apps on both 64bit and 32bit Operating Systems. This would solve my initial problem
  • PROGRAMFILES(x64) to point to the location of 64 bit apps on 64bit OSes. This is just for completeness – it doesn’t have any relation to my original problem

Fortunately it’s not hard to compensate for this, a few extra commands in the script gives everything I need

IF DEFINED ProgramFiles(x86) SET ProgramFiles(x64)=%ProgramFiles%
IF NOT DEFINED ProgramFiles(x86) SET ProgramFiles(x86)=%ProgramFiles%
“%PROGRAMFILES(x86)%\IronPython 2.0.1\IPY.EXE” -D -X:TabCompletion -X:ColorfulConsole

Now I have a reliable (for my purposes) way of finding 32 bit apps on a Windows machine that “does the right thing” on either 32bit or 64bit operating systems and, more specifically, I am now have coloring and tab completion for IronPython on all my machines.



  • The script doesn’t check whether the locations actually exist, but rather what the paths “should” be
  • I’m far for a Windows shell scripting expert, if you have alternative techniques, please share

Comments (0)

Skip to main content