windowsurlbatch-filecmd

Launch .bat files from a custom URL handler without showing the console window


I registered a custom URL handler in Windows, in order to be able to launch a local program from an URL. Following the MSDN documentation, I inserted the following values in the Registry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\TestLaunch]
@="URL:TestLaunch Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\TestLaunch\DefaultIcon]
@="\"c:\\temp\\test.bat\""

[HKEY_CLASSES_ROOT\TestLaunch\shell]

[HKEY_CLASSES_ROOT\TestLaunch\shell\open]

[HKEY_CLASSES_ROOT\TestLaunch\shell\open\command]
@="\"c:\\temp\\test.bat\" %1"

This works, but when I click a TestLaunch: link and the batch file starts I can see the console windows appearing. Since the role of the batch file is just parsing the argument url and launching another application, I would like the console non to appear (or at least being minimized), even if it is just for a fraction of a second.

The only thing that came to my mind is creating a link to the batch file (test.bat.lnk) and set it to start as minimized, but that won't work. Any other ideas ? I'm open to an alternative to batch files, but I'd like to stick to what Windows provides


Solution

  • You could use VBS?

    @="\"WSCRIPT c:\\temp\\test.vbs\" %1"
    

    Using

    if wscript.arguments.length > 0 then
         wscript.createobject( "WScript.Shell" ).run("app.exe " & wscript.arguments(0))
    end if