470,848 Members | 1,751 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

code to kill App

Hi,

How do I kill a process in xp? It is really anoying. I have the code. I
suspect that I don't have permission to do it.

What is wrong with it?
HANDLE hProcess;
PROCESSENTRY32 pe32;
CString cstrProcess;
CString app;
BOOL bResult;
cstrProcess=process;
hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hProcess == INVALID_HANDLE_VALUE)
{
return (FALSE);
}

pe32.dwSize = sizeof(PROCESSENTRY32);

if (!Process32First(hProcess, &pe32))
{
CloseHandle(hProcess);

return (FALSE);
}

do
{
app=pe32.szExeFile;
if(cstrProcess==app)
{
// kill app if name matches
if(WaitForSingleObject(hProcess, 5000)
!=WAIT_OBJECT_0)
bResult = TerminateProcess(hProcess,0);
else
bResult = TRUE;
}
} while (Process32Next(hProcess, &pe32));
CloseHandle(hProcess);
return (TRUE);
Feb 26 '06 #1
1 1700
"no one" <on@one.com> schrieb im Newsbeitrag
news:5a********************@comcast.com...
Hi,

How do I kill a process in xp? It is really anoying. I have the code. I
suspect that I don't have permission to do it.

What is wrong with it?


1. If a function fails, examine the results (including documented
side-effects) to find the cause for its failure.
2. Don't use one variable for two (or more) tasks.
3. For OS related questions, OS related groups are almost allways a better
choice.

HTH
Heinz
Feb 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Alex Hunsley | last post: by
10 posts views Thread by Fred | last post: by
2 posts views Thread by Micky | last post: by
7 posts views Thread by David Mitchell | last post: by
3 posts views Thread by pattanawadee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.