title: Track Desktop Application Session
body: <p>I am developing a WPF appllication which has to track session of desktop applications.I have used <code>ManagementEventWatcher</code> it works as expected, but my WPF application needs to be run as administrator. The users of the application will not have admin rights so the users getting <code>Access is denied</code> exception. </p>
  
  <p>Even while developing my application in Visual Studio, to query this ManagementEventWatcher("SELECT * FROM Win32_ProcessStopTrace") the Visual studio has to be run as administrator.</p>
  
  <p>How to get the stopped event processes without admin right?Is there other way so that i can get the stopped processes?</p>
  
  <p>Below is the code i have used:</p>
  
  <pre><code>processStopEvent = new ManagementEventWatcher("SELECT * FROM Win32_ProcessStopTrace");
  
  processStopEvent.EventArrived += new EventArrivedEventHandler(processStopEvent_EventArrived);
  processStopEvent.Start();
  
  void processStopEvent_EventArrived(object sender, EventArrivedEventArgs e)
  {
     string processName = e.NewEvent.Properties["ProcessName"].Value.ToString();
     string processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value).ToString();
  
      if (processName.ToUpper().Contains(processname.ToUpper().Replace(".EXE", "")))
      {
             //closed/disconnect desktop log
      }
  }
  </code></pre>