Groups | Blog | Home
all groups > dotnet security > july 2004 >

dotnet security : Detecting User logon/Logoff events for a Windows Service



DotNetJunkies User
7/12/2004 11:14:28 AM
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!

---
Posted using Wimdows.net NntpNews Component -

Niroo
7/13/2004 3:51:02 AM
Not sure whether there is a better .Net way, but the platform mechanism is called SENS. I'm not sure whether this is callable from a service.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/syncmgr/syncmgr/about_system_event_notification_service.asp

Niroo

[quoted text, click to view]
AddThis Social Bookmark Button