INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

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:

CODE

HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer "Logon User Name" username
or

CODE

HKEY_USERS\<SID>\Volatile Environment "APPDATA" C:\Documents and Settings\username\Application Data
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?

RE: How to show logged on users?

quser from command prompt?

use the .run method and cmd /c quser > c:\user.txt

this will pipe the output to a text file
than parse thru that.

yinyang Tranpkp pc2

RE: How to show logged on users?

Here you go:

CODE

strComputer = "servername"   ' " use "." for local computer


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?

(OP)
Thanks Mark.  That appears to be just what I was looking for.    

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close