How to kill a process?

I know the program name to be killed, such as 'UpdateUI.exe'.

How could I found the 'UpdateUI.exe' and killed the program?
Use TerminateProcess(): http://msdn.microsoft.com/en-us/library/ms686714%28VS.85%29.aspx.

That one requires a handle to the process. You can get a handle by using OpenProcess(): http://msdn.microsoft.com/en-us/library/ms684320%28VS.85%29.aspx.

OpenProcess(), in turn, requires the process ID. You can get the process ID by enumerating the currently running processes. Once you find a match for "UpdateUI.exe", then you can OpenProcess() and then TerminateProcess().

To learn how to enumerate processes, read the topic about the CreateToolhelp32Snapshot() at MSDN: http://msdn.microsoft.com/en-us/library/ms682489%28VS.85%29.aspx.
It's easy.

HANDLE tmpHandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessID);
if (NULL != tmpHandle)
{
TerminateProcess(tmpHandle, 0);
}

But you must know the process ID.

And you know the process name,
you can get the process id
easy
,in CMD mode, it's easy for you to use "ntsd -c q -p pid ",and you could terminate any process in ring3 level.
phikaa, since I'm not familiar with the command you post, I assume that it is for Linux/Unix? If so, please note that the topic is under the "Windows Programming" forum.
ntsd is the symbolic debugger and is irrelevant here.
It isn't irrelevant -- it answers the OP's question: how do I kill a process?

It does require you to start a new process (the ntsd.exe) and it also requires you to know the PID of the process to kill...

However, if you are going to use the command prompt, you can also use the taskkill Windows utility, which gives a few more options for selecting which process(es) to kill. (Works with XP and later.)
Being this a C++ forum, I'd say a command-line solution is irrelevant. When someone asks a question in these forums, I think it is expected to do it via C++.
You can find the PID of a process using its process name grammatically. Read this article from FrostCode

http://www.frostcode.info/common-articles/get-pid-from-process-name.html

Then, use TerminateProcess() to kill process.
Last edited on
Stop your spamming on all forums with your BS 'frostcode' : its only complete newbie and horrible pseudo-code
Read MSDN for the right method to get the PID
Read the Petzold to learn Windows programming .
Topic archived. No new replies allowed.