2010-01-27 2 views
2

C#을 사용하면 이미지 이름, 설명 및 프로세스 ID를 포함하여 현재 컴퓨터에서 실행중인 모든 프로세스 목록을 어떻게 얻을 수 있습니까? 나는 자원 정보가 없어도 작업 관리자의 "프로세스"탭에서 볼 수있는 것과 비슷한 것을보고있다.C#에서 Windows 프로세스 목록을 반환하는 방법?

답변

4

이렇게하려면 진단 패키지에서 사용 가능한 유틸리티를 사용해야합니다. 이 코드를 발견하고 잘 작동합니다.

이 행은 프로세스를 정확하게 검색합니다. 그러면 각 프로세스의 특성을 추출 할 수 있습니다.

`Process [] allProcs = Process.GetProcesses();

전체 코드는 다음과 같습니다. 필요에 따라 사용자 정의 '

using System; 
using System.Diagnostics; 

public class ListProcs 
{ 
public static void Main() 
{ 
    int totMemory = 0; 
    Console.WriteLine("Info for all processes:"); 

    Process[] allProcs = Process.GetProcesses(); 
    foreach(Process thisProc in allProcs) 
    { 
    string procName = thisProc.ProcessName; 
    DateTime started = thisProc.StartTime; 
    int procID = thisProc.Id; 
    int memory = thisProc.VirtualMemorySize; 
    int priMemory = thisProc.PrivateMemorySize; 
    int physMemory = thisProc.WorkingSet; 
    totMemory += physMemory; 
    int priority = thisProc.BasePriority; 
    TimeSpan cpuTime = thisProc.TotalProcessorTime; 

    Console.WriteLine("Process: {0}, ID: {1}", procName, procID); 
    Console.WriteLine(" started: {0}", started.ToString()); 
    Console.WriteLine(" CPU time: {0}", cpuTime.ToString()); 
    Console.WriteLine(" virtual memory: {0}", memory); 
    Console.WriteLine(" private memory: {0}", priMemory); 
    Console.WriteLine(" physical memory: {0}", physMemory); 
    } 

    Console.WriteLine("\nTotal physical memory used: {0}", totMemory); 
    } 
    } 

원본 참조 article.

관련 문제