I am trying to automate a process where a user can establish an ssh tunnel in WSL then use that tunnel for an RDP connection using MSTSC. The same script might launch multiple instances of MSTSC using tunnels (i.e. in all cases the host would be localhost but using different port numbers). There is no scope for creating the tunnel natively on MS-Windows / there may be scope for running an RDP client in WSL but that would be a last resort.
While I can easily script the ssh part and launching MSTSC.EXE from WSL, my script has no visibility of what happens subsequently with MSTSC. I would like to be able to track (from the script in WSL) if the specific instance of MSTSC is still running, and in certain circumstances terminate it.
While running "MSTSC.EXE" (or other native MS-Windows .exes) from WSL results in a Linux process - this is a ghost. The Linux PID persists after the MS-Windows process has exited. Killing the Linux PID has no effect on a running MS-Windows process.
TASKKILL.EXE will kill the process from WSL - but I need the MS-Windows PID for this.
I don't know if I can use TSDISCON.EXE from the client - this allows me to end a RDP session but 1) I need something that runs from the client side and 2) I have neither the MS-Windows PID nor the session name.
MSTSC does not allow me to specify a session name.
Is there a way I can terminate a specific MSTSC instance started from WSL?