Question

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.

Was it helpful?

Solution

If these are someone else's processes (i.e. you didn't start them yourself), then Windows keeps track of when the process was started (or its "creation time"), so I expect you could just find whichever process started last using that information.

OTHER TIPS

Well, how are you launching the process? For example, if you are launching it from C#, the static Process.Start method returns a Process instance, which has an Id, and a Kill() method. The mechanism will differ between architectures/languages...

And if you aren't doing it through code, it may be off-topic ;-p

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top