Reputation: 62554
In a Windows Forms application I kill a process like this:
Process[] ps = Process.GetProcessesByName("DataWedge");
foreach (Process p in ps)
p.Kill();
How can I do it in the Windows Mobile operating system?
(This sample doesn't work on Windows Mobile.)
Upvotes: 0
Views: 7363
Reputation: 21
There is a bug in this code that makes it always return an empty list.
First, add this constant :
private const uint TH32CS_SNAPNOHEAPS = 0x40000000;
Then call it like this :
IntPtr snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS, 0 );
Upvotes: 0
Reputation: 68506
You need to enumerate the Processes running on the device in order to get it's process ID. Once you've got the processId you can just do:
Process process Process.GetProcessById(processId);
process.Kill();
Here's an article that deals with enumerating the processes, it also includes a kill example as well.
Upvotes: 1
Reputation: 31
Since the above article no longer exists I used the Wayback Machine to get the article to use the code. Below is how you would use the code from the article to enumerate through the processes and kill the one that you want:
List<ProcEntry> processes = new List<ProcEntry>();
ProcessEnumerator.Enumerate(ref processes);
foreach (ProcEntry proc in processes)
{
if (proc.ExeName == "DataWedge.exe")
{
ProcessEnumerator.KillProcess(proc.ID);
}
}
Upvotes: 2