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.
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.
try and use the taskkill command, it has more control over what to filter by.
Beyond that your question is very confusing.
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.
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?
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:
CreateProcess
.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.
GetWindowThreadProcessID
.CreateToolhelp32Snapshot
and then Process32First
and Process32Next
to inspect each process until you find one that matches.FindWindow
or EnumWindows
to get a window handle, and then use the first method.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.
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.