Skip to main content

Kill Process for Windows Mobile / Pocket PC

Lately i was working on Windows CE process view and way to kill particuler process in WIndows Mobile. Interestly there is "Running Programs" option available uder Start -> Settings -> System -> Memory -> Running programs but unfortunately it does not show all system related / critical processes running, so ihave decided to comeup with my own Kill Process application.

ToolHelp Library provides APIs which are usefule to handle processes. So we would need following header file and libraries to include in our solution / project.
1. Tlhelp32.h. 2. Kernel32.lib

Steps:

1. Take snapshot of currently executing processes in the system using API "CreateToolhelp32Snapshot" which returns a handle to the snapshot for further usage

2. Then walk through the process list using Process32First() to get the details of the first process into a PROCESSENTRY32 predefined and iterate this process using Process32Next().

3. After getting handle for first process compare the same with "process to be killed", we can use "_wcsicmp(const wchar_t *, const wchar_t *)" function to do the same. Where const wchar_t * is nothing but current process of snapshot const wchat_t * will be our "process to be killed" name. If both are matched then close tool help snapshot and return ProcessID using PROCESSENTRY32 structure element called "th32ProcessID".

4. Before killing process to be safer side we need to open process object which we have got in previous step and grant all access using following API
HANDLE WINAPI OpenProcess( __in DWORD dwDesiredAccess, __in BOOL bInheritHandle, __in DWORD dwProcessId);

5. Now we can close / kill process safely using follwoing API and close handle after done with terminate process.

BOOL WINAPI TerminateProcess( __in HANDLE hProcess, __in UINT uExitCode);

COde snippet ===================================

void CKillProc(TCHAR* procName){
// CFindProcess function takes procName string as input and return Process ID of procName if found in the process
DWORD dwPID = CFindProcess(procName);
HANDLE hProcess;
if (dwPID) // If process ID is non-zero then enter inside to kill the same
{ hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,dwPID);
// open process object to change access
TerminateProcess(hProcess,0);
// Kill process
CloseHandle(hProcess);
// Close handle
}
}

DWORD CFindProcess(TCHAR* procName)
{
HINSTANCE hProcessSnap = NULL;
PROCESSENTRY32 pe32 = {0};
//snapshot of currently executing processes
hProcessSnap = (HINSTANCE)CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS TH32CS_SNAPNOHEAPS, 0);

if (hProcessSnap == INVALID_HANDLE_VALUE ) return 0;
pe32.dwSize = sizeof(PROCESSENTRY32); // Set the size of the structure before using it.
if (Process32First(hProcessSnap, &pe32)) // Retrieve information about the first process, {
do
{ if (_wcsicmp(pe32.szExeFile,szName)==0)
// Compare current process name with process to be killed name.
{ CloseToolhelp32Snapshot(hProcessSnap);
// If both are match Close snapshot
return pe32.th32ProcessID; // return PID of current process.
}
}while (Process32Next(hProcessSnap, &pe32));
// goto next process name
}
CloseToolhelp32Snapshot(hProcessSnap);
// if no matches found then close snapshot and return zero
return 0;
}



Please let me know if you require full source code. i.e Windows CE Win32/MFC source code.

Comments

Unknown said…
I have an HTC phone and have been search for such a utility. Have you got a .cab that I can use? Thanks
Alan said…
don't worry - found one
http://zybermark.blogspot.com/2008/05/process-explorer-for-windows-mobile.html
Anonymous said…
Nice brief and this mail helped me alot in my college assignement. Thanks you on your information.
Anonymous said…
[url=http://www.ile-maurice.com/forum/members/wetter-vorhersage.html][b]wetter wetter[/b][/url]

[url=http://www.ile-maurice.com/forum/members/wetter-vorhersage.html][b]in wetter[b][/url]
Anonymous said…
[url=http://www.ile-maurice.com/forum/members/wetter-vorhersage.html]wetter dienst[/url]

[url=http://www.ile-maurice.com/forum/members/wetter-vorhersage.html]wetter wetterzentrale[/url]
Anonymous said…
[url=http://www.ganar-dinero-ya.com][img]http://www.ganar-dinero-ya.com/ganardinero.jpg[/img][/url]
[b]La mejor web sobre ganar dinero[/b]
Nosotros hemos hallado la mejor guia en internet de como ganar dinero internet. Como fue de utilidad a nosotros, tambien les puede ser de utilidad a ustedes. No son unicamente metodos de ganar dinero con su pagina web, hay todo tipo de metodos para ganar dinero en internet...
[b][url=http://www.ganar-dinero-ya.com][img]http://www.ganar-dinero-ya.com/dinero.jpg[/img][/url]Te recomendamos entrar a [url=http://www.ganar-dinero-ya.com/]Ganar dinero[/url][url=http://www.ganar-dinero-ya.com][img]http://www.ganar-dinero-ya.com/dinero.jpg[/img][/url][/b]
Anonymous said…
Amiable post and this fill someone in on helped me alot in my college assignement. Thank you seeking your information.
Term Papers said…
I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards
Unknown said…
Please post the full source for Windows CE Win32/MFC.

Popular posts from this blog

WinCE / PocketPC / Windows Mobile Power Battery Timeout - Solution

Hello Folks, I am back with yet another WinCE / Windows Mobile Solution this time it is something exciting and it is on Power Batter Suspend timeout related stuff. It is really challenging task to optimize battery life of any embedded device. Sometimes we want to control back light and battery suspend related activities through our program. OK .. here is simple question how do you control Back light, suspend timeout .. etc event through program ? To answer this question one has to understand "How WinCE operates w.r.t Power driver and what exactly happens behind the scenes". To simplify things ... i am going to divide whole things in three parts 1. WinCE OS Part whihc include Power / Battery drivers. 2. Application 3. Registry Registry : It is the place where all values gets stored i.e it acts as media for storing and retrieving values. I hope it is clear that Registry is nothing but global storage media and it has NO power to trigger anything. So that means it is of new us

What is the Current Directory in Windows CE & Windows Mobile ?

Lately i encountered  a situation where i had to find the current directory from where my application is running and all my config files reside. Question is "How do I find the current directory?" on Windows CE/Mobile devices. Desktop / PC it is just piece of cake but Windows CE / Mobile devices don't have a concept of a current directory.  Which means all pats are absolute and there is no concept called relative path. Due to lack of relative paths most of the files are loaded to the "Windows" directory and that is how Windows directory is crowded. Alternatively you can hard code directory path and insist user to load files always there. But i hate to hard code values or copy files to Windows directory.  So this has triggered to find a solution to identify my current directory. Since there is no concept of a current directory on a Windows CE / Windows Mobile device how would one locate a resource for which only a relative path is known?  That is what following c

Android Bluedroid debugging

Android Bluedroid Debugging  i.e New BT Stack from Android Community: Wow ... its been more than 2 years i updated my blog ... Am i too lazy or too busy or combination of both. Combination of both -:).  Anyways today i see a need to update my blog with some important info regarding Bluedroid debugging. Bluedroid is the latest and greatest Bluetooth stack from Android developed by Google & Broadcom jointly. So obviously Google does not have interest or resources to maintain two stacks hence they are going to drop famous BlueZ stack for good reasons.  BlueZ stack comes with lot of good tools like hcidump for debugging and i see all those tools no more work starting with Android JB MR2 a.k.a 4.3 which has Bluedroid integrated full-fledged.  So Bluedroid got to have new tools or some tools to debug but as usual Google is very poor at documenting the things and they leave finding puzzles to developers out there. SO today's quest is fining the debugging tools for Bluedroid.