I'm developing an application to run in the background for capturing a user's activity on their system, like logoff/shutdown/idle/switch user/continues press of any key/system lock etc.
It's working fine and I am able to track all activities, now I need to log off the user automatically after 15 min of system lock.
I have tried the code below. The ExitWindowsEx()
function is working fine when user is logged in but not working after the user has locked their system.
[DllImport("user32")]
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
private SessionSwitchEventHandler sseh;
void SysEventsCheck(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLock:
if(condition)
{
ExitWindowsEx(0, 0);
}
break;
}
}
Can any one help me how to log off the user when he/she is in locked state.
Finally got an alternative to the problem,
public static bool _IsLocked;
private SessionSwitchEventHandler sseh;
void SysEventsCheck(object sender, SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case SessionSwitchReason.SessionLock:
if (!_IsLocked)
{
Process.Start("shutdown", "/r /f /t 900");
}
_IsLocked = true;
break;
case SessionSwitchReason.SessionUnlock:
if (_IsLocked)
{
Process.Start("shutdown", "-a");
}
_IsLocked = false;
break;
}
}
Above code will schedule system restart (15 min) at the time of system locking, if user unlock system before 15 min code will cancel that schedule otherwise this will restart system after 15 min.
Process.Start("shutdown", "/r /f /t 900");
Process.Start("shutdown", "-a");