Determine remote windows screen locked or unlocked remotely
Solution 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
Solution 2
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
Related videos on Youtube
![Syed Jahanzaib](https://lh6.googleusercontent.com/-4n5IKeJTYNA/AAAAAAAAAAI/AAAAAAAAACI/08wKHTa7kYI/photo.jpg?sz=256)
Syed Jahanzaib
Updated on September 18, 2022Comments
-
Syed Jahanzaib almost 2 years
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 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. How can I get required result by command or other method?
-
Syed Jahanzaib over 7 yearssorry 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. -
HPWD almost 3 years@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]) { ...