Solved

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

Posted on 2013-12-10
7
392 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 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