Jump to content

detecting Login Screen (excluding CTRL-ALT-DEL screen)?


Burgaud
 Share

Recommended Posts

I am writing a script to monitor my kid's use of computer such that:

1. If computer is idle for x minutes, it will hibernate. I know Windows already have this but somehow, can be circumvent with open files, or some video app disabling hibernation. 

2. Black Off the monitor after y minutes. And turns it back on after z minutes of rest. I call this process TimeOut to force my kid to stand up and take a walk...

(Basically I simply displays a BLACK Rectangle GUI in foreground. I know that games can circumvent this when it is not displaying in Windows Mode - this I need to fix later...)

So far so good. But I have some problems when the machine was turned on from hibernation. Machine always goes into a lockscreen waiting for password. How do I detect this?

This has been asked many times in the past with answers ranging from

detecting the "explorer.exe" (not working).

to _WinAPI_OpenDesktop('Default', $DESKTOP_SWITCHDESKTOP)                    ; but this captures the CTRL-ALT-DEL task manager page.

I want solely the login screen.

 

thanks

Link to comment
Share on other sites

Maybe this ?

#include <WinAPISys.au3>

Opt("MustDeclareVars", 1)

AdlibRegister(IsWorkstationLocked, 500)
Sleep(2000)
_WinAPI_LockWorkStation()
For $i = 1 To 30 ; now you have 30 secs to test various commands
  Sleep(1000)
Next

Func IsWorkstationLocked()
  Local Const $WTS_CURRENT_SERVER_HANDLE = 0
  Local Const $WTS_CURRENT_SESSION = -1
  Local Const $WTS_SESSION_INFO_EX = 25

  Local $hWtsapi32dll = DllOpen("Wtsapi32.dll")
  Local $result = DllCall($hWtsapi32dll, "int", "WTSQuerySessionInformation", "int", $WTS_CURRENT_SERVER_HANDLE, "int", $WTS_CURRENT_SESSION, "int", $WTS_SESSION_INFO_EX, "ptr*", 0, "dword*", 0)
  If @error Or Not $result[0] Then Return SetError(1, 0, False)

  Local $buffer_ptr = $result[4], $buffer_size = $result[5]
  Local $buffer = DllStructCreate("uint64 SessionId;uint64 SessionState;int SessionFlags;byte[" & $buffer_size - 20 & "]", $buffer_ptr)
  Local $isLocked = DllStructGetData($buffer, "SessionFlags")

  $buffer = 0
  DllCall($hWtsapi32dll, "int", "WTSFreeMemory", "ptr", $buffer_ptr)
  DllClose($hWtsapi32dll)

  ConsoleWrite("Is Locked ? " & $isLocked & @CRLF)
  Return $isLocked
EndFunc   ;==>IsWorkstationLocked

 

Edited by Nine
Link to comment
Share on other sites

Alternatively, you can search for "parental control and child monitoring software" (depending on what is legal in your particular country).
However, I personally would prefer to discuss these circumstances directly with the children, but this is of course your own decision.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

To test I used this code instead of the FOR LOOP

local $counter = 0
While 1
    if IsWorkstationLocked() Then
        $counter = $counter + 1
    else
        $counter = 0
    endif
    tooltip($counter)
    sleep(100)
WEnd

It counts up.

When I hit hibernate, then wake up, the counter starts from 0 indicating it detected correctly.

When I hit CTRl-ALT-DEL, it still continues counting up as i wanted!

 

The value of the return is opposite of the workstationlock status though. not a big problem.

 

Thanks for the help!

This solves a lot!

Link to comment
Share on other sites

  • 4 months later...

After a few months, my son was able to trick this function. he was able to do something (except login), that forces this function to return TRUE even if Windows 10 is not locked. Of course my son aint' telling me how.

ADD: I was able to do a screenshot that causes the fake "login screen" detection. I do not know how this was produced though.

I appreciate if anyone could tell me how to reproduce this without actually rebooting the machine or actual login.

re Parental Control:
The autoit I wrote (using this codes) simply blanks the screen after 30 minutes of use and will be made available 15 minutes later. I hope the kid would stand up and walk for a few minutes instead of sitting infront of the computer for the whole day, morning to evening... at first it was doing OK until he managed to do something....

Dan

DELL-7459_20200809_181935.png

Edited by Burgaud
add
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...