I'm trying to autoload Putty Pageant with some SSH-keys with a batch script, but because I want to bypass the error message of Pageant that it is already running, I placed it in an IF-statement. For some reason however, it doesn't work:
tasklist /FI "IMAGENAME eq pageant.exe" 2>NUL | find /I /N "pageant.exe">NUL
if %ERRORLEVEL%==1 ( :: checks whether pageant.exe is running or not
:: set the SSH-keys
if exist "C:\SSH keys\key1.ppk" (set KEYS="C:\SSH keys\key1.ppk")
if exist "C:\SSH keys\key2.ppk" (set KEYS=%KEYS% "C:\SSH keys\key2.ppk")
if not defined KEYS (
msg * A SSH-key is propably missing.
)
:: Start pageant with the defined SSH-keys
start /d"C:\Program Files (x86)\PuTTY" pageant.exe %KEYS%
)
While they do work separately: (1)
tasklist /FI "IMAGENAME eq pageant.exe" 2>NUL | find /I /N "pageant.exe">NUL
if %ERRORLEVEL%==1 ( :: checks whether pageant.exe is running or not
:: This works!
start /d"C:\Program Files (x86)\PuTTY" pageant.exe
)
(2)
:: set the SSH-keys
if exist "C:\SSH keys\key1.ppk" (set KEYS="C:\SSH keys\key1.ppk")
if exist "C:\SSH keys\key2.ppk" (set KEYS=%KEYS% "C:\SSH keys\key2.ppk")
if not defined KEYS (
msg * A SSH-key is propably missing.
)
This works as well!
start /d"C:\Program Files (x86)\PuTTY" pageant.exe %KEYS%
Is it a syntax problem?