Click here to Skip to main content
13,000,002 members (49,055 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 30 May 2009

Compact Framework Process class that supports fully specified file paths

, 30 May 2009
Rate this:
Please Sign up or sign in to vote.
Terminate a process, or check if it is running, using the full file path. It also enumerates processes returning the full path to the running EXE file.


I needed to be able to terminate all the processes in a specific folder.

The Process class in the .NET Compact Framework is limited in its functionality. You cannot even enumerate processes. You can find code to do this on the Internet, but all the samples I found only return the name of the EXE file of a process. What I needed was the full path to the EXE file.

After some research, I found the solution. I wrapped the result into the ProcessCE class.

What can the ProcessCE class do for you?

  • Enumerate running processes;
  • Each enumerated process contains the full path to the EXE file;
  • Check in a single function call if a process is running by specifying the full path to the EXE file;
  • Kill a process in a single function call by specifying the full path to the EXE file;
  • Find the Process ID (PID) in a single function call by specifying the full path to the EXE file.

This code is based on several code snippets and examples I found on the Internet.

Using the code

The ProcessCE class is straightforward and easy to use. Download and add the containing ProcessCE.cs file to your project. Then, add the following using statement to the source file where you want to use the class:

using Terranova.API;

To enumerate running processes:

ProcessInfo[] list = ProcessCE.GetProcesses();
foreach (ProcessInfo item in list)
   Debug.WriteLine("Process item: " + item.FullPath);
   if (item.FullPath == @"\Windows\iexplore.exe")

// Sample output:
// Process item: \Windows\nk.exe
// Process item: \Windows\filesys.exe
// Process item: \Windows\device.exe
// Process item: \Windows\services.exe
// Process item: \Windows\gwes.exe
// Process item: \Windows\shell32.exe
// Process item: \Windows\poutlook.exe
// Process item: \Program Files\Geso\Discovery\TerranovaWakeUpWCE.exe

To check if a process is running:

bool result = ProcessCE.IsRunning(@"\Windows\iexplore.exe");

To find a Process ID (PID):

IntPtr pid = ProcessCE.FindProcessPID(@"\Windows\iexplore.exe");
if (pid == IntPtr.Zero)
  throw new Exception("Process not found.");

To terminate a process:

bool result = ProcessCE.FindAndKill(@"\Windows\iexplore.exe"); 

ProcessCE.FindAndKill() will return false if the EXE file was not found. If terminating the process fails, it will throw a Win32Exception.

Points of interest

This code is for use with Windows CE and Windows Mobile only. The code was tested on Windows Mobile 6.1 (Windows CE 5.2). Windows CE 4 should be no problem.

Tip: A code example to enumerate processes that can be found on several websites was crashing randomly with Win32 error 8 on several devices. This is an out of memory message. The solution is to add the TH32CS_SNAPNOHEAPS flag to the CreateToolhelp32Snapshot() call:

CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS, 0)


  • 30 May 2009 - Article submitted.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Frank T. van de Ven
Software Developer (Senior)
Belgium Belgium
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThank you Pin
Member 89518472-Jun-16 6:24
memberMember 89518472-Jun-16 6:24 
Questionuseful code Pin
Member 184667011-Oct-15 3:16
memberMember 184667011-Oct-15 3:16 
QuestionAwesome work! Pin
Sergio Andrés Gutiérrez Rojas24-Jun-15 5:29
memberSergio Andrés Gutiérrez Rojas24-Jun-15 5:29 
GeneralGreat job! Pin
woytas9-Dec-14 4:15
memberwoytas9-Dec-14 4:15 
QuestionProcess killed by TaskMgr but not by this code Pin
cerede200027-Nov-14 5:41
membercerede200027-Nov-14 5:41 
Questionterminate VNCCE Process Pin
Member 1068188320-Mar-14 23:07
memberMember 1068188320-Mar-14 23:07 
QuestionVB.NET version of this code? Pin
seph0r1-Jan-14 21:39
memberseph0r1-Jan-14 21:39 
GeneralMy vote of 3 Pin
hjgode29-May-13 20:24
memberhjgode29-May-13 20:24 
BugCrashes device (WM65) in TerminateProcess Pin
hjgode29-May-13 20:23
memberhjgode29-May-13 20:23 
QuestionExcellent. Thanks. Pin
Member 848957513-May-13 5:22
memberMember 848957513-May-13 5:22 
GeneralWow! Niceeee. Clap! clap!! Pin
Roxxyy14-Jan-13 10:21
memberRoxxyy14-Jan-13 10:21 
QuestionMi respeto hermano!!!! Pin
gabriel loria29-Jan-12 5:23
membergabriel loria29-Jan-12 5:23 
QuestionSystem.OverflowException was unhandled Pin
ninefofo16-Aug-11 9:12
memberninefofo16-Aug-11 9:12 
AnswerRe: System.OverflowException was unhandled Pin
lyris16-Nov-12 4:09
memberlyris16-Nov-12 4:09 
GeneralRe: System.OverflowException was unhandled Pin
seph0r1-Jan-14 21:41
memberseph0r1-Jan-14 21:41 
GeneralBrilliant Pin
garyevans4-Jul-11 2:25
membergaryevans4-Jul-11 2:25 
GeneralPerfect job! Pin
RalphMaas27-Jan-10 23:57
memberRalphMaas27-Jan-10 23:57 
GeneralTrying to use this namespace in project Pin
SvenCPA27-Jan-10 5:54
memberSvenCPA27-Jan-10 5:54 
GeneralBrilliant! Pin
Muffadal4-Jan-10 23:56
memberMuffadal4-Jan-10 23:56 
GeneralRe: Brilliant! Pin
Frank T. van de Ven5-Jan-10 2:04
memberFrank T. van de Ven5-Jan-10 2:04 
GeneralThanks. finish my problem in 10 minutes Pin
Keshmahajan10-Dec-09 11:36
memberKeshmahajan10-Dec-09 11:36 
GeneralRe: Thanks. finish my problem in 10 minutes Pin
Frank T. van de Ven5-Jan-10 2:06
memberFrank T. van de Ven5-Jan-10 2:06 
QuestionThread List too? Pin
LiamD10-Sep-09 2:47
memberLiamD10-Sep-09 2:47 
GeneralThanks! Pin
Scalee26-Aug-09 13:09
memberScalee26-Aug-09 13:09 
Generalerror CS0029: Cannot implicitly convert type 'Terranova.API.ProcessInfo[]' to 'SmartCSD.Form1.ProcessInfo[]' Pin
nohear_t8-Jul-09 7:44
membernohear_t8-Jul-09 7:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 30 May 2009
Article Copyright 2009 by Frank T. van de Ven
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid