Get logged on RDP users on Windows Terminal Server

Hi,

I have a very tricky question.
I want to have a overview of some Windows Terminal Servers. One aspect to monitor is the count of users and a list of users on a TS (terminal server). I solved this by getting the list of all “explorer.exe” and the owners. This works pretty fine. Unfortunately it does not work for RemoteApp users. So I need a new way to get all users including the RemoteApp users.
Recoginzing every single RemoteApp seems to be a dirty way but is possible.
Do you have any other solutions?
Some ideas and words to my config:
The webserver is a Win 2008 R2 with IIS and php. I need this to get the WMI Querys running. TS are 2008R2 or 2012R2.
An idea is to run the command “query session” with the exec() function. Unfortunately the return is blank. Other commands, like ipconfig, return stings/array as expected. Can you imagine why there is empty return?

I know my english is very bad but I hope I described the issue accurately.
Thank you for your help.

Well, not experienced much in Terminal Servers, but, as far as I know you just have to shell out the “quser” command.
This will display a list of current users and their sessions. In PHP, I think you can use the shell command and run this
function and return the displayed list. Then, you would have a string that you could parse to get the info you need.

But, there is a program written in C that can do it. You would have to shell out to that, too, to get a response back.
Here is a link to that one: https://www.myotherpcisacloud.com/post/Usersexe-v1003

Not sure if any of this helps…

Thank you for your reply. quser is short for query user and will return empty string like command query session. Seems every query command returns nothing.
I will check the exe. Hope this helps :slight_smile:

Hmmm, it should work. Oh, the quser command must run on the server, but, I think it will run using remote desktop.
If you are talking about running it using PHP, it would need to run on the server and the PHP file would need permissions to
execute the server command. Perhaps someone else can find a solution or maybe that link will solve it. Good luck!

OK, took some time, but now I know a little more.
It is a permission issue.
When I exec() quser or query user or query session there is no output.
But when I exec
[php]quser 2>&1[/php]
I get the message

No User exists for * No User exists for *

Your hint with users.exe has also no permissions for the servers, even not for localhost.

Well, it appears that from what I read for you that you either must be logged into TS as an ADMIN or at least, your user account needs permission to access the user list. Here is a site that talks about TS and Query User… It mentions that you can set the permissions for a user thru the TS this this list of tabs:
Terminal Services Configuration | Connections | Properties | Permissions | Advanced | Permissions
( http://ss64.com/nt/query-user.html )

Another possible way to handle this is to have a CRON job run on the server every few minutes that shells out to the query user command and saves the list in a file. Then, you could load the file and display it without needing any permissions…

This code was found using my buddy Google… It is supposed to display all RDS users connected. Might work!?!
$servers = get-content “C:\scripts\servers.txt”
foreach ($server in $servers)
{
$server
$command = “quser /server:” + $server
invoke-expression $command
}

Also, on this site, it shows you can list the users using a shell command (dosprompt command) which means you can do this inside a webpage by just shelling out to dos using a PHP shell funtion and have the result returned to a string and then you can use that sting to list the users which might also work for you! This site also talks about REMOTELY getting the list and also REMOTELY logging off a user. Might work for you…
http://www.systemroot.ca/2014/09/remotely-list-disconnect-users-windows/

See if you can get your permission level bumped up and let us know if it works for you… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service