Skip to content

Instantly share code, notes, and snippets.

@silverkorn
Last active August 7, 2017 21:16
Show Gist options
  • Save silverkorn/62fead99a98788aecf368b3780ff989a to your computer and use it in GitHub Desktop.
Save silverkorn/62fead99a98788aecf368b3780ff989a to your computer and use it in GitHub Desktop.
A way to make PuTTY load the host with the protocol in the parameter. Supports login name and password.
var sExecutable = 'putty.exe';
var oShell = WScript.CreateObject("WScript.Shell");
var oFSO = WScript.CreateObject("Scripting.FileSystemObject");
var oFile = oFSO.GetFile(WScript.ScriptFullName);
var sExecutableFullPath = '"' + oFSO.GetParentFolderName(oFile) + "\\" + sExecutable + '"';
if(WScript.Arguments.length > 0){
var sArg = WScript.Arguments(0);
var aCmd = [];
var oCmd = {
'executable': sExecutableFullPath,
'protocol': null,
'login': null,
'password': null,
'host': null
};
if(sArg.indexOf('://') !== -1){
oCmd.protocol = '-' + sArg.substr(0, sArg.indexOf('://'));
oCmd.host = sArg.substr(sArg.indexOf('://') + 3);
}else{
oCmd.host = sArg;
}
oCmd.host = oCmd.host.replace(/\//g, '');
if(oCmd.host.indexOf('@') !== -1){
oCmd.login = oCmd.host.substr(0, oCmd.host.indexOf('@'));
oCmd.host = oCmd.host.substr(oCmd.host.indexOf('@') + 1);
if(oCmd.login.indexOf(':') !== -1){
oCmd.password = '-pw "' + oCmd.login.substr(oCmd.login.indexOf(':') + 1) + '"';
oCmd.login = oCmd.login.substr(0, oCmd.login.indexOf(':'));
}
oCmd.login = '-l "' + oCmd.login + '"';
}
for(var i in oCmd){
if(oCmd[i] !== null) aCmd.push(oCmd[i]);
}
oShell.Run(aCmd.join(" "));
}else{
oShell.Run(sExecutableFullPath);
}
@silverkorn
Copy link
Author

silverkorn commented Mar 30, 2017

Initially created to use with Windows registry:
HKEY_CURRENT_USER\Softwares\Classes\ssh\shell\open\command
or
HKEY_CLASSES_ROOT\ssh\shell\open\command
using the command wscript "path\to\putty-schema.js" "%1"
Just drop this script within the same directory as your putty.exe executable.

It has been designed to be flexible, just change the sExecutable property to the one needed and change the switches/options (in this case -l and -pw) to the one supported by the target executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment