Only run script when pc is locked (lock screen)

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 987
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Only run script when pc is locked (lock screen)

Post by Grovkillen » Wed Jan 17, 2024 5:11 pm

Here's a proof of concept to have a script run only when the pc is locked. I just look for the process "LogonUI.exe" which is the lock screen. If it's running then the pc is locked. I hope it's help someone.

Code: Select all

OnEvent>CUSTOM,LOOP_TO_CHECK_IF_LOCKED_WORKSTATION,LOGONUI_IS_ACTIVE,RUN_THIS_ONLY_WHEN_SCREEN_LOCKED

Label>start_of_main_loop
Wait>10
Goto>start_of_main_loop

SRT>LOOP_TO_CHECK_IF_LOCKED_WORKSTATION
  Let>PID_array_count=0
  GetProcessIDs>LogonUI.exe,PID_array
  If>PID_array_count>0
    Let>LOGONUI_IS_ACTIVE=true
  Else>
    Let>SECONDS_SINCE_LOCKED=0
    Let>LOGONUI_IS_ACTIVE=false
  Endif>
END>LOOP_TO_CHECK_IF_LOCKED_WORKSTATION

SRT>RUN_THIS_ONLY_WHEN_SCREEN_LOCKED
  Wait>1
  Add>SECONDS_SINCE_LOCKED,1
  Message>SECONDS_SINCE_LOCKED
END>RUN_THIS_ONLY_WHEN_SCREEN_LOCKED
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts