windowsipcurl-schemexojo

Windows URL scheme call to running program


I want to trigger an event in my running application and deliver arguments with the call of a URL scheme in Windows 10. I made the following registry entry:

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

Obviously, this always starts a new instance of my application with an argument, when calling 'alert:arg1'. But I want Windows to call my already running instance.

With Mac, the call of this URL scheme triggers an event, I can catch. Exactly, as I want. To do this, I added the following part to alert.app/Contents/Info.plist:

<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>Alert</string>
    <key>CFBundleURLSchemes</key>
    <array>
            <string>alert</string>
    </array>
  </dict>
</array>

So how do I realise this on Windows? I'm programming this application in XOJO with object-oriented BASIC, but I'll be happy about a general solution.


Solution

  • Well, after reading the answer of Alex, I searched how to realise this with code and found a well explained and working solution from Brad Smith written in C#.

    The registry entry above can stay as it is, but the program also needs:

    • A service class (which is exposed by the application instance
      via .NET remoting)
    • A modified entry point (which will either communicate with the service and then terminate, or start the application normally)

    Read his article and look at his code for further explanation.