How add value on hkey_classes_root key where the application installed

2.5k views Asked by At

Solved!!

I am trying to create a Custom URL Protocol of my application that will launch my application when they visit or clicked link to myapp:start

My problem is how to know where the user installed my application. Can the msi installer put the location when registering HKEY_CLASSES_ROOT to registry?

HKEY_CLASSES_ROOT
   myapp
      (Default) = "URL:myapp Protocol"
      URL Protocol = ""
      DefaultIcon
           (Default) = "myapp.exe,1"
      shell
           open
               command
                   (Default) = "C:\Program Files\MyAppFolder\MyApp.exe" "%1"

I wanted to change the path "C:\Program Files\MyAppFolder\MyApp.exe" to where the user installed my app during installation process.

Solution

HKEY_CLASSES_ROOT
   myapp
      (Default) = "URL:myapp Protocol"
      URL Protocol = ""
      DefaultIcon
           (Default) = "myapp.exe,1"
      shell
           open
               command
                   (Default) = "[TARGETDIR]MyApp.exe "%1""

[TARGETDIR] will automatically change to where the user installed the file e.g. "C:\Program Files\MyAppFolder\"

For more information click this link -> Registering an Application to a URI Scheme

1

There are 1 answers

3
Rudi Visser On BEST ANSWER

With the Visual Studio Setup Project, you can use the [TARGETDIR] variable when creating your registry key.

This variable is automatically set to the target directory that your application is being installed into, simply append your .exe file to the end.