header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Hooking Workstation Lock/Unlock Events?
Last Post 09 Sep 2008 11:32 AM by TreeStryder. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
TreeStryderUser is Offline
New Member
New Member
Posts:1
Avatar

--
09 Sep 2008 11:32 AM

    Try four at this post, the other three vaporized....
    -----

    I would like to run a script when my pc is locked and unlocked. Not finding lock/unlock events, I decided to create my own locking mechanism that could be called with a Start Menu shortcut with a keyboard combination.

    My first attempt (listed below) calls a function when started, locks the workstation with a RunDll call, waits while the screen saver process is active (borrowed from a scripting guys article), and when the machine is unlocked calls the Unlocked function. The problem is that our network policy has screen savers disabled, so I need another way to detect when the machine is locked. I looked around and learned that when "locked", windows actually switches the desktop to the Winlogon desktop (1). It seems like I should be able to make a call to User32.dll (2) to determin which desktop is active. But I just do not know enough about it to put the pieces of this puzzle together.

    Think you could help me out?

    Thanks


    (1) http://www.codeproject.com/KB/syste...nlock.aspx

    (2) http://waynes-world-it.blogspot.com/2008/04/unlocking-xp2003-without-passwords.html

    function Locked {
        # Do stuff before locking the workstation
    }

    function Unlocked {
        # Do stuff after unlocking the workstation
    }

    function WaitForUnlock {
        $ScreenSaverPath = (get-item "HKCU:\control panel\desktop\").GetValue("scrnsave.exe")
        while ([boolean] (get-process | where-object {$_.Path -like $ScreenSaverPath})) {
        Sleep .5
        }
        Read-Host "Until I find a better way to detect when the system is unlocked Hit Enter to Continue"
    }

    "{0:G} Locked" -f $([datetime]::Now)
    . Locked
    rundll32.exe "user32.dll,LockWorkStation"
    WaitForUnlock
    . Unlocked
    "{0:G} Unlocked" -f $([datetime]::Now)

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer