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.
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");
}
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"
[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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.