-
July 3rd, 2005, 06:42 AM
#1
killing a process according to its PID
Hi,
I'm looking for an API which enable killing a process according to its process ID.
Is there an API like that, I didn't find it
If not how can I kill a process, if I have its name (xxx.exe) & ID I can have 2 processes with the same name - running the same application twice (of course different PID)
Thanks in advance
Avi123
-
July 3rd, 2005, 06:54 AM
#2
Re: killing a process according to its PID
Use OpenProcess() with X_TERMINATE rights and then use TerminateProcess() to hardcode terminate a process. Or try to send WM_QUIT firstly, this is a finer and neater solution than just killing it.
-
July 3rd, 2005, 07:00 AM
#3
Re: killing a process according to its PID
Originally Posted by NoHero
Use OpenProcess() with X_TERMINATE rights and then use TerminateProcess() to hardcode terminate a process. Or try to send WM_QUIT firstly, this is a finer and neater solution than just killing it.
Before using 'TerminateProcess()' (which should only be used as a last resort) you might want to take a look at the following FAQ which demonstrates how to shutdown a process "cleanly"...
-
July 3rd, 2005, 07:07 AM
#4
Re: killing a process according to its PID
I know about all the other ways I can kill a process
and I would like to kill it according to the PID, is it possible?
If not how do I kill it if all I have is the name (xxx.exe) & the pid
Thanks
Avi123
-
July 3rd, 2005, 07:33 AM
#5
Re: killing a process according to its PID
Originally Posted by avi123
I know about all the other ways I can kill a process
and I would like to kill it according to the PID, is it possible?
If not how do I kill it if all I have is the name (xxx.exe) & the pid
Thanks
Avi123
like NoHero mentioned above Correctly, you can use the ::OpenProcess with the PID you have, the ::OpenProcess will return you a Handle to the Process and then you can call ::TerminateProcess() with the Handle
Code:
HANDLE hP= ::OpenProcess(PROCESS_ALL_ACCESS,0,Pid/*the pid you have*/);
::TerminateProcess( hP,0);
another method you can try using is locating the HWND of the process from the Pid, and then ::SendMessage(, WM_COSE,, ); to the window.
Code:
HWND h = ::GetTopWindow(0 )
while ( h )
{
DWORD pid;
DOWRD dwTheardId = ::GetWindowThreadProcessId( h,&pid);
if ( pid == /*your process that you looking for*/
{
/*here you have the thread id*/
::SendMessage(h,WM_CLOSE,0,0);
break;
}
h = ::GetNextWindow( h , GW_HWNDNEXT);
}
Cheers
Last edited by golanshahar; January 1st, 2009 at 12:41 AM.
-
July 3rd, 2005, 07:41 AM
#6
Re: killing a process according to its PID
Thank you all very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|