Passing parameters to a custom URI Passing parameters to a custom URI windows windows

Passing parameters to a custom URI


Not that I want to reopen such an old question but I was looking for a better answer to this all morning with no luck. The OP was lucky in that he had a batch file that was modifiable. However, I wanted to add a URI to an existing program (putty) without having to install additional files.

There were two problems as I see them, the first was the full URI including the protocol being passed as one parameter. The second is not being able to pass multiple parameters.

For the first solution of the protocol prefix, it can be solved by doing a little string manipulation. Such that the command value in the registry looks like:

cmd /V:ON /C "SET r=%1 & start D:\demo.bat !r:Demo:=!"
  • /V:ON allows for the !r! replace to be delayed in execution.
  • /C opens a command window, executes the specified command and closes the command window.
  • SET r=%1 saves the URI, which by the time the SET is run has alreadybeen replaced by the actually URI string
  • start starts your program or batch file in this case

The second solution now that we can manipulate strings would be to do another replace, which although I am sure there is a better way you could just chain the replaces together like so:

cmd /V:ON /C "SET r=%1 & SET s=!r:Demo:=! & start D:\demo.bat !s:_= !"

This last addition replaces underscores(_) with spaces ( ), and by making them spaces makes them become separate arguments used to call demo.bat.Therefore, to run:

D:\demo.bat -ping -ip 172.18.102.65

Your URI would be:

Demo:-ping_-ip_172.18.102.65

Note:I would recommend using a lowercase protocol but going with the OP's example for consistency


When using a custom URL, the entire URL is passed to the registered app/script as a single parameter. Your app/script needs to parse the URL to extract what it needs. For example:

[HKEY_CLASSES_ROOT\Demo\shell\open\command]@="\"D:\\demo.bat\" \"%1\""

You can format the URL any way you want, as long as it is a valid URL and begins with demo:, eg:

D:\demo.bat "demo:ping?ip=172.18.102.65"D:\demo.bat "demo:ping=172.18.102.65"D:\demo.bat "demo:ping%20172.18.102.65"

Update: Note, however, that this only works with Internet Explorer (and Windows Explorer, and tbe Windows Shell). You need another solution for other browsers. For instance, Firefox has its own Protocol Handler mechanisms:

Web-based protocol handlers

Adding a New Protocol to Mozilla

Writing a Firefox Protocol Handler