Windows CE. How to kill a process by name?

10,137

I found a Code Project class which does exactly what i need it to do. Ill post it as an answer to this project.

http://www.codeproject.com/Articles/36841/Compact-Framework-Process-class-that-supports-full

        ProcessInfo[] list = ProcessCE.GetProcesses();

        foreach (ProcessInfo pinfo in list)
        {
            if (pinfo.FullPath.EndsWith("MyExe.exe"))
                pinfo.Kill();
        }
Share:
10,137
CathalMF
Author by

CathalMF

Updated on June 04, 2022

Comments

  • CathalMF
    CathalMF almost 2 years

    Im looking for a way to kill a process by name using C# on WindowsCE

    The .NET Compact Framework doesnt have a Process.GetProcessByName() method it only has a .GetProcessById() method.

    But i dont know how i can figure out the process id of my running process.

    I was thinking i could loop though all the process ids, but this is horrible because i dont know the max number of process ids. Anyone know a better way?

            for (int i = 1; i < 40000; i++)
            {
                Process prs = Process.GetProcessById(i);
    
                if (prs.StartInfo.FileName == "MyExe.exe")
                {
                    prs.Kill();
                }
    
                prs.Dispose();
            }
    

    EDIT: I found the solution to my problem. A codeproject link. http://www.codeproject.com/Articles/36841/Compact-Framework-Process-class-that-supports-full