Solved

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

Posted on 2013-12-10
7
380 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:tedbilly
Comment Utility
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
Comment Utility
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:tedbilly
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:or1969
Comment Utility
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:
tedbilly earned 500 total points
Comment Utility
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
Comment Utility
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:tedbilly
Comment Utility
Not sure why the credentials aren't cached then.  Hopefully the FileSystemWatcher might fix it.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now