I have this issue that I want to resolve. Lets think we have this situation. We have one instance of notepad.exe running. I run another notepad.exe. Now I want to kill the latter. How can I do it?

If I was able to know the pid of last notepad.exe then I could kill it. But how to get the PID of last opened program?

Another way is to give every application a unique image name. From what I learned it seems impossible becouse image names are hard coded into the binary file.

So any ideas?

P.S. As you already noticed this is all in windows.