tags:

views:

358

answers:

5

I want to find a process that belongs to a .EXE file with a specific file version number, and kill it. How can I do that?

I am working with Delphi, but any general help would be appreciated.

A: 

try and use the taskkill command, it has more control over what to filter by.

Beyond that your question is very confusing.

whatsisname
A: 

yer i know its a tough one, i just need to be able to kill the actuall file but not by right click, it must be via delphi which i can do, i just need to know how to kill the file by only looking inside the version.

ronnie, try to use comments instead of answers.
statenjason
@statenjason, you need 50 rep to post a comment, so there's really no other way for him to handle it, though he CAN edit his own post.
yx
There is no reputation minimum for posting comments within your own question, and Ronnie proves in his comment to Joseph's answer.
Rob Kennedy
A: 

You can kill a task by process name like this:

taskkill /im MyProcess.exe /f

But it sounds like you want to kill it based on the file version number. Is that correct?

JosephStyons
yes that is correct
I don't know the answer (yet) but I've modified your question in a way that I hope is clearer. If you disagree, feel free to roll it back.
JosephStyons
no thats fine thanks
+10  A: 

You can't "kill the file by only looking inside the version." You can kill a process if you have a handle to it. There are two common ways to get a process handle:

  1. Use the handle you got when you started the process with CreateProcess.
  2. Get a handle to an already-running process with OpenProcess.

I'll assume you haven't started the process yourself, so you'll need to use OpenProcess.

Then the issue turns to choosing which process to try to open. OpenProcess requires a process ID, and there are a few ways to get one of those, depending on what other information you already have about the process.

If you are concerned about the version number of the EXE file, then consider using the second method, but before you choose the process, open the EXE file and check the contents. That's a sufficiently different task from killing a process that if you have trouble with it, you should ask about it in a separate question.

Once you have the handle to the process you're interested in, you can kill it with TerminateProcess. Please heed the warnings in the documentation for that function; it's not a clean process shutdown by any stretch.

Finally, be careful that you observe the difference between window handles and process handles. They are not interchangeable. Use the HWnd type when you want to hold a window handle; THandle for process handles.

Rob Kennedy
i will try this now, thanks mate I really am greatful.
A: 

yer i want to kill it based on file description if possible as i can pull in the image name into delphi and have the user select the file but i want them to see descriptins also.

Again with the answer instead of a comment. Anyway, an EXE's description is stored as part of its version information, so if you want to ask, "How do I get an EXE file's version information?" then please do so; I don't see it answered here yet.
Rob Kennedy
Oh. I see you already have asked another question: http://stackoverflow.com/questions/1113645/question-about-pulling-in-process-info-delphi
Rob Kennedy