3

I have several windows 7/2008 workstation in my domain environment. we have a GPO that autolock 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

 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
 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. howto get required result instantly by command or method??

1

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. – Syed Jahanzaib Jan 25 '17 at 6:54
1

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.

Result:

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

Remote PC = WORKSTAION-1
IP Details =
Address: 10.0.0.20
Address: 10.0.0.21

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

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.