Running PLINK.EXE & Kill on App Closing

Hello there,

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:

  1. make a PLINK.EXE copy and rename it to have a (nearly) unique filename (PLINK.EXE => "[MyAppName]_plink.exe.
  2. Create a Shell with with sh.ExecuteMode = Shell.ExecuteModes.Synchronous mode
  3. Execute Command sh.Execute(" [MyAppName]_plink.exe ...") with proper connection arguments (host, user, pass, port, forwarding, etc.)
  4. 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. :slight_smile: