8

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.

4
  • 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
    Jan 6, 2013 at 1:50
  • 1
    @Karan I originally thought so too, but I think this could be of use to any windows power user.
    – chollida
    Jan 6, 2013 at 2:40
  • 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") Jan 6, 2013 at 3:06
  • 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) Jan 6, 2013 at 3:10

4 Answers 4

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
1
  • 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
    Apr 28, 2014 at 19:51
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.

1

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

2
  • 2
    that depends on the setup man ...
    – WeloSefer
    Jan 6, 2013 at 3:05
  • 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
    Jan 6, 2013 at 6:44
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .