On Windows, it’s possible to create new “protocol handlers” so that URLs like
telnet://hostname, etc. are recognized and launch some
application (e.g., PuTTY). The only trickery is that Windows will pass the
entire protocol string to the application (e.g., PuTTY will be launched with
the command line
putty telnet://hostname). For applications that understand
the protocol prefix this is fine, but otherwise we have to employ a bit of
scripting trickery to strip it off. Following this SO answer
led to the possibility of using protocol handlers for
all kinds of sysadmin things (the advantage being that protocol links can be
embedded in wikis, Visio diagrams, hotsheets, inventory systems, etc.). As creating the required
registry keys is a bit of a pain, I wrote
a script for registering new protocol handlers.
Some examples should make its usage clear (run these from a command prompt, in
the folder where you saved
regproto.js ping "ping -t %%HOST%%" regproto.js telnet "putty -telnet %%HOST%%" regproto.js ssh "putty -ssh %%HOST%%" regproto.js cmd "psexec \\%%HOST%% cmd.exe" regproto.js shutdown "shutdown /s /m \\%%HOST%%" regproto.js restart "shutdown /r /m \\%%HOST%%" regproto.js manage "mmc compmgmt.msc /computer=\\%%HOST%%" regproto.js ps "powershell -NoExit -Command Enter-PSSession -ComputerName %%HOST%%" regproto.js rdp "mstsc /v:%%HOST%%"
The above will register
ping://handler which will open a console window with
ping -trunning on the host.
telnet://handlers, linked to PuTTY (assuming it’s in your
cmd://handler that will use
psexecto launch a command interpreter on the remote machine.
shutdown://handler that will shutdown the remote machine.
restart://handler that will restart the remote machine.
manage://handler that will launch the Computer Management snapin connected to the remote machine.
ps://handler that will run Powershell on the remote machine.
rdp://handler that will launch a remote desktop connection to the target machine.
The only required arguments are the protocol name, and the command string to
launch. The command string can refer to
%%HOST%%, the “hostname” (or whatever)
given in the
protocol://hostname. Note that this could include a username and
password, if your application understands those (PuTTY does, so you can do
telnet://username@hostname and it will work).
The full documentation for
regproto is in a big comment at the top of the
file (pay special attention to the note at the bottom about custom protocols
in Firefox and Chrome).
regproto will create a script
script is used to launch applications with the URL given, but with the protocol
stripped off. It’s possible that (e.g.) antivirus might block the creation of
this script, in which case you won’t be able to register any protocols.