Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to terminate process

4 views
Skip to first unread message

Davidw

unread,
Dec 3, 2009, 5:33:39 AM12/3/09
to
Hi,
I am trying to terminate a running process.

HANDLE lProcSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lRes=Process32First(lProcSnapshot,&procEntry);
while(lRes)
{
if (procEntry.szExeFile == "myapp.exe")
{
hProcess = (HANDLE)procEntry.th32ProcessID;
if (!TerminateProcess(hProcess,113))
{
dwLaseError = GetLastError();
}
break;
}
lRes=Process32Next(lProcSnapshot,&procEntry);
}
CloseToolhelp32Snapshot(lProcSnapshot);

The process found, but I get dwLaseError = 6
Which is: ERROR_INVALID_HANDLE The handle is invalid.

Thanks,
David


Luca Calligaris [eMVP]

unread,
Dec 4, 2009, 7:55:27 AM12/4/09
to
The handle is invalid because you casting procEntry.th32ProcessID (the
process ID, a number) to a handle.

Given the process ID you can pass it to OpenProcess to retrieve the handle
to use in TerminateProcess.

Check even %_WINCEROOT%\PUBLIC\WCESHELLFE\OAK\TASKMAN to see how Task
Manager kills processes

--
Luca Calligaris (MVP-Windows Embedded)
l.calliga...@eurotech.it.nospam
www.eurotech.it


"Davidw" <da...@weinstein-d.com> ha scritto nel messaggio
news:OqpQ1PAd...@TK2MSFTNGP06.phx.gbl...

Paul G. Tobey [ eMVP ]

unread,
Dec 4, 2009, 11:15:01 AM12/4/09
to
In addition to Luca's very clear response, I'd like to note that you really,
really don't want to terminate a process, in most cases. Bad things happen
when you do this. The only case where it makes sense is when the process is
irrevocably locked and you have to exit it to keep the device operational.
That is, if you are doing some 'scripting' of the device (open Pocket Word,
do some stuff, close Pocket Word), you should not do the close operation via
TerminateProcess.

Paul T.

"Davidw" wrote:

> .
>

Bruce Eitman [eMVP]

unread,
Dec 14, 2009, 8:32:51 PM12/14/09
to
I just posted a function to kill a process on my blog at
http://geekswithblogs.net/BruceEitman/archive/2009/12/14/windows-ce-killing-an-application.aspx


--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT Eurotech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

Eurotech Inc.
www.Eurotech.com

"Davidw" <da...@weinstein-d.com> wrote in message
news:OqpQ1PAd...@TK2MSFTNGP06.phx.gbl...

0 new messages