Jump to content
Sign in to follow this  

Check if desktop/windows is locked end exit with error defined, if it is

Recommended Posts


Have tried a couple of functions, shown below, but none seem to work at deployment via SCCM (2012 sp1). Does anyone have a solution for this? Need to check at the beginning of the script if the computer is locked and if so abort the script with a predefined error code.

#include <APIConstants.au3>
#include <WinAPIEx.au3>

If _IsLocked() Then
    ConsoleWrite('Workstation Is Locked.' & @CRLF)
    Exit 666
    ConsoleWrite('Workstation Not Locked.' & @CRLF)

Func _IsLocked()
    Local $fIsLocked = False
    Local Const $hDesktop = _WinAPI_OpenDesktop('Default', $DESKTOP_SWITCHDESKTOP)
    If @error = 0 Then
        $fIsLocked = Not _WinAPI_SwitchDesktop($hDesktop)
    Return $fIsLocked
EndFunc   ;==>_IsLocked
MsgBox(0, "Test01", "Workstation Not Locked")

Func _WinLocked()
    if $h[0]=0 then $res=1
    DllCall("user32.dll", "int", "CloseDesktop", "int", $h[0])
    If $res = 1 Then
        MsgBox(0, "Test02", "Workstation Locked")
        exit($res)  ;1=computer locked, 0=unlocked

They work before I turn them into EXE files, but after that they only work when run as administrator and when I deploy the _WinLocked function via SCCM the script exits directly. Is there a function that can work when run as System via SCCM?

Share this post

Link to post
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
Sign in to follow this