Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

Join Tek-Tips
*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 from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

How to show logged on users?Helpful Member! 

PPettit (IS/IT--Management) (OP)
1 Dec 06 18:29
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?
VulcanJedi (TechnicalUser)
1 Dec 06 19:16
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

Helpful Member!  markdmac (MIS)
2 Dec 06 2:16
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

PPettit (IS/IT--Management) (OP)
4 Dec 06 10:56
Thanks Mark.  That appears to be just what I was looking for.    

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!

Back To Forum

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