2009-03-16 7 views
12

외부 응용 프로그램을 시작할 때 Windows에서 C#으로 어떻게 감지합니까?응용 프로그램 실행 감지

파일이 실제로 변경되지 않기 때문에 작동하지 않는 FilesystemWatcher를 시도했습니다. 또한 타이머를 가지고 끊임없이 모든 열린 프로세스를 점검하는 것은 약간 죽일 수도 있습니다. 이것을 할 수있는 다른 방법이 있습니까? C#이 아니라면 C++에서 그렇게 할 수 있습니다 (그렇다면 예제를주세요).

내가 원하는 이유는 로깅 목적입니다. 어떻게이 일을 했는가 @stalkerh

답변

20

당신은 System.Management

class WMIEvent { 
    public static void Main() { 
     WMIEvent we = new WMIEvent(); 
     ManagementEventWatcher w= null; 
     WqlEventQuery q; 
     try { 
      q = new WqlEventQuery(); 
      q.EventClassName = "Win32_ProcessStartTrace"; 
      w = new ManagementEventWatcher(q); 
      w.EventArrived += new EventArrivedEventHandler(we.ProcessStartEventArrived); 
      w.Start(); 
      Console.ReadLine(); // block main thread for test purposes 
     } 
     finally { 
      w.Stop(); 
     } 
} 

    public void ProcessStartEventArrived(object sender, EventArrivedEventArgs e) {  
     foreach(PropertyData pd in e.NewEvent.Properties) { 
      Console.WriteLine("\n============================= ========="); 
      Console.WriteLine("{0},{1},{2}",pd.Name, pd.Type, pd.Value); 
     } 
    } 
+0

WMI (Windows Management Instrumentation)를 사용할 수 있습니까? MangementEventWatcher와 같은 다양한 유형은 System.Management 또는 System.Mangement.Instrumentation에 없습니다. 어디에서 찾을 수 있습니까? 내가 뭐 놓친 거 없니? – Svish

+0

신경 쓰지 마세요. System.Management dll에 대한 참조도 추가해야했습니다. pagery를 사용하는 것만으로는 안된다. ... * sigh * : p – Svish

+0

그러나'w = new ProcessStartEventArrived (q);는 여전히 작동하지 않는다 ... – Svish