C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

code to kill App

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
no one
Guest





PostPosted: Sun Feb 26, 2006 7:06 am    Post subject: code to kill App Reply with 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?


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





PostPosted: Sun Feb 26, 2006 8:06 am    Post subject: Re: code to kill App Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.