Hi everyone,
i'm trying to Handle the Micosoft.Win32. SessionSwitch Event, so when Windows is going to be locked by the user, i will simply write a line to the console.When it's going to be unlocked, the same.
Here's the code:
My Problem is now, that the Add/Remove Handler wants to have the 2 arguments given.
Here's the code in C# again, here it works flawless, without the arguments given.
Thank you and sorry for my bad englisch.
Chris
i'm trying to Handle the Micosoft.Win32. SessionSwitch Event, so when Windows is going to be locked by the user, i will simply write a line to the console.When it's going to be unlocked, the same.
Here's the code:
Code:
Sub Main()
AddHandler Microsoft.Win32.SystemEvents.SessionSwitch,
_ SystemEvents_Sessionswitch()
Console.ReadLine()
RemoveHandler Microsoft.Win32.SystemEvents,
_ SystemEvents_Sessionswitch()
End Sub
Private Sub SystemEvents_Sessionswitch(ByVal sender As Object,
_ ByVal e As Microsoft.Win32.SessionSwitchEventArgs)
If e.Reason = Microsoft.Win32.SessionSwitchReason.SessionLock Then
Console.WriteLine("locked at: " & DateTime.Now)
End If
If e.Reason = Microsoft.Win32.SessionSwitchReason.SessionUnlock Then
Console.WriteLine("unlocked at: " & DateTime.Now)
End If
End Sub
Here's the code in C# again, here it works flawless, without the arguments given.
Code:
using Microsoft.Win32;
public class App
{
static void Main()
{
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
Console.ReadLine();
SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
}
static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
if(e.Reason == SessionSwitchReason.SessionLock)
{
Console.WriteLine("locked at {0}", DateTime.Now);
}
if(e.Reason == SessionSwitchReason.SessionUnlock)
{
Console.WriteLine("unlocked at {0}", DateTime.Now);
}
}
}
Chris
Comment