TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vv vv
NA
1
0
Windows Service that detects logon/logoff events
Jun 27 2009 5:41 AM
Hi,
I want to write a window service that detects the window logon/logoff event. i have written below listed code it is working fine at logoff time but not working at logon time
.
protected
override
void
OnStart(
string
[] args)
{
StartListenLogon(); //Not working when i log on my system
StartListenLogOff();
}
public
void
StartListenLogon()
{
string
_Query =
"SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_LogonSession'"
;
EventWatcher =
new
ManagementEventWatcher
(_Query);
EventWatcher.EventArrived +=
new
EventArrivedEventHandler
(EventWatcher_EventArrived);
EventWatcher.Start();
}
void
EventWatcher_EventArrived(
object
sender,
EventArrivedEventArgs
e)
{
string
fileName =
string
.Empty;
fileName =
@"D:\WindowsWatcherOn\"
+
DateTime
.Now.ToString(
"dd-MMM-yyyy_hh-mm-ss"
) +
"LOGON.txt"
;
File
.Create(fileName);
}
public
void
StartListenLogOff()
{
SystemEvents
.SessionEnded +=
new
SessionEndedEventHandler
(SystemEvents_SessionEnded);
}
void
SystemEvents_SessionEnded(
object
sender,
SessionEndedEventArgs
e)
{
string
fileName =
string
.Empty;
fileName =
@"D:\WindowsWatcherLogOff\"
+
DateTime
.Now.ToString(
"dd-MMM-yyyy_hh-mm-ss"
) +
"_LOGOFF.txt"
;
File
.Create(fileName);
}
please send me the solution on
[email protected]
please help thanks in advance
Vikas Aggarwal
Reply
Answers (
0
)
can't play embedded youtube swf on some computers
real time chat