Users.exe v1.0.0.3

by Ryan 16. January 2013 11:42

In my last post, I showed how to get RDP/TS session information from a local or remote computer, including ClientName, on the command line using Powershell. (But it's not really Powershell. It's a PS wrapper around some C# that P/Invokes a native API. Which is pretty nuts but it works.)  Since I can't think of any other way to get this information on the command line, I thought it would be useful to convert the thing to native code. I named the program users.exe. It's written in C. Here is what it looks like:

C:\Users\joe\Desktop>users /?

USAGE: users.exe [hostname]

Not specifying a hostname implies localhost.
This command will return information about users currently logged onto
a local or remote computer, including the client's hostname and IP.
Users.exe was written by Ryan Ries.

C:\Users\joe\>users SERVER01

Session ID  : 0
Domain\User : System
Client Name : Local
Net Address : n/a
Conn. State : Disconnected

Session ID  : 1
Domain\User : System
Client Name : Local
Net Address : n/a
Conn. State : Connected

Session ID  : 25
Domain\User : DOMAIN\joe
Client Name : JOESLAPTOP
Net Address : 10.122.124.21 (AF_INET)
Conn. State : Active

I had a pretty rough time shaking the rust off of my native/unmanaged code skills, but I pulled it off.  That said, if you wanna give it a try, I would very much appreciate any bug reports/feature requests.

users.exe (63.50 kb)

Comments (3) -

Randall Cummins Canada
3/5/2013 2:24:05 PM #

Hey thanks for writing this... I developed one for our hospital out of python to quickly allow nurses to disconnect from their citrix sessions.  it works well, but i want to rewrite this with powershell...  I saw on your other site that had the .net code wrapped in powershell, pretty sweet!

Thanks!

Reply

Robert Wilde Australia
3/20/2013 1:47:48 AM #

This is awesome! I am setting up a dynamic floor plan for an office to show what thin clients are in use and where the free desks are.  I originally created a simple VB script to run at log on and log-off on the RDS host but soon realized the users sometimes logon, get side tracked then logon at another desk and I need to monitor that as well.
This provides me with Conn State and even the IP.

Any thoughts on the best way to get the output into a DB would be very handy for a lot of companies that use thin clients.

Thanks again

Reply

Christian Neels
10/25/2014 9:31:41 AM #

This program is nice! The output response is very fast too.
It grabs more relevant information that the 'query' command (the Client Name and Net Address are relevant to me).
Thanks man for creating this.

It will be awesome if you add support for 'user impersonation', so that it will also work when the terminal server is part from an other domain (or if your current account doesn't have permissions on the remote side).
I know I can locally run the 'runas' command with your program, but that will make run users.exe on a separate process with that user-account, which is isolated for batch tasks (and only works if your local machine accept that remote account for executing programs, which is not the case if there is no domain trust, or your machine is simply not member of that domain).

Please? :)

Reply

Pingbacks and trackbacks (2)+

Add comment

About Me

Ryan Ries
Texas, USA
Systems Engineer
ryan@myotherpcisacloud.com

I am a systems engineer with a focus on Microsoft tech, but I can run with pretty much any system that uses electricity.  I'm all about getting closer to the cutting edge of technology while using the right tool for the job.

This blog is about exploring IT and documenting the journey.


Blog Posts (or Vids) You Must Read (or See):

Pushing the Limits of Windows by Mark Russinovich
Mysteries of Windows Memory Management by Mark Russinovich
Accelerating Your IT Career by Ned Pyle
Post-Graduate AD Studies by Ned Pyle
MCM: Active Directory Series by PFE Platforms Team
Encodings And Character Sets by David C. Zentgraf
Active Directory Maximum Limits by Microsoft
How Kerberos Works in AD by Microsoft
How Active Directory Replication Topology Works by Microsoft
Hardcore Debugging by Andrew Richards
The NIST Definition of Cloud by NIST



MCITP: Enterprise Administrator

VCP5-DCV

Profile for Ryan Ries at Server Fault, Q&A for system administrators

LOPSA

GitHub: github.com/ryanries

 

I do not discuss my employers on this blog and all opinions expressed are mine and do not reflect the opinions of my employers.