ronnie
ronnie

Reputation:

How can I kill a process based on the version number of its .EXE file?

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.

Upvotes: 2

Views: 1749

Answers (3)

Rob Kennedy
Rob Kennedy

Reputation: 163277

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.

Upvotes: 12

JosephStyons
JosephStyons

Reputation: 58685

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?

Upvotes: 0

whatsisname
whatsisname

Reputation: 6150

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

Beyond that your question is very confusing.

Upvotes: 0

Related Questions