views:

21231

answers:

3

I'm using:

FileInfo(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + @"\MyInstalledApp"

In order to determine if a program is detected on a users machine (it's not ideal, but the program I'm looking for is a right old kludge of a MS-Dos application, and I couldn't think of another method).

On XP and 32-Bit versions of Vista this works fine. However, on x64 Vista the code returns the x64 Program Files folder, whereas the application is installed in Program Files x86. Is there a way to programatically return the path the path to Program Files x86 without hard wiring "C:\Program Files (x86)"?

+5  A: 

One way would be to look for the "ProgramFiles(x86)" environment variable:

String x86folder = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
tomasr
+6  A: 

Note, however, that the ProgramFiles(x86) env variable is only available if your app is running 64-bit.

If your app is running 32-bit, you can just use the ProgramFiles env variable whose value will actually be "Program Files (x86)".

chadmyers
True enough. However, it is obvious that his application *is* running as 32-bit, otherwise GetFolderPath() would already be returning the right x86 folder anyway.
tomasr
Very helpful! this just saved me hours of work! and saved people from having to use my code. It's great when things work out of the box!
David Silva Smith
+47  A: 
JaredPar
Great - thanks very much!
Leonard H Martin
Can anyone comment as to whether this works in a localized environment? Thanks in advance...
Tom