views:

63

answers:

2

What is the "correct" way for a 32-bit application to find the "Program Files" folder on 64-bit Windows? For example, I am running a 32-bit application with a VBScript engine, and want to launch 64-bit Excel (using ShellExec, or similar). In the 32-bit world, I would check the environment variable "ProgramFiles" to get the base folder. My understanding is that as a 32-bit app on a 64-bit Windows, that environment variable will point to the 32-bit program files folder - eg: C:\Program Files(x86). But my 64-bit Excel will be under C:\Program Files.

I want to avoid hard-coding a reference to "c:\program files".

+2  A: 

You can check the environment variable "ProgramW6432". It should exist and point to Program Files, without the x86, when running a 32bit application on a 64bit Windows.

Documentation: MSDN

Mic
Perfect! That's exactly what I needed. Thanks!
Ed Schembor
If running a 64-bit app, will ProgramW6432 be blank?
Ed Schembor
It's quite simply missing when running a 64bit application.
Mic
+3  A: 

Depending on the version of windows, you should be using the known folders apis.

http://msdn.microsoft.com/en-us/library/bb776911%28v=VS.85%29.aspx

Specifically you can use FOLDERID_ProgramFilesX64 in conjunction with SHGetKnownFolderPath.

Logan Capaldo