Solved

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

Posted on 2013-12-10
7
393 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:or1969
  • 4
  • 3
7 Comments
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 39712646
Are you looking for changes to the path?  Is it on a Windows system?  If yes, are you using the FileSystemWatcher class?
0
 

Author Comment

by:or1969
ID: 39713285
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>)
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 39713398
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.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:or1969
ID: 39713442
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?
0
 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 500 total points
ID: 39717332
I'd HIGHLY recommend you try the FileSystemWatcher class.  it was designed for what you are doing and rather than recreate it yourself you might have more luck with it.

Also, are you running the service using the account that has credentials to access the share or are you authenticating in your code?  What account is the service running as?
0
 

Author Comment

by:or1969
ID: 39717366
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.
0
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 39717433
Not sure why the credentials aren't cached then.  Hopefully the FileSystemWatcher might fix it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question