Tim
Tim

Reputation: 143

Inno Setup Registry entry for custom URL protocol

I'm hoping someone can help me translate the following into a correctly formatted InnoSetup [Registry] entry to use in my InnoSetup Installer? The goal here is to create a new custom URL protocol on the user's machine.

HKEY_CLASSES_ROOT      
       ctp
          (Default) = "URL:Alert Protocol"
          URL Protocol = ""
          DefaultIcon
               (Default) = "myapp.exe"
          shell
               open
                    command
                         (Default) = "C:\Program Files\MyApp\myapp.exe"

I read through the InnoSetup Help doc but couldn't figure out how to translate the above into a proper InnoSetup Registry section:

[Registry]
Root: HKCR; Subkey: ".....etc.

The final result after the installer runs is that the user clicks on a link on a web site formatted as "ctp://myapp.exe" and that local app will launch on the user's machine. Am I approaching this correctly? Thanks very much for any responses.

Upvotes: 11

Views: 4216

Answers (2)

Higor E.
Higor E.

Reputation: 716

@TLama's answer is correct, but might not work for everybody.

HKCR is actually a merge between HKLM\Software\Classes and HKCU\Software\Classes and writting to HKCR directly may require administrative access on some systems, thus it's not compatible with InnoSetup's PrivilegesRequired=lowest. The official HKCR documentation explains:

If you write keys to a key under HKEY_CLASSES_ROOT, the system stores the information under HKEY_LOCAL_MACHINE\Software\Classes. If you write values to a key under HKEY_CLASSES_ROOT, and the key already exists under HKEY_CURRENT_USER\Software\Classes, the system will store the information there instead of under HKEY_LOCAL_MACHINE\Software\Classes.

The alternative is HKA (see [Registry] section) which resolves to HKLM in administrative installs and HKCU in non-administrative ones. The documentation also states that:

HKCU and HKA should only be used for settings which are compatible with roaming profiles.

Using HKCR is not recommended, use HKA with the Subkey parameter set to "Software\Classes" instead.

So, if you care about non-administrative installs, your [Registry] section should look like this:

[Registry]
Root: HKA; Subkey: "Software\Classes\ctp"; ValueType: "string"; ValueData: "URL:Custom Protocol"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\ctp"; ValueType: "string"; ValueName: "URL Protocol"; ValueData: ""
Root: HKA; Subkey: "Software\Classes\ctp\DefaultIcon"; ValueType: "string"; ValueData: "{app}\myapp.exe,0"
Root: HKA; Subkey: "Software\Classes\ctp\shell\open\command"; ValueType: "string"; ValueData: """{app}\myapp.exe"" ""%1"""

For more info see the links above, and also the following ones:

Upvotes: 2

TLama
TLama

Reputation: 76693

Try it this way:

[Registry]
Root: HKCR; Subkey: "ctp"; ValueType: "string"; ValueData: "URL:Custom Protocol"; Flags: uninsdeletekey
Root: HKCR; Subkey: "ctp"; ValueType: "string"; ValueName: "URL Protocol"; ValueData: ""
Root: HKCR; Subkey: "ctp\DefaultIcon"; ValueType: "string"; ValueData: "{app}\YourApp.exe,0"
Root: HKCR; Subkey: "ctp\shell\open\command"; ValueType: "string"; ValueData: """{app}\YourApp.exe"" ""%1"""

Upvotes: 21

Related Questions