asharma

asharma

  • NA
  • 1
  • 0

Detecting User logon/Logoff events for a Windows Service

Jul 12 2004 2:21 PM
I have written a windows service that needs to perform certain functions only if a User is logged in. The problem I am running into is that I get an error if the computer is in the process of being shut down or restarted. At all other times, the service runs just fine. I need to either detect a logon/logoff event OR check somehow as to whether there is currently a valid logged on user. The closest I have found is ManagementEventWatcher class, but I am not able to determine the appropiate event class to query for the Audit logon/logoff events. Basically I just need to not try and open the ad-watch if the user has logged off (Event Id 538). Of course, if there is an easier check, please let me know of that! I do appreciate any assistance on this. Thank you!

Answers (1)