Bob Smith
2009-03-09 19:36:06 UTC
I created a script to determaine which users were logged in via RDP to a
server, however it doesn't seem to work very well. Users who have
disconnected from the server (which I have verified by TS Manager) still show
as connected. The information I gather is no different from the connected
users. I have included the output and the code.
Output from Connected User~
AuthenticationPackage: Kerberos
Caption:
Description:
LogonId: 1455198956
LogonType: 10
Name:
Status:
Username: bsmith1
FullName: Smith, Bob
Output from Disconnected User~
AuthenticationPackage: Kerberos
Caption:
Description:
LogonId: 14551989
LogonType: 10
Name:
Status:
Username: bsmith2
FullName: Smith, Bob (2)
strComputer = "MyServer"
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
wscript.Echo ""
WScript.Echo "AuthenticationPackage: " &
objSession.AuthenticationPackage
WScript.Echo "Caption: " & objSession.Caption
WScript.Echo "Description: " & objSession.Description
WScript.Echo "LogonId: " & objSession.LogonId
WScript.Echo "LogonType: " & objSession.LogonType
WScript.Echo "Name: " & objSession.Name
WScript.Echo "Status: " & objSession.Status
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
Wscript.Echo "FullName: " & objItem.FullName
Next
Next
End If
server, however it doesn't seem to work very well. Users who have
disconnected from the server (which I have verified by TS Manager) still show
as connected. The information I gather is no different from the connected
users. I have included the output and the code.
Output from Connected User~
AuthenticationPackage: Kerberos
Caption:
Description:
LogonId: 1455198956
LogonType: 10
Name:
Status:
Username: bsmith1
FullName: Smith, Bob
Output from Disconnected User~
AuthenticationPackage: Kerberos
Caption:
Description:
LogonId: 14551989
LogonType: 10
Name:
Status:
Username: bsmith2
FullName: Smith, Bob (2)
strComputer = "MyServer"
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
wscript.Echo ""
WScript.Echo "AuthenticationPackage: " &
objSession.AuthenticationPackage
WScript.Echo "Caption: " & objSession.Caption
WScript.Echo "Description: " & objSession.Description
WScript.Echo "LogonId: " & objSession.LogonId
WScript.Echo "LogonType: " & objSession.LogonType
WScript.Echo "Name: " & objSession.Name
WScript.Echo "Status: " & objSession.Status
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
Wscript.Echo "FullName: " & objItem.FullName
Next
Next
End If