recently I got the problem to make PLINK.EXE run on demand (Button Click event) and termintate on App closing or Excepction thrown to avoid the process still lingering (plink) after the App already terminated.
I came up with the following solution:
- make a PLINK.EXE copy and rename it to have a (nearly) unique filename (
- Create a Shell with with
sh.ExecuteMode = Shell.ExecuteModes.Synchronousmode
- Execute Command
sh.Execute(" [MyAppName]_plink.exe ...")with proper connection arguments (host, user, pass, port, forwarding, etc.)
- On App exit or exception run shell with
sh.Execute("taskkill.exe /F /IM [MyAppName]_plink.exe")
This solution does not make use of any windows platform Win32-API SDK process methods.
Note: shadow-copying plink => [new image name] is suggested for PLINK.EXE usage only. As long as you run on windows tih solution should work for you.