0

I have an EXE that I built that I am trying to have installed in the Program Files (x86) folder on Win7 machines. There is really interesting behavior going on. The program has a gui-we used wx-Python and XRC to handle the interface. we include an XRC folder in the distribution. The program uses getcwd() to locate itself and find the xrc folder. However, and this is really interesting-it all works fine when I place the program in Program Files. When I place the program in the Program Files x86 folder I get a message that indicates to me that it can't find the xrc folder.
Let me be clear this application runs fine on an XP machine in Program Files and on a Vista Machine as well as a Win7 machine in Program Files

Now what else is interesting is if I double click the exe in the Program Files (x86) folder it runs fine but when I try to run it off of the short cut added to the start/program menus it does not run correctly. That is where I get the error message that suggests the program is not finding the xrc folder. I also moved the program to a folder on the desktop, and at the root and in every other location it starts and runs fine. Thus I am confident that my code to point to the xrc folder is fine.

So back to the question. When programs are running from the x86 folder is something happening that causes the path references to get screwy? More importantly is it fixable?

One final note- To be as certain as possible that the problem relates to the path to the xrc folder I deleted the xrc folder from two instances of the application and I get the same error message that I received when the program was installed in the x86 folder.

Just for clarification the only time the program will not run is when I use the shortcut on the start menu and the exe and all of the parts are saved in the Program Files (x86) folder

Plasticsabers answerreally helped me understand the problem and I was able to fix it. This is not a Vista verus XP issue it is a 32 bit OS versus 64 bit issue.

I need to run on 64 bit XP and 32 bit Win7.

PyNEwbie
  • 4,882
  • 4
  • 38
  • 86

1 Answers1

0

According to this note, the Program Files (x86) folder is specifically intended for 32-bit program files, as opposed to the Program Files folder, which is intended for 64-bit programs.

But in order for a 32-bit program to pretend that it's on a 32-bit machine, the name of the working directory has to be returned as 'Program Files,' because that's what it would be on a 32-bit machine. This is what you're seeing when you ask Windows for the working directory with getcwd(). Since your program is trying to use that directory name in a path, and that's not actually the path to the file on the real, 64-bit machine, it breaks.

Looking at the WOW64 docs, I suspect the reason it only breaks when launched from the start menu is, that's an instance of a 64-bit process creating a 32-bit process, which causes the system to change the ProgramFiles environment variable. In the case where you double-click to launch it, it's a 32-bit process from the beginning.

It seems you're not the only one to encounter this; this Windows API seems designed specifically to work around the problem you're describing. If nothing else it suggests the behavior you're seeing is by design.

But this is academic. To insulate yourself from this sort of thing, I would get the absolute path to your exe, using something like os.path.realpath(__file__), and go from there.

plasticsaber
  • 232
  • 1
  • 4
  • Well why does it work for the versions installed in the Program Files directory? Notice, I am talking about the exact same app installed in numerous places and in every case I installed a short cut on the start menu. If you can clarify this I would appreciate it. – PyNEwbie Jul 27 '11 at 21:41
  • It would work installed elsewhere if the links to the other installation have inside them a "start in" folder that allows them to find the folder. – dash-tom-bang Jul 27 '11 at 21:43
  • So- (grr enter handling) the typical way to handle this is to get the path that launched the executable from sys.argv[0], pass that through os.path.abspath(), and be on your way. – dash-tom-bang Jul 27 '11 at 21:44
  • I am still struggling because I did nothing different in any case – PyNEwbie Jul 27 '11 at 21:46
  • @plasticsaber I am working on your suggestion but I am sorry I was not clear, it worked in all cases (from Start menu and from double clicking the exe when installed anywhere bu the (x86) folder. When in the x86 folder it only starts by double clicking the executable – PyNEwbie Jul 27 '11 at 21:56
  • @PyNEwbie Ah, sorry for the misunderstanding. I think I've found the [relevant article](http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm) describing the two Program Files folders. I'm updating my answer. – plasticsaber Jul 27 '11 at 22:04
  • @plasticsaber your interpretation of the article suggests my program should be installed in the Program files folder not the x86 folder. I assumed x86 because well the computer I used to run py2exe is an x86 32 bit machine so this is strange. – PyNEwbie Jul 27 '11 at 22:16
  • @PyNEwbie So the only thing that doesn't work is: launching from shortcut, program located in the x86 folder? – plasticsaber Jul 27 '11 at 22:34
  • I'm sorry but this is not correct. The two program files directories are there for convenience but they are not subject to file system redirection. – David Heffernan Jul 28 '11 at 08:55