Jump to content

Check if workstation is locked on Windows 10


Kerl
 Share

Recommended Posts

Hi, this used to work on Windows 7 64, but doesn't on Windows 10 64:

Func _isWorkstationLocked()
    $hDesktop = DllCall("User32.dll", "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", 0x100)
    $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

Please, has anybody an idea how to make this work on Windows 10 64?

Link to comment
Share on other sites

  • 2 months later...

I am trying to write a script that will keep a software logged in. It has a login window that pops up centered on the active application every 30 minutes, sometimes it pops over and sometimes it pops under. There is an option to keep the connection alive by clicking "Stay Logged In". Unfortunately when the window pops under the active application, I don't see it and it isn't easy to notice in the Task Bar that it's about to log out. The script activates the window, bringing it the focus, and then clicks the "Stay Logged In" button. It works fine when at the desktop and working in other applications. It will not work when the system is at the lock screen. Yes, I know about the limitations of the SEND() command; this is why it won't work

I have tested the script shown above by Kerl and I've also tested the script shown above by jguinch. Both scripts tell me when I'm at the login screen. Neither script tells me if I'm at the lock screen in Win10. When you are on a domain and press Ctrl+Alt+Del and the click "Lock" (or press Win+L) and the computer is on a domain, you are shown the lock screen. I have tried numerous other scripts on the AutoIt Forums as well as the AutoIt Wiki, and all seem to replicate the same behavior.

    Both scripts do not distinguish between the lock screen and the desktop.
    Both scripts show that the system is locked at the login screen (after Ctrl+Alt+Del and before logging in) and at the log off screen (after Ctrl+Alt+Del and before clicking "Lock").
    Both scripts show that the system is NOT locked while on the lock screen.
    Both scripts show that the system is NOT locked while on the desktop.

I need a script that will determine if the system truly is locked and not simply at the security screen (which is what these two scripts above do).

Who lied and told you life would EVER be fair?

Link to comment
Share on other sites

  • 2 weeks later...
On 5/11/2017 at 0:26 AM, Floops said:

@benched42 not the solution you are looking for, but have you tried ControlSend?

Yes I have. It doesn't seem to work. I have the utility writing to a log file to see when it fires. ControlSend() requires the controlID as a parameter, and the controlID changes with each instance of the popup.

Who lied and told you life would EVER be fair?

Link to comment
Share on other sites

ControlSend() does not have to use the controlID. There are several other properties of the control you can use to identify it, Check the help file, Specifically this section Autoit->Using AutoIt->Controls

"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

  • 1 year later...

Hi all.

I know this is an old thread, but wanted to offer another solution - Just check for a specific process:

If ProcessExists("LogonUI.exe") Then...

The logonui.exe is running only when the screen is locked on Windows 10 or there is another user with disconnected session (Switch User has taken place at some point). So the best way is to first check for any disconnected sessions, along with the check for an active session (quser is sufficient for that). If there is only one session, then the above code is enough. If there are more than one session, then must logoff all disconnected ones, and then check for the process. If exists, then for sure the active session has a locked screen.

Edited by rickjames
Link to comment
Share on other sites

  • 1 year later...

This seems to work for me on win10 x64:

#include <WinAPISys.au3>

Func _isWindowsLocked()
    If _WinAPI_OpenInputDesktop() Then Return False
    Return True
EndFunc

Never mind, I had my win 10 pc settings set to disable the welcome screen/clock/picture thing and go directly to the user selection screen when locked so this only worked on my pc, tested on emulator with default win10 settings and it does not work...

Edited by garbb
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...