How to show logged on users?
How to show logged on users?
(OP)
Is there a way to determine all of the currently logged on users of a Terminal Server? To be more specific, I want to be able to build a list of the users that appear in Terminal Services Manager at the time that I run my script.
The only possibility that I can see at this point is to search through HKEY_USERS for all of the following registry keys:
or
From there I would just extract the username data that I need.
Anyone know of a better way to enumerate the currently logged on users?
The only possibility that I can see at this point is to search through HKEY_USERS for all of the following registry keys:
CODE
HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer "Logon User Name" username
CODE
HKEY_USERS\<SID>\Volatile Environment "APPDATA" C:\Documents and Settings\username\Application Data
Anyone know of a better way to enumerate the currently logged on users?
RE: How to show logged on users?
use the .run method and cmd /c quser > c:\user.txt
this will pipe the output to a text file
than parse thru that.
RE: How to show logged on users?
CODE
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSessions = objWMI.ExecQuery _
("Select * from Win32_LogonSession Where LogonType = 10")
If colSessions.Count = 0 Then
Wscript.Echo "No interactive users found"
Else
WScript.Echo "RDP Sessions:"
For Each objSession in colSessions
Set colList = objWMI.ExecQuery("Associators of " _
& "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " _
& "Where AssocClass=Win32_LoggedOnUser Role=Dependent" )
For Each objItem in colList
WScript.Echo "Username: " & objItem.Name & " FullName: " & objItem.FullName
Next
Next
End If
I hope you find this post helpful.
Regards,
Mark
Check out my scripting solutions at http://www.thespidersparlor.com/vbscript
RE: How to show logged on users?