Hi All,
I am trying to fetch system-events, and I am successful
with "TimeChanged", but cannot get "SessionEnding". I am
not an OO expert and so - just to be sure - I made all
my methods public and static, this this does'nt seem
to help.
Could someone plesase help? My code is below:
using System;
using Microsoft.Win32;
using System.Diagnostics;
using System.Threading;
public class SystemEventDemo
{
public static EventLog eventLog = new EventLog("Application", ".",
"AdminTools");
public static Microsoft.Win32.SessionEndingEventHandler
sessionEndingEventHandler = new
Microsoft.Win32.SessionEndingEventHandler(OnSessio nEnding);
public static EventHandler timeChanged = new EventHandler(OnTimeChanged);
[MTAThread]
public static void Main()
{
Microsoft.Win32.SystemEvents.SessionEnding += sessionEndingEventHandler;
Microsoft.Win32.SystemEvents.TimeChanged += timeChanged;
while(true)
{
Console.WriteLine("Waiting for system-events!");
Thread.Sleep(60000);
}
}
public static void OnSessionEnding(object sender,
Microsoft.Win32.SessionEndingEventArgs e)
{
// the user session is ending or computer is shutting down /////// THIS
DOES NOT WORK!
Console.WriteLine("OnSessionEnding!");
eventLog.WriteEntry
(
String.Format
(
"The 'OnSessionEnding' event occured, Reason:{0}.",
e.Reason.ToString()
),
EventLogEntryType.Information,
2
);
}
public static void OnTimeChanged(object sender, EventArgs e)
{
//The time was changed[this fires and logs as expected]
Console.WriteLine("OnTimeChanged, begin.");
eventLog.WriteEntry
(
"OnTimeChanged",
EventLogEntryType.Information,
3
);
Console.WriteLine("OnTimeChanged, end.");
}
}
Any help is welcome. I am currently out of hope and even searches in
web/group
on google does not give any useful results.
Best regards,
Manfred Braun
(Private)
Mannheim
Germany
mailto:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)