-
Jun 12th, 2025, 05:29 AM
#1
Thread Starter
Lively Member
[RESOLVED] Checking lock status of another user's pc
Searched but couldn't find a solution so not holding out much hope, but is there a way to check if another user's workstation is locked either by passing the machine name or the logged on name?
-
Jun 12th, 2025, 08:14 AM
#2
Re: Checking lock status of another user's pc
 Originally Posted by AdorablePlum
Searched but couldn't find a solution so not holding out much hope, but is there a way to check if another user's workstation is locked either by passing the machine name or the logged on name?
Hmmmm...... https://community.spiceworks.com/t/w...unlocks/685905
And as always: Read until the end
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jun 12th, 2025, 01:07 PM
#3
Re: Checking lock status of another user's pc
The WTS APIs looked promising but I dead-ended for regular networked computers. I could get a server handle but access denied enumerating sessions, registering for session change events i only got them for my local account.
So my next thought was seeing if I could get a logged on user count from NetWkstaGetInfo. Access denied.
Suffice it to say, I can access the shares from these systems so I should have access.
What I tried:
Code:
Sub lou1()
Dim tInfo As WKSTA_INFO_102
Dim ppBuf As LongPtr
Dim lRet As Long
lRet = NetWkstaGetInfo(StrPtr("\\server"), 102, ppBuf)
Debug.Print "lRet=0x" & Hex$(lRet)
If ppBuf Then
CopyMemory tInfo, ByVal ppBuf, LenB(tInfo)
Debug.Print "users=" & tInfo.wki102_logged_on_users
End If
End Sub
Sub gls()
Dim hServer As LongPtr
Dim tSessionInfo() As WTS_SESSION_INFO
Dim tInfo As WTSINFOEXW
Dim ppBuffer As LongPtr
Dim lRet As Long
Dim cbRet As Long
Dim pc As Long
Dim i As Long
hServer = WTSOpenServerW(StrPtr("\\server"))
If hServer Then
If WTSEnumerateSessionsW(hServer, 0, 1, ppBuffer, pc) Then
If pc Then
ReDim tSessionInfo(pc - 1)
CopyMemory tSessionInfo(0), ByVal ppBuffer, LenB(tSessionInfo(0)) * pc
WTSFreeMemory ppBuffer: ppBuffer = 0
For i = 0 To UBound(tSessionInfo)
MsgBox "Session id=" & tSessionInfo(i).SessionId & ", state=" & tSessionInfo(i).State
If WTSQuerySessionInformationW(hServer, tSessionInfo(i).SessionId, WTSSessionInfoEx, ppBuffer, cbRet) Then
If cbRet Then
CopyMemory tInfo, ByVal ppBuffer, LenB(tInfo)
MsgBox "Session flags=" & tInfo.Data.SessionFlags & " (Level " & tInfo.Level & ")"
End If
If ppBuffer Then WTSFreeMemory ppBuffer: ppBuffer = 0
Else
MsgBox "WTSQuerySessionInformationW error 0x" & Hex$(Err.LastDllError) & ": " & GetSystemErrorString(Err.LastDllError)
End If
Next
Else
MsgBox "WTSEnumerateSessionsW succeeded but no sessions returned."
End If
Else
MsgBox "WTSEnumerateSessionsW error 0x" & Hex$(Err.LastDllError) & ": " & GetSystemErrorString(Err.LastDllError)
End If
WTSCloseServer hServer
Else
MsgBox "WTSOpenServerW error 0x" & Hex$(Err.LastDllError) & ": " & GetSystemErrorString(Err.LastDllError)
End If
End Sub
Going straight past enum sessions to WTSQuerySessionInformationW with 0, 1, or WTS_CURRENT_SESSION all end in access denied too.
(APIs defined in WinDevLib; exported at wdWTS.twin and wdAPI.twin if you want to copy them out for VB6 without using tB.
Last things to try for those are restarting to see if the EnableRemoteRPC option works after that (HKLM\SYSTEM\CurrentControlSet\Control); and maybe logging on by code somehow (Explorer prompts for credentials to access shares; maybe it doesn't apply to other processes?).
Last edited by fafalone; Jun 12th, 2025 at 02:44 PM.
-
Jun 12th, 2025, 02:49 PM
#4
Re: Checking lock status of another user's pc
I'm not going to dig it all out, but I've been down this rabbit hole before. IIRC, to do this via the LAN, you've got to have Windows Pro on the machine wanting to know, and the user trying to do it has to have administrative rights on the "target" machine. So, to do it, it's going to need to be someone with LAN-wide administrative rights.
If you're on a Windows Pro machine and have administrative rights, explore the "query" command line program.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 12th, 2025, 03:07 PM
#5
Hyperactive Member
Re: Checking lock status of another user's pc
When windows is locked, it starts a process called "LogonUI.exe". You could check the process list to see if it running with a WMI query
SELECT * FROM Win32_Process WHERE Name='LogonUI.exe'
You will need to turn on remote wmi in most environments https://learn.microsoft.com/en-us/wi...ing-with-vista
-
Jun 12th, 2025, 03:07 PM
#6
Re: Checking lock status of another user's pc
I'm logged on as admin on both; Win10 Pro on remote, Win10 Ent on local. Tried as SYSTEM\TrustedInstaller too.
Wondering if WTSConnectSessionW would help... but can it connect to the existing session; and how could you get the logon ID without hitting access denied?
-
Jun 12th, 2025, 03:46 PM
#7
Hyperactive Member
Re: Checking lock status of another user's pc
-
Jun 12th, 2025, 05:05 PM
#8
Re: Checking lock status of another user's pc
I'll try it later but will just asking for WTSConnectState instead of WTSSessionInfoEx matter?
-
Jun 12th, 2025, 05:13 PM
#9
Re: Checking lock status of another user's pc
I've looked at it a bit more, and it should be a command line query (as administrator) that looks something like the following:
> query user /server:user_name_here
Apparently, the Remote Procedure Call (RPC) service needs to be running, possibly on both machines.
I don't really have a full-blown LAN here, so I can't test.
If you could get a command line running, then you'd just need to figure out how to do that from VB6. Worst case, just create a BAT file and pipe the results out to a file, and then run the BAT and read the file from VB6.
Last edited by Elroy; Jun 12th, 2025 at 05:22 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jun 12th, 2025, 07:11 PM
#10
Re: Checking lock status of another user's pc
Good chance my code will work if that does and just changing the registry setting wasn't enough to enable Remote RPC.
-
Jun 13th, 2025, 12:04 AM
#11
Re: Checking lock status of another user's pc
 Originally Posted by Elroy
I've looked at it a bit more, and it should be a command line query (as administrator) that looks something like the following:
> query user /server:user_name_here
Apparently, the Remote Procedure Call (RPC) service needs to be running, possibly on both machines.
I don't really have a full-blown LAN here, so I can't test.
If you could get a command line running, then you'd just need to figure out how to do that from VB6. Worst case, just create a BAT file and pipe the results out to a file, and then run the BAT and read the file from VB6.
Yeah it's probably calling the same API under the hood...
Even after restarting after changing the EnableRemoteRPC option to 1... your command is giving me this:
C:\Users\Jon>query user /server:<name>
Error 0x00000005 enumerating sessionnames
Error [5]:Access is denied.
Where <name> is the string after the \\ in the network name for the tablet I was checking (while Explorer was browsing its shares).
Do you know any more details of what to enable? From my searches for using those APIs, only EnableRemoteRPC came up.
-
Jun 13th, 2025, 01:11 AM
#12
Re: Checking lock status of another user's pc
I don't understand, why you're so hung up on the Username.....
If a PC is locked or not has nothing to do with the logged in user, but only with the machine itself
Think about it: 5 Users can log in on the same Computer, but only one has an "active/unlocked" Session.
The Moment User 6 logs in, the previous "active" user gets locked out, the other 4 already being locked out, since User 5 grabbed the active Session.
Remember when you want to switch to another User, who is already logged in, but has not the active Session: You have to enter your credentials
So with all those queries/code/API based on Username, what result do you expect, if you query if User 3 is locked out? The Result is Yes, while User 6 is working on a fully functional machine
Read the Link i posted above
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jun 17th, 2025, 03:23 AM
#13
Thread Starter
Lively Member
Re: Checking lock status of another user's pc
Thanks for the input everyone. I tried various things but either I couldn't get them to work or they were blocked due to permissions.
In then end I went for dirty method of checking the lock status locally on a timer and writing a file on the server which can be read by the application. Seems to work so far.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|