title: How to capture that session logoff started from windows service
body: <p>I have a service which constantly checks some application and assures that it wasn't closed. If this app closed - service launches it again. </p>
  
  <p>The problem starts when user decides to log off the session. During logoff all applications are closing including the mine one. But the service is still running and constantly trying to start it again.</p>
  
  <p>The questions is how to notify the service that user is going to log off and the application doesn't need to be restarted anymore? I've tried to make it using SERVICE_CONTROL_SESSIONCHANGE notification. But in accordance to MSDN they come to services when all apps already closed and logging off procedure completed. It is too late for me. Is there any way to programmatically find out that current session is in process of logging off?</p>
  
  <p>My service launched under LocalSystem account.</p>
  
  <p>Thanks.</p>
  
  <p>p.s. I don't have the access to application source code. The goal need to be achieved without modifying it.</p>