Execute Task When Screen Is Locked

Am looking to execute a task but only of the screen is locked. When the user leave and windows is in secure mode, then, it is the time to do some routing browser cleanups, and reopen the browser.

How can I set in the task or in the relevance to only execute the action script when the windows or mac screen is locked.

How do you detect that the screen is locked?

I have been looking into powershell scripts. The code below seems to do the trick. But, I was hoping that Bigfix could do it as part of the execution task.

function GetRemoteLogonStatus ($computer = ā€˜localhostā€™) {
if (Test-Connection $computer -Count 2 -Quiet) {
try {
$user = $null
$user = gwmi -Class win32_computersystem -ComputerName $computer | select -ExpandProperty username -ErrorAction Stop
}
catch { ā€œNot logged onā€; return }
try {
if ((Get-Process logonui -ComputerName $computer -ErrorAction Stop) -and ($user)) {
ā€œWorkstation locked by $userā€
}
}
catch { if ($user) { ā€œ$user logged onā€ } }
}
else { ā€œ$computer Offlineā€ }
}

Call the function

GetRemoteLogonStatus

Thanks, thatā€™s useful. It looks like the conditioms are ā€˜there is a user logged onā€™ and ā€˜there is a process named logonui runningā€™. We should be able to work with that.

Iā€™m not near a computer now, but check whether exists logged on users and exists processes whose (name of it as lowercase = "logonui.exe") does the trick.

2 Likes

I set a test fixlet with the relevance suggested. The good news is that it does the trick. The next step is to evaluate if there is no one currently logged on. Having these two variables can assist on deciding what type of action script to execute on the remote computer. Some action scripts will not interfere with user work; then, knowing the user probably step out for a few minutes it will allow the script to move forward. If there is no one currently logged on, then, the action script could do some routing maintenance.

I got it.This is just an example action script code.

if {exists logged on users}
run "C:\windows\system32\notepad.exe"
endif
if {exists processes whose (name of it as lowercase = ā€œlogonui.exeā€)}
run "C:\windows\system32\notepad.exe"
endif

Hello lions1855,

You might need to change the script to something like this, to make sure both conditions are checked at the same time.:

if { (relevance1) and (relevance2) }

For example:

if {exists logged on users and exists processes whose (name of it as lowercase = "logonui.exe")}
run "C:\windows\system32\notepad.exe"
endif

Otherwise, if both conditions evaluated as true and you check them separately, notepad.exe might be ran twice.

Regards,
Vitaliy