 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
no one Guest
|
Posted: Sun Feb 26, 2006 7:06 am Post subject: 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); |
|
| Back to top |
|
 |
Heinz Ozwirk Guest
|
Posted: Sun Feb 26, 2006 8:06 am Post subject: Re: code to kill App |
|
|
"no one" <on (AT) one (DOT) com> schrieb im Newsbeitrag
news:5aadnf5wv47E0JzZRVn-sQ (AT) comcast (DOT) com...
| Quote: | 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 |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|