Niko Nik wrote:
Which brings me to the next question: how can I close the program after a disconnect as you suggested?
One way to do this is to run the following windows command:
IF EXIST %SystemRoot%\System32\wbem\wmic.exe IF EXIST %SystemRoot%\System32\taskkill.exe IF EXIST %SystemRoot%\System32\findstr.exe %SystemRoot%\System32\wbem\wmic.exe process get name, processid|for /F "tokens=2" %i in ('%SystemRoot%\System32\findstr.exe /B /I "WinSCP"') do @%SystemRoot%\System32\taskkill.exe /F /PID %i
Or if you put it in an batch file, and call the batch file, then in the batch file double the percent signs in the
for command:
IF EXIST %SystemRoot%\System32\wbem\wmic.exe IF EXIST %SystemRoot%\System32\taskkill.exe IF EXIST %SystemRoot%\System32\findstr.exe %SystemRoot%\System32\wbem\wmic.exe process get name, processid|for /F "tokens=2" %%i in ('%SystemRoot%\System32\findstr.exe /B /I "WinSCP"') do @%SystemRoot%\System32\taskkill.exe /F /PID %%i
This will:
- check to make sure wmic, taskkill, and findstr commands are available, and if they are
-- then to use wmic to get the process name and process id of all processes, and
-- then it passes the results from wmic to the FOR command to get the second token which in this case is the process id
--- it bases the FOR results on the findstr command that makes sure FOR only works on the lines that have WinSCP in them (ie. only the process id for WinSCP)
---- it then passes the process id to taskkill and forces it to kill the program (as long as the user has rights to force the kill on the process id).
---- Note: This will close all open instances of WinSCP.
That should work.