I need to find the PID of a program that I am starting via the shell. The Shell is mode 1 and I am using a thread to control sending the commands and receiving the data back from the shell. The program I need to close is plink. The problem is I already have one instance of plink running that I need to keep open so I can't just do this:
Shell.Execute("taskkill /F /IM plink*") otherwise it would close both instances.
I found that I could rename the plink file itself to something else and close that instead and it works but I really don't want to have to include two versions of the same file with my program. Or rename the file that's probably some kind of no no licensing issue anyway.
This is what I would like to do (this is within a thread):
dim xShell As New Shell xShell.Mode = 1 xShell.Execute(strConnect) //Starts the file instance that I need to close later me.Sleep(10000) //Gives time to connect xShell.Write(strCommand) //Executes a command I need me.Sleep(5000) //Give time for result back strResult = xShell.Result //FIND THE PID of the process started with xShell.Execute(strConnect) xShell.Execute("taskkill /F /PID <pid>") //Close the process xShell.Close
If there isn't a way to do this is there a way to assign a different name to the process when you open it? Thanks for any help.