Monday, 4 May 2015

How to check running process in your system and Kill it using C#

 Process[] checkprocess = Process.GetProcessesByName("notepad");
         
            if (checkprocess.Length > 0)
            {
                Console.WriteLine("is runing");
                checkprocess[0].Kill();
            }
            else {
                Console.WriteLine("not runing");
            }


Or you can  check all process in your system by using Process.GetProcesses(); method  

 Process[] proinfo = Process.GetProcesses();

its will  return all process list of your system which is running and you check one by one which process is ruining by foreach loop

  Parallel.ForEach(proinfo, file =>
            {
                Console.WriteLine("Process name is this {0} and its id {1} and {2}", file.ProcessName, file.Id, file.WorkingSet64);
             
                Process[] p = Process.GetProcessesByName("mspaint");
                if (p.Length > 0)
                {
                    Console.WriteLine("Mspaint is runing");
                 
                }
                else
                {
                    Console.WriteLine("Mspaint is not runing so we can't kill that process");
                }
               
            });
if have any query , please asked me at ankitpanwar15588@gmail.com

No comments:

Post a Comment