0

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.

Butters
  • 947
  • 5
  • 16
  • 25

4 Answers4

2

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");
 }
Community
  • 1
  • 1
David
  • 15,894
  • 22
  • 55
  • 66
  • I want to add that to registry. so this would not be much helpful. – Butters Apr 02 '13 at 15:17
  • Basically I want to know what can be used instead of C:\Program Files (x86)\ in registry – Butters Apr 02 '13 at 15:17
  • @Butters - This would generate a path which you could generate a string which then you could place in the registry. Although checking the architecture of the operating system isn't required `Environment.GetEnvironmentVariable("ProgramFiles(x86)");` will always return the correct system path. – Security Hound Apr 02 '13 at 15:28
  • But I'm just running a MyRegistryFile.reg to add all the key value pairs instead of creating those key values one by one on my program code. Is there another way, or should I go back to creating those registry key values on the code, so that I can use Environment.GetEnvironmentVariable("ProgramFiles(x86)") – Butters Apr 02 '13 at 15:35
  • @Butters, you tend to mix 2 issues together. My answer is to answer your first concern, and then you get another. You'd better get a new post to raise your 2nd question. This will help you get answered quickly. – David Apr 02 '13 at 15:58
2

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"
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • I tried this and got this error. Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access this item. – Butters Apr 02 '13 at 15:21
  • @Butters, do you mean the installer did not replace that property with its value when generating the registry key? – Frédéric Hamidi Apr 02 '13 at 15:23
  • There are a lot of key/values to be created. So, I'm basically running a MyRegistryFile.reg inorder to create all of those key/values on registry. and Yes, "[ProgramFilesFolder]MyApp\MyApp.exe" "%1" is exactly as it is on the registry – Butters Apr 02 '13 at 15:28
  • @Butters, I misunderstood, I thought you were letting the installer generate the registry key. See my updated answer. – Frédéric Hamidi Apr 02 '13 at 15:43
0

[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"
alex
  • 12,464
  • 3
  • 46
  • 67
  • Okay, I tried "[INSTALLDIR]MyApp.exe" "%1" and also "[INSTALLDIR]" "%1" but both times it says application not found – Butters Apr 02 '13 at 15:15
0
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
Todd
  • 620
  • 4
  • 13