Вопрос

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.

Это было полезно?

Решение

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"

Другие советы

Possibly duplicate here.

 static string ProgramFilesx86()
 {
    if( 8 == IntPtr.Size 
        || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
    {
        return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
    }

    return Environment.GetEnvironmentVariable("ProgramFiles");
 }

[INSTALLDIR] includes the name of your application. So it translates to

C:\Program Files (x86)\MyApp\MyApp\MyApp.exe in your example. Try using

"[INSTALLDIR]MyApp.exe" "%1"
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top