code to kill App

N

no one

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);
 
H

Heinz Ozwirk

no one said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top