Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get users logged onto 2003 terminal server

88 views
Skip to first unread message

BMC

unread,
Oct 3, 2007, 6:10:01 AM10/3/07
to
I need to retrieve usernames of all users logged onto a Windows 2003 terminal
server. The script below is posted on several sites, purporting to do just
that. However, whilst the first WMI query does return the logon sessions, the
second returns nothing, so I cannot get the username. It does return expected
data when strComputer is a Windows XP desktop.

strComputer = "tserver"
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSessions = objWMI.ExecQuery _
("Select * from Win32_LogonSession Where LogonType = 10")
Wscript.Echo colSessions.Count & " users found"
If colSessions.Count <> 0 Then
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

jmi...@hotmail.com

unread,
Oct 5, 2007, 10:25:05 PM10/5/07
to
Why don't you just use the Terminal Services Manager utility? It lists
all the users currently connected.

Jeff

BMC

unread,
Oct 6, 2007, 9:08:01 AM10/6/07
to
Because I'm using a script to automate a process... is that so weird?
0 new messages