开发者

Trigger an event when system locks/unlocks on Windows XP

Please help me to find a way to track lock/unlock time on my WinXP machine. I've tried windows scheduler - it only logs logins, not locks. Any alternatives?

In Miranda's source code I saw implementation via IdleObject tracker, but this way is too long. May be an AutoIt script? Time tracking program开发者_如何学编程 (freeware)?


If you have a Windows service you can get notification of login/logout/lock/unlock events via the OnSessionChange method. In C# you would do this:

 protected override void OnSessionChange(SessionChangeDescription changeDescription)
 {
        switch (changeDescription.Reason)
        {
            case SessionChangeReason.SessionLogon:
                //Logon
                break;
            case SessionChangeReason.SessionLogoff:
                //Logoff
                break;
            case SessionChangeReason.RemoteConnect:
                //Remote Connect
                break;
            case SessionChangeReason.RemoteDisconnect:
                //Remote Disconnect
                break;
            case SessionChangeReason.SessionLock:
                //lock
                break;
            case SessionChangeReason.SessionUnlock:
                //Unlock
                break;
            default:
                break;
        }
 }


I solved it using Windows XP built in eventtriggers.exe, which basically monitors one of Windows event logs for changes and allow you to trigger stuff based on criteria you specify. Since it is a log monitor it will usually trigger after a short delay

For example the following code that will call a BAT-file with a parameter depending on login/logout-related events (however, this is unfortunately not only actual user login/logouts but also system-related events and computer lock events)

eventtriggers.exe /create /tr "logout_occured" /l SECURITY  /eid 538 /tk "cmd /c c:\lockhandler.bat LOGOUT_OCCURED"
eventtriggers.exe /create /tr "login_occured" /l SECURITY  /eid 528 /tk "cmd /c  c:\lockhandler.bat LOGIN_OCCURED"


Do check that CanHandleSessionChange property is True or not ? This will be checked from the designer view -> Property

Then use OnSessionChange function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜