Link to home
Start Free TrialLog in
Avatar of or1969
or1969

asked on

C# logon and logoff events are create when checking anything on the network

I've create a simple C# service that is checking the existence of a shared network path (on a domain) every 20 seconds.

the service is running using an account with Domain Admin rights.

My problem is that every 20 seconds a logon event is created (4624) and after 12 seconds a logoff event is created (4634).

Why? Is there a way to prevent that? I need the service to check every 20 seconds. I have no problem that it will logon once. But why it logs off every 12 seconds and logged on again?

Thanks
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

Are you looking for changes to the path?  Is it on a Windows system?  If yes, are you using the FileSystemWatcher class?
Avatar of or1969
or1969

ASKER

The same happens on the Microsoft OS's I've tested (XP and 7) checking if a directory or file exist on the connected network.

C# line is : Directory.Exist(@\\<MACHINENAME>\<SHARENAME>)
You didn't answer my question.  Are you using the FileSystemWatcher class in a service?  It doesn't sound like you are.  The FileSystemWatcher class is built to do what you are doing.
Avatar of or1969

ASKER

I using System.IO
Any of the classes used for connecting to the network will will create a logon event.

After additional testing, I've found that a logoff event is created after exactly 12 seconds.

When changing the timer to 5 seconds, the logon event is created once and there are no logoff events. I guess this keeps the session alive.

Now I'm thinking to create a separate thread timer that will check if a directory in the network exist every 5 seconds (keepalive).

May main concern, will it have any impact on communication of the DC?
ASKER CERTIFIED SOLUTION
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of or1969

ASKER

The service is running with a user account with domain admin rights and have access to the network share.

Thanks for the suggestion to use the FileSystemWatcher Class. I'll have time to test it tomorrow.

Thanks.
Not sure why the credentials aren't cached then.  Hopefully the FileSystemWatcher might fix it.