Killing running applications on pocketpc 2002

  • Thread starter Thread starter Roy Rodsson via .NET 247
  • Start date Start date
R

Roy Rodsson via .NET 247

Hi,
I have been trying to kill running applications on my pocket pc from code for a while now without success.

How do I (for instance) kill the Inbox application? or the poutlook.exe ?

I want to be able to unload both dll:s and exe files from the memory (from code) .
The api function FreeLibrary seems to only handle dlls -right? How do I unload exe files?

Thanks in advance,
Roy
 
Killing things is bad (just so we start on the right tone). You really,
really don't want to be randomly terminating applications on the device.
That could easily leave things in a bad, or even inoperative state.

To accomplish it, you'll have to use the toolhelp API for which there is no
managed code wrapper. My suggestion would be to write a DLL in C which
calls toolhelp to terminate an application which you specify in some way
from managed code (name of the EXE, maybe). Your custom DLL could have a
nice simple interface easily P/Invoked from managed code.

The toolhelp functions you'll need are:

CreateToolhelp32Snapshot
Process32First
Process32Next
CloseToolhelp32Snapshot

You'll also need to call a few standard API functions:

OpenProcess
TerminateProcess
CloseHandle

There is also an article on MSDN that Alex wrote on this topic which might
help:

http://msdn.microsoft.com/library/d.../dnnetcomp/html/ProcessManager.asp?frame=true

Paul T.

Roy Rodsson via .NET 247 said:
Hi,
I have been trying to kill running applications on my pocket pc from code
for a while now without success.
 
Before you resort to killing the process you should consider getting the
window handle of the application and send it a WM_CLOSE message. This will
allow the application to close down cleanly. If that doesn't work you can
then kill the process as a last resort.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

Paul G. Tobey said:
Killing things is bad (just so we start on the right tone). You really,
really don't want to be randomly terminating applications on the device.
That could easily leave things in a bad, or even inoperative state.

To accomplish it, you'll have to use the toolhelp API for which there is
no
managed code wrapper. My suggestion would be to write a DLL in C which
calls toolhelp to terminate an application which you specify in some way
from managed code (name of the EXE, maybe). Your custom DLL could have a
nice simple interface easily P/Invoked from managed code.

The toolhelp functions you'll need are:

CreateToolhelp32Snapshot
Process32First
Process32Next
CloseToolhelp32Snapshot

You'll also need to call a few standard API functions:

OpenProcess
TerminateProcess
CloseHandle

There is also an article on MSDN that Alex wrote on this topic which might
help:

http://msdn.microsoft.com/library/d.../dnnetcomp/html/ProcessManager.asp?frame=true

Paul T.

Roy Rodsson via .NET 247 said:
Hi,
I have been trying to kill running applications on my pocket pc from code
for a while now without success.
 
Peter,
How can one get the window handle of an application that is already running
on the Pocket PC (PPC WM 2003) ? Say the Pocket Word app (pword.exe) ?

I use C#.NET.

Thank you.

Peter Foot said:
Before you resort to killing the process you should consider getting the
window handle of the application and send it a WM_CLOSE message. This will
allow the application to close down cleanly. If that doesn't work you can
then kill the process as a last resort.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
You'd probably use EnumWindows( <your callback>,
processIDOfProcessToTerminate ); Note that this requires a callback, which
you can't just quickly do in .NET CF. I believe that Alex may have posted
some code a while back to do this, or you can do it in a native DLL quite
easily. In the callback, you'd do something like this:

DWORD tprocID = (DWORD)targetProcID;
DWORD procID;
GetWindowThreadProcessId( hwnd, &procID );

if ( tprocID == procID )
{
// Send WM_CLOSE message...
PostMessage( hwnd, WM_CLOSE, 0, 0 );
}

return TRUE; // Continue...

After calling EnumWindows in the main routine, you'd want to give the
WM_CLOSE operation a chance to exit the application, but you'd also want to
try to tell the main thread to quit, in case it either has a modal dialog up
or has no windows, before you call TerminateProcess, so you might do:

// Post a WM_QUIT message to the main thread in the process.
PostThreadMessage( processID, WM_QUIT, 0 /* nExitCode */, 0 );

// Wait for the process to quit.
wait = WaitForSingleObject( hProcess, 1000 );
if ( wait != WAIT_TIMEOUT )
{
return TRUE;
}

Paul T.
 
You can use JShell of Windows Mobile Developer Power Toys

--
David Amador Tapia
WebMaster "La Web de Davphantom"
www.davphantom.net
Cartagena. Colombia


Roy Rodsson via .NET 247 said:
Hi,
I have been trying to kill running applications on my pocket pc from code
for a while now without success.
 
Back
Top