开发者

How to kill a process in Windows Mobile?

In a Windows Forms application I kill a process like this:

    Pr开发者_JS百科ocess[] 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.)


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);
    }
}


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.


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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜