Jump to content

Way to detect when login is finished so I can lock workstation?


kor
 Share

Recommended Posts

I am running a script that first sets the auto admin login. It then reboots the machine and as soon as the auto login happens I lock the workstation Via this code.

; Set auto login to local administrator
RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName", "REG_SZ", $localuser)
RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", $localpass)
RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "1")

Once the machine reboots I use this code.

Sleep(2000)
Run("RunDll32.exe user32.dll,LockWorkStation") ; lock workstation
Sleep(2000)

The problem I am having is that some machines log in faster than others. And the lockworkstation isn't actually locking on slower machines. Is there a way to reliably assume when a computer has fully logged in then lock the workstation immediately? Is there something I can wait for or some service or process I can watch to see when a computer is finished with the login and is at the desktop?

EDIT: As I was thinking about it I thought maybe this would work. Have the lock workstation code inside a DO loop and try and lock the workstation every second until the "unlock workstation" window was active. That would be a good indication that the workstation was successfully locked, then move onto the rest of the code in the script.

Edited by kor
Link to comment
Share on other sites

This post looks as though it should help you with determining if the PC has been successfully locked.

If not locked then try again.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

This post looks as though it should help you with determining if the PC has been successfully locked.

If not locked then try again.

I stumbled upon that code right about the same time you posted.

Here is my modified code.

; Global variables
Global $DESKTOP_SWITCHDESKTOP = 0x100

Sleep(2000) ; allow time for initial login
While 1
    If _IsLocked() Then
        ExitLoop
    Else
        Run("RunDll32.exe user32.dll,LockWorkStation") ; lock workstation
    EndIf
    Sleep(1000)
WEnd

; main script
; main script

Func _IsLocked()
    $hDesktop = DllCall("User32.dll", "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP)
    $ret = DllCall("User32.dll", "int", "SwitchDesktop", "int", $hDesktop[0])
    DllCall("User32.dll", "int", "CloseDesktop", "int", $ret[0])

    If $ret[0] Then
        Return SetError(0, 0, 0)
    Else
        Return SetError(0, 0, 1)
    EndIf
EndFunc ;==> _IsLocked
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...