I have several Windows 7/2008 workstation in my domain environment. We have a GPO that autolocks Window if no one is working on it(idle). No screensaver just lock.

How can I remotely check whether the remote workstation is Locked or Unlocked? I tried to query user using quser command (tested on user whose Windows is locked or another user whose Windows is unlocked, same result)

C:\>psexec \\REMOTEPC1 quser

 USER1                 console             1  Active      none   1/24/2017 11:21 AM

The above result is showing STATE=ACTIVE, but I am unable to query if the workstation is LOCKED/UNLOCKED. How can I get required result by command or other method?

3 Answers 3


I am unable to query if the workstation is LOCKED/UNLOCKED

Use the following PowerShell Script (GetRemoteLogonStatus.ps1).

This script will return the logon status of the local or a remote machine. Return types include "Not logged on", "Locked", "Logged on", and "Offline. The most useful part of this is to check whether a computer is in the locked state, although the other return types could also be useful.

This is a simple function, and can easily be included in a larger script. The return types could be changed to numbers for the calling script to more easily parse the return value.

# This function will return the logged-on status of a local or remote computer 
# Written by BigTeddy 10 September 2012 
# Version 1.0 
# Sample usage: 
# GetRemoteLogonStatus '<remoteComputerName>' 
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" } 

Source Get Remote Logon Status - Powershell

  • 1
    sorry for being noob, I have not used powershell scripts before. I simply made a file in notepad named GetRemoteLogonStatus.ps1 and pasted all contents in it. then I tried to executed it but its giving no output. example I started powershell by executing 'powershell' command, then run the script like PS C:\temp> .\GetRemoteLogonStatus.ps1 and the prompt returns, no error , no info etc. Jan 25, 2017 at 6:54
  • @SyedJahanzaib - did you replaced localhost with the actual computer name? You should be able to pass in a parameter to the script. That way, you would not need to edit the ps1 file every time you need to use it. getRemoteLogonStatus.ps1 laptopABC Inside the powershell script, modify the function as such: function GetRemoteLogonStatus ($computer = $args[0]) { ...
    – HPWD
    Aug 27, 2021 at 13:38

I forgot to update the post. Since I am using my Ubuntu box to manage most of the Active Directory functions using Webmin/BASH scripts, therefore I made a small bash script which queries for remote windows logged in user session and windows locked/unlocked status.


root@linux:/temp# /temp/winuserstatus.sh WORKSTAION-1

IP Details =

User Status = Logged in User found ... details as below ...
jahan.zaib console 13 Active 1+00:53 1/23/2017 1:57 PM
Windows Status = Windows is LOCKED

The bash script does the following …

  • Check for remote PC PING Status, if ping fails, exit with error

Get remote windows IP via NSLOOKUP using local DNS

Current Logged-in user and their status

Current status of windows either its locked/unlocked.

TRIM the results and display according to our taste

I posted it details here


There is a logonui process if the machine is locked.

if (System.Diagnostics.Process.GetProcessesByName("logonui").Any())
    //screen is locked
    // it's not locked 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.