Search code examples
c#x86registryexeprogram-files

Path of %ProgramFiles(x86)% in 64 bit machine (for Registry)


Question: What is the equivalent of [INSTALLDIR] for %ProgramFiles(x86)% to use in Registry in 64 bit machine ?

I have a program that will be installed inside %ProgramFiles(x86)% in 64 bit machine.

Basically, I want to add these values in registry

Value name:

(Default)

Value data:

"C:\Program Files (x86)\MyApp\MyApp.exe"  "%1"

The above Value data works just fine but I cannot use the exact path because the Windows might be installed in a different directory other than C:\

I tried

Value data:

"[INSTALLDIR]MyApp.exe" "%1"

but it gives application not found error.

What can I use to get the path of %ProgramFiles(x86)% in registry? Any help will be really appreciated.


Solution

  • If your installer is marked x64, you can use the ProgramFilesFolder installer property:

    "[ProgramFilesFolder]MyApp\MyApp.exe" "%1"
    

    In x64 mode, this property will point to the x86 Program Files folder, and ProgramFiles64Folder will point to the x64 Program Files folder.

    EDIT: If you import a reg file into the registry instead of having the installer generate the keys and values, you can use an environment variable instead:

    "%ProgramFiles(x86)%\MyApp\MyApp.exe" "%1"