본문 바로가기

C#

프로세스 목록을 얻어오기 및 실행종료

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Diagnostics;

using System.Threading;



namespace ConsoleApp2

{

    class Program

    {

        static void Main(string[] args)

        {

          

            Process[] pl_allproc = Process.GetProcesses();

            int count = 1;


            Console.WriteLine("[*] 현재 프로그램에서 실행 중인 프로세스의 수 {0}", pl_allproc.Length);

            foreach(Process p in pl_allproc)

            {

                Console.WriteLine("[{0}]. 프로세스", count++);

                WriteProcessInfo(p);

            }

            Console.ReadLine();

            return;

        }


        private static void WriteProcessInfo(Process p)

        {

            try

            {

                Console.WriteLine("프로세스 이름 : {0}", p.ProcessName);

                Console.WriteLine("시작 시간 : {0}", p.StartTime);

                Console.WriteLine("프로세스 아이디[PID] : {0}", p.Id);

                Console.WriteLine("메모리 크기 :  {0}", p.VirtualMemorySize64);

                Console.WriteLine("프로세스 응답 여부 : {0}", p.Responding);

                Console.WriteLine("세션 아이디 : {0}", p.SessionId);

                Console.WriteLine("우선 순위 : {0}", p.BasePriority);

                Console.WriteLine("핸들 갯수 : {0}", p.HandleCount);



                CheckandKill(p);

            }

            catch(Exception E)

            {

                Console.WriteLine(E.ToString());

            }

        }


        private static void CheckandKill(Process p)

        {

            if(p.ProcessName.Equals("target"))

            {

                p.Kill();

            }

        }

    }

}



'C#' 카테고리의 다른 글

DNSPY c# 디컴파일 툴  (0) 2019.08.27
c# dll export  (0) 2019.01.10