Active1 year, 3 months ago
Fix for: Windows cannot find setup.exe Make sure you typed the name correctly and then try again - Duration: 2:15. Elioth Santillan 86,797 views.
I'm using:
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 Windows XP and 32-bit versions of Windows Vista this works fine. However, on x64 Windows 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 to Program Files x86 without hard wiring 'C:Program Files (x86)'?
Mathieu Renda5,68611 gold badge1818 silver badges2828 bronze badges
Leonard H. MartinLeonard H. Martin1,38933 gold badges1616 silver badges2323 bronze badges
7 Answers
The function below will return the x86
Program Files
directory in all of these three Windows configurations:- 32 bit Windows
- 32 bit program running on 64 bit Windows
- 64 bit program running on 64 bit windows
3,36066 gold badges2323 silver badges4545 bronze badges
JaredParJaredPar605k127127 gold badges11101110 silver badges13691369 bronze badges
If you're using .NET 4, there is a special folder enumeration ProgramFilesX86:
Lee Grissom7,02355 gold badges2929 silver badges4444 bronze badges
NathanNathan1,44311 gold badge99 silver badges44 bronze badges
Carl HörbergCarl Hörberg4,62033 gold badges3535 silver badges4545 bronze badges
Note, however, that the
ProgramFiles(x86)
environment variable is only available if your application is running 64-bit.If your application is running 32-bit, you can just use the
Peter MortensenProgramFiles
environment variable whose value will actually be 'Program Files (x86)'.14.5k1919 gold badges8989 silver badges118118 bronze badges
chadmyerschadmyers
One way would be to look for the 'ProgramFiles(x86)' environment variable:
tomasrtomasr13k33 gold badges3232 silver badges2727 bronze badges
I am writing an application which can run on both x86 and x64 platform for Windows 7 and querying the below variable just pulls the right program files folder path on any platform.
Peter Mortensen14.5k1919 gold badges8989 silver badges118118 bronze badges
SamirSamir
Where Can I Find C Program Files
One-liner using the new method in .NET. Will always return x86 Program Files folder.
Environment.Is64BitOperatingSystem ? Environment.GetEnvironmentVariable('ProgramFiles(x86)') : Environment.GetEnvironmentVariable('ProgramFiles'))
Red JohnRed John