Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to kill a task given the task name? 4

Status
Not open for further replies.

gleason

Programmer
Jun 2, 1999
50
US
I am looking for a way to programatically kill a task running on an NT box just given the task name.&nbsp;&nbsp;<br><br>If I had a handle, I could call &quot;TerminateProcess()&quot; or just send a WM_QUIT to it or something, but all I will know is the task name.<br><br>As always, thanks for your help.<br> <p>Pat Gleason<br><a href=mailto:gleason@megsinet.net>gleason@megsinet.net</a><br><a href= > </a><br>
 
I think you can acheive the same by using SendMessage with the same WM_QUIT, and the application's Classname(which can be acheived by using FindWindow) <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Dear Pat,<br><br>I'm not sure what you mean by 'Task Name'. Could you clarify?<br><br>One way to kill desktop processes is to obtain their HWND's using EnumWindows(). Once you have the HWND you call PostMessage sending a WM_CLOSE message.<br><br>Note: Console applications are not required to handle WM_CLOSE so unless they specifically handle the message they&nbsp;&nbsp;will not close.<br><br>Hope this helps<br>-pete
 
Call EnumWindows, U will get the Window Handle, <br>then Call GetWindowThreadProcessId, U will get a process Id,<br>Call Terminate Process with the process Id.
 
Hi Sir,

Why do i keep getting zero for the return value of GetWindowThreadProcessId?
any idea? i can't seem to get the thread id.

Please help.
Thanks in advance.

hWnd = FindWindow(&quot;WindowsApp&quot;, &quot;Windows App&quot;);
dwPid = GetWindowThreadProcessId(hWnd, NULL);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top