|
-
June 2nd, 1999, 12:01 PM
#1
How do I kill a proccess just knowing its name?
How can I kill all instances of say test.exe programatically? Anyone know of how to do this or have a sample of how it is done?
Thanks
George
-
June 2nd, 1999, 02:29 PM
#2
Re: How do I kill a proccess just knowing its name?
You basically need to get the process ID, pass it to OpenProcess, and then call TerminateProcess to kill it.
The tricky part is getting the process ID and for that you can use the classes found here in CodeGuru. I found a nice set at http://www.codeguru.com/misc/process.shtml and here's how you can use them:
CProcessList* pProcessList = CProcessList::Create();
pProcessList->SnapShot();
CString strFile = "c:\\the file you're interested in";
for (CProcess* pProcess; (pProcess = pProcessList->GetNextProcess()); )
{
if (pProcess->GetFilename() == strFile)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pProcess->GetPID());
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
Hope this helps!
Alvaro
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
|