I have set a custom uri handler "caesar://" and i use it as a shortcut to open heidisql, winscp, putty and setup quick tunnels from a web page (a control panel). However, the same error can be produced (at least on my computer) just by accessing a .bat file
@echo off
mode con: cols=100 lines=10
setlocal enableextensions disabledelayedexpansion
echo "CAESAR URI handler has started..."
:: winscp - caesar://sftp:88.88.88.88:22:root:null:null:null:null/yourpassword/null/null/#etc#lighttpd#/
:: parse the uri parameters
for /f "tokens=1 delims=:" %%C in ("%line%") do set "type=%%C"
for /f "tokens=2 delims=:" %%C in ("%line%") do set "sship=%%C"
for /f "tokens=3 delims=:" %%C in ("%line%") do set "sshport=%%C"
for /f "tokens=4 delims=:" %%C in ("%line%") do set "sshuser=%%C"
for /f "tokens=2 delims=/" %%C in ("%line%") do set "sshpass=%%C"
for /f "tokens=3 delims=/" %%C in ("%line%") do set "sqluser=%%C"
for /f "tokens=4 delims=/" %%C in ("%line%") do set "sqlpass=%%C"
for /f "tokens=5 delims=/" %%C in ("%line%") do set "sftpdir=%%C"
for /f "tokens=5 delims=:" %%C in ("%line%") do set "remoteip=%%C"
for /f "tokens=6 delims=:" %%C in ("%line%") do set "remoteport=%%C"
for /f "tokens=7 delims=:" %%C in ("%line%") do set "localport=%%C"
:: sftp directory
set sftpdir=%sftpdir:#=/%
if "%sftpdir%"=="" set sftpdir="/%sshuser%"
if "%sftpdir%"=="null" set sftpdir="/%sshuser%"
:: let's just user's home directory (winscp does not reload it's sites database if the application is active and registry changes)
set sftpdir="/%sshuser%"
:: create a popup message file
@echo Set objArgs = WScript.Arguments > %AppData%\\caesarurimsg.vbs
@echo messageText = objArgs(0) >> %AppData%\\caesarurimsg.vbs
@echo MsgBox messageText,0,"Caesar URI Notification" >> %AppData%\\caesarurimsg.vbs
:: check if winscp is installed
if exist "C:\Progra~1\WinSCP\WinSCP.exe" set apploc_winscp=C:\Progra~1\WinSCP\WinSCP.exe
if exist "C:\Progra~2\WinSCP\WinSCP.exe" set apploc_winscp=C:\Progra~2\WinSCP\WinSCP.exe
if "%apploc_winscp%"=="" (
cmd /c cscript %AppData%\\caesarurimsg.vbs "Could not find WinSCP.exe in the default location. If it it not installed, - install it, if it is - check the script location inside %SystemRoot%\caesaruri.bat."
exit
)
:: add registry values for winscp (if they do not already exist)
:: reference here: https://winscp.net/eng/docs/custom_distribution#distributing_passwords
if "%type%"=="sftp" set create_sftp_reg=1
set "winscpkey=HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Sessions\%sessionname%"
if defined create_sftp_reg (
echo "Preparing WinSCP..."
REG QUERY "%winscpkey%">nul && (
echo "- Session has already been created before..."
) || (
echo "- Creating a new session..."
REG ADD "%winscpkey%" /f /v "HostName" /t REG_SZ /d "%sship%" > NUL
REG ADD "%winscpkey%" /f /v "Username" /t REG_SZ /d "%sshuser%" > NUL
REG ADD "%winscpkey%" /f /v "PortNumber" /t REG_DWORD /d "%sshport%" > NUL
REG ADD "%winscpkey%" /f /v "PasswordPlain" /t REG_SZ /d "%sshpass%" > NUL
)
)
:: open a winscp connection (to solve a "Host not found" (tested up to v5.8) bug when creating new sessions - when a new session is created and error occurs, go to "Session>Sites>Site Manager" (a new dialog will open), close the dialog - problem will not occur for the same session next time)
if "%type%"=="sftp" (
echo "- Opening WinSCP..."
if not "%sftpdir%"=="" (
REG ADD "%winscpkey%" /f /v "RemoteDirectory" /t REG_SZ /d "%sftpdir%" > NUL
)
%apploc_winscp% "%sessionname%"
)
:: just in case
exit
The script above can be called using the code below via cmd.exe
hstart.exe /UAC "caesaruri.bat %1"
However, I use the custom uri handler to call it, it can be set up with .reg (contents below)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CAESAR]
@="url:caesar protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\CAESAR\shell]
[HKEY_CLASSES_ROOT\CAESAR\shell\open]
[HKEY_CLASSES_ROOT\CAESAR\shell\open\command]
@="hstart.exe /UAC \"caesaruri.bat %1\""
NOTE: I minimized the .bat script to only show winscp, I did a fast review, but there might be some bugs/missing code, but I think that the most important parts can be understood without even executing the code.