I've seen a number of people asking how to add their own URL handler
so that when they type a URL such as the examples below, it would
launch their own app such as terminal services.
ts:<terminal server client>
According to the docs at the microsoft website, it is relatively easy
to add an app to respond to the URL type. However, when you pass it
the hostname, %1, it passes the URL handler as well, eg: ts:<terminal
server client>. Not many executables know what to do with the URL
part. The only way I've been able to get around this is to parse off
the ts: part. This then allows the hostname to be passed to the app
for operation on. Below are the tools I've developed to do this:
(1) the batch file to parse off the URL
(2) the registry entries required for the ts protocol.
--------------------------------------------------------------
1) The batch file C:\Program Files\urlhandler\urlhandler.bat
This requires the ssed.exe program available from
http://sed.sourceforge.net/grabbag/ssed/sed-3.59.zip
==============================================================
@echo off
rem - What this does
---------------------------------------------------
rem If less than 3 arguments display usage
if not "%3" == "" goto start
:usage
echo.
echo USAGE: urlhandler.bat [url_prot] [command] [arg1] [arg2] [argx..]
echo.
echo This batch file will assemble a commandline [command] [args1]
[argx]
echo and strip the string [url_prot] from that commandline
echo Then the commandline will be executed. Minimum of 4 arguments.
echo.
echo This is a workaround since IE passed the URL protocol to its
commandline!
echo.
goto end
:start
rem - Edittable variabled
---------------------------------------------
rem bdir: directory helper binaries urlhandler.bat and ssed.exe files
set bdir=c:\progra~1\urlhandler
rem batfile: name of batchfile to run
set batfile=urlcmd.bat
rem - Commandline Arguments
-------------------------------------------
rem %1: string to strip off the URL
rem eg: ts:
set urlprot=%1
rem %2: Command to run
rem eg: C:\winnt\system32\mstsc
set cmd=%2
rem %3 and more: parameters/arguments.
rem eg: -v:<host>
set args=%3 %4 %5 %6 %7 %8 %9
rem - Part that processes the commands
-----------------------------------
rem Piece together the commandline
set cline=%cmd% %args%
rem UNREM next three lines to see what the command would look like
rem echo Running %cline% removing %urlprot% and deleteding "/" off any
words
rem ending in "/"
rem pause
echo start /B %cline% | %bdir%\ssed.exe s/%urlprot%/""/g |
%bdir%\ssed.exe s/\/" "/" "/g > %bdir%\%batfile%
call %bdir%\%batfile%
cls
exit
:end
----------------------------------
(2) The URL protocol definition
==================================
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\ts]
"URL Protocol"=""
@="URL:TS Protocol"
[HKEY_CLASSES_ROOT\omni\DefaultIcon]
@="\"C:\\WINNT\\SYSTEM32\\mstsc.exe\" ,7"
[HKEY_CLASSES_ROOT\ts\shell]
[HKEY_CLASSES_ROOT\ts\shell\open]
[HKEY_CLASSES_ROOT\ts\shell\open\command]
@="c:\\Progra~1\\urlhandler\\urlhandler.bat ts:
C:\\WINNT\\SYSTEM32\\mstsc.exe /v:%1"
DISCLAIMER: This tool is provided as Political-A-Ware. If you find it
useful it might give you more time to do the things that make a
difference. Like protest your government against war or suggest that
your CEO to share their wealth. There are many creative ways you can
make a difference.
Yall have a great Easter,