title: vbscript list logged on users to terminal server
body: <p>Try to list the logged on users to a windows terminal server in a workgroup via vbscript.</p>
  
  <p>I have the below but it does not seem to return the logged on users?</p>
  
  <pre><code>strComputer = "."  
  
  Set objWMI = GetObject("winmgmts:" _ 
                &amp; "{impersonationLevel=impersonate}!\\" _ 
                &amp; strComputer &amp; "\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 " _ 
           &amp; "{Win32_LogonSession.LogonId=" &amp; objSession.LogonId &amp; "} " _ 
           &amp; "Where AssocClass=Win32_LoggedOnUser Role=Dependent" ) 
       For Each objItem in colList 
         WScript.Echo "Username: " &amp; objItem.Name &amp; " FullName: " &amp; objItem.FullName 
       Next 
     Next 
  End If
  </code></pre>