Is there a way to determine if a user logged in via remote desktop

6

2

I'd like to determine if the currently logged in user is logged in by physically being at the computer of if they logged in via remote desktop.

I'm fine with limiting this to windows 7 if that helps.

I'm also fine with answers that determine this programatically or manually, though I would ultimatly prefer a programmatic answer.

chollida

Posted 2013-01-06T01:47:21.757

Reputation: 297

2"I would ultimatly prefer a programmatic answer" - Then you're in the wrong place and StackOverflow would be better suited to requests for code. – Karan – 2013-01-06T01:50:03.767

1@Karan I originally thought so too, but I think this could be of use to any windows power user. – chollida – 2013-01-06T02:40:47.920

One you have this information what are you doing with it, it affects what you can do as a solution (if the question is *"I want to know if the computer I just walked up to is in a terminal session"* the answer could be as simple as *"Move your mouse to the top middle of the screen and a bar to close the remote desktop session shows up"*) – Scott Chamberlain – 2013-01-06T03:06:21.193

Also as is your question would be closed on SO for being overly broad and vauge. Are you wanting to check your user? Are you wanting to see if users on a server are connected via the console or via RDP? Is the app being run on a computer with Wtsapi32.dll (only server editions have it) – Scott Chamberlain – 2013-01-06T03:10:52.027

Answers

2

The following solution works if you have cygwin installed. Running this script gives you output 'console' if you are running on a console, and 'rdp' if you are running in an rdp session:

#!/bin/bash
# returns 'rdp' or 'console'
current_session_line=`query session | grep '^>' $t | sed -e 's/>//'`
current_session_type=`echo $current_session_line|sed -e 's/[- ].*//'`

echo $current_session_type

user319027

Posted 2013-01-06T01:47:21.757

Reputation: 36

Hm, my solution assumes the windows executable query.exe is on your path. On one of my win7 boxes query.exe is available in c:\windows\system32, but on another it is nowhere to be found. Not sure what windows component brings query.exe in. – user319027 – 2014-04-28T19:51:52.457

5

You can determine whether the user is logged in locally or remotely via Users tab in Task Manager.

Client Name JAN-PC shows where the connection originates from

enter image description here

You can also use CLI to view current RDP sessions which can be run with no problems against remote machines.

C:\>query session /?

An example of query session output>>

enter image description here

Comprehensive info on managing remote desktop services from CLI.

Volodymyr M.

Posted 2013-01-06T01:47:21.757

Reputation: 1 428

1

When you login via Remote Desktop the current loggedin user is Switched Out.

CSᵠ

Posted 2013-01-06T01:47:21.757

Reputation: 231

2that depends on the setup man ... – WeloSefer – 2013-01-06T03:05:43.217

If multi user remote desktop is setup then you won't get kicked. On a standard consumer PC setup you will be kicked to the lock screen and says "Login in from RANDOM-PC". – Sam – 2013-01-06T06:44:08.220

1

For Windows 2000 and higher, you can view in the Task Manager. You can press Ctrl+Shift+Escape to bring it up, then click the Users tab. If you see 'Console' listed, they are logged in to the physical machine. If they show as Disconnected, they are no longer actively on the system. If it shows something such as RDP-001 or a computer name, they are logged in via remote desktop

Canadian Luke

Posted 2013-01-06T01:47:21.757

Reputation: 22 162