2014-03-01 64 views
-1

我想使應用程序停留在後臺並記下哪些應用程序在前臺打開並記錄它們的路徑。誰能告訴我,如果它可能和如何去做C#應用程序,在後臺工作,並注意到其他打開的應用程序及其路徑

+1

所以..有什麼問題嗎? –

+0

想知道如何獲得稍後打開的應用程序,並獲得他們的路徑... –

+1

你能發表你自己的調查嗎?你到目前爲止編碼了什麼。你會採取什麼做法? – cvraman

回答

1

這裏是一個MSDN文章: http://msdn.microsoft.com/en-us/library/aa720671(v=vs.71).aspx

下面是一些InstanceCreationEvent下調代碼:

private void subscribeToProcessStartEvents() 
    { 
     string pol = "3"; 
     string queryString = "SELECT * FROM __InstanceCreationEvent WITHIN " + pol + " WHERE TargetInstance ISA 'Win32_Process'"; 
     ManagementEventWatcher watcher = new ManagementEventWatcher(queryString); 
     watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived); 
     try 
     { 
      watcher.Start(); 
     } 
     catch (Exception e) 
     { 
      MessageBox.Show("Error Occurred: " + e.ToString()); 
     } 
    } 

    public void watcher_EventArrived(object sender, EventArrivedEventArgs e) 
    { 
     ManagementBaseObject proc = ((ManagementBaseObject)e.NewEvent["TargetInstance"]); 
     MessageBox.Show(DateTime.Now.ToString() + ": Process " + proc["Name"] + " with Path: " + proc["ExecutablePath"] + " Has Started"); 
     //To see the arguments used: 
     string commandLineString = proc["CommandLine"].ToString(); 
    } 
相關問題