Users.exe v1.0.0.3

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 (11) -

Randall Cummins 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!

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

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? Smile

Dear ryan,

Thanks for the sharing User.exe i have i question
How can i log off all connected users from rdp server?

Thanks
Glory

Thanks for dropping by.

I'm pretty sure you'll have to script it.  Use Powershell to parse the output of users.exe (or quser.exe or qwinsta.exe or whatever) and logoff X for every user you find, where X is the session number assigned to that logged on user.

Adam Turner 4/6/2015 1:15:07 PM

Hey Ryan,

Is the source code available for this? I saw the .NET in another one of your posts but it looks a little out of date (doesn't return the IP address, etc.)

Thanks!
Adam

Adam Turner 4/6/2015 1:48:08 PM

Nevermind, I found your github Smile

Danny PLUVIER 8/24/2015 4:03:41 AM

thanks.
very usefull tool !!

keep up the good work

thanks!!!
very handy, appreciate it. ;)

I have the following error
ERROR 997: Could not connect to servername!

is it because i don't have permission to remote to that server?

i tried to run yr tool for the remote server i have access to, but still get the same 997 error

Pingbacks and trackbacks (2)+

Comments are closed