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.
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
http://zybermark.blogspot.com/2008/05/process-explorer-for-windows-mobile.html
[url=http://www.ile-maurice.com/forum/members/wetter-vorhersage.html][b]in wetter[b][/url]
[url=http://www.ile-maurice.com/forum/members/wetter-vorhersage.html]wetter wetterzentrale[/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]