In my situation, I am looking for a solution wherein a specific task gets executed from batch file.
Upon executing the same batch file the task/ processid which gets started by batch file previously should only get kill.
Currently with the command
taskkill /f /im "notepad.exe"
powershell.exe Start-Process notepad.exe
All the instances of notepad gets close which were opened by user/ any other process. however, I specifically want this batch file to close the PID which get created by it and close the same PID in case we run this batch file again.
May be with this requirement batch file should write a file with the ProcessName and its PID. and for every execution of batch file it should look for process ID mentioned there and close it if already running and open a new instance and update the file where the PID is being stored.
Any help will be appreciated. Thanks