Creating a Custom URL Protocol for SSH
It can sometimes be very useful to have links in your web browser spawn third-party applications for you. A user recently submitted a question wanting to have a URL open an SSH connection with PuTTY. As he learned, this can be done by creating a custom URL protocol.
I am trying to set up Firefox to launch a putty session upon the entry of ssh://nodename in the address bar and I am having some issues. I have successfully added the necessary keys to the registry such that putty is launched, however, putty doesn’t accept the input correctly and tries to connect to a non-existent host.
I was thinking about writing a bat file which would accept the input from Firefox […] but I am unsure how to do so since I am not a scripter or a windows guru. Any help you could provide would be greatly appreciated. Thanks!
Well, Kyle, you are so very close to your solution. The problem here is that the browser is passing the complete URL to the PuTTY application. Since PuTTY does not accept full URLs as host names, you receive a non-existent host name error.
As you suggested, the easiest way to solve this problem is to use a script to parse the URL into a valid host name and, in turn, launch the PuTTY application. You suggested a batch file, but you’ll see why this is much easier in WSH. But first, let’s show our readers how to create the custom protocol necessary to make this all work.
Adding custom protocols is extremely easy but it does require editing the Windows Registry. If you are uncomfortable editing the registry, I’ve written an installer that will do this for you. You can find the link at the end of this article.
You’re going to be creating several registry keys and values to create the key structure necessary for this to work. To begin, you’ll need to click the start button and choose Run… to open the Run Dialog box. Enter regedit and choose OK to open the Registry Editor.
Please use the trackback link when linking to this post.


(8 votes, average: 4 out of 5)






























August 10th, 2007 at 11:36 am
Robert,
Thanks so much for your help. The insight you gave into the nature of the issue along with the suggestions and ultimately a packaged software solution was exactly what I was looking for. Keep up the great work!
Kyle
August 10th, 2007 at 12:55 pm
Thank you so much, Kyle. It was a pleasure. I’m glad I could help!
February 25th, 2008 at 2:09 am
Hi,
I made a small mod to your ssh.vbs script to enable it to accept custom ports. Did it quick and dirty could be done a bit better but works.
Tim
‘ Region Description
‘
‘ Name: ssh.vbs
‘ Author: Robert Dunham (Nilpo)
‘ Website: http://www.nilpo.com
‘ Description: This script is for use with a custom SSH protocol for Putty.
‘
‘ EndRegion
strSSH = “C:\ssh\putty.exe”
strPort = “22″
Select Case WScript.Arguments.Count
Case 0
WScript.Echo “No hostname provided. Aborting SSH operation.”
WScript.Quit
Case Else
Set colArgs = WScript.Arguments
For i = 0 To WScript.Arguments.Count - 1
strHost = ” ” & WScript.Arguments.Item(i)
Next
End Select
Set WshShell = CreateObject(”WScript.Shell”)
strHost = CleanHostname(strHost)
WshShell.Run “”"” & strSSH & “”" -P ” & strPort & ” “”" & strHost & “”"”
WScript.Quit
Function CleanHostname(strHost)
strHost = Trim(strHost)
‘Remove protocol if it was passed
If InStr(strHost, “ssh://”) = 1 Then
strHost = Right(strHost, Len(strHost) - 6)
End If
‘Remove trailing slash if present
If InStrRev(strHost, “/”) = Len(strHost) Then
strHost = Left(strHost, Len(strHost) - 1)
End If
If InStrRev(strHost, “:”) > 0 Then
strPort = right(strHost, Len(strHost) - InStrRev(strHost, “:”))
strHost = Left(strHost, InStrRev(strHost, “:”) - 1)
End If
‘Return cleaned hostname
CleanHostname = strHost
End Function
February 25th, 2008 at 8:21 pm
Looks good, Tim. Thanks for the addition!
October 28th, 2008 at 2:24 am
Thank you for your article. It’s very good. I search very long time how to create my own protocol. I customise your script for my usage.
LePiaf