Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a Windows XP Pro machine at work that several people connect to via VNC (RealVNC). Each user logs into Windows under their own account. We all want to be polite to the other users and only connect when nobody else is using the machine. If someone else is using it I want to find out who (ie. what Windows user is logged on) so I can ask them when they're likely to finish. The question is: how do I find this out?

What we currently do is first try to connect via RDP, so that it prompts us "User SmithJ is currently logged on. Do you want to log them off?" We answer "No", but now we know it's John Smith that's using it. This works, but it's a fair bit of extra hassle - you have to run Remote Desktop, select the machine, enter your password. Is there any way we can do this with VNC itself?

Of course, another way would be to send CtrlAlt-Del once connected via VNC, but that would be really annoying to the other person using it and I don't want to interrupt them like this.

Before someone asks, no, we cannot just use RDP - the session must appear to be the "interactive" session. However, if there are alternative products to VNC that can do this I'd be interested to hear about them.

share|improve this question

Following on from:

echo %USERNAME% > CurrentlyLoggedIn.txt

It looks like windows XP, and later, have an environment variable "SESSIONNAME", which is set to "Console" for the console login session.

I'm not sure what its set to for an RDP (remote desktop) session. If different, you can use that in the batch file as a means of qualifying if the magic file should be updated or not.

A little gotcha with this approach: You need a means of deleting that file on console logout as well.

share|improve this answer
Hmm, you could be on to something here! I'm not sure if this is enough to solve the problem, but +1. – EMP Oct 30 '10 at 23:11

Sounds like using psloggedon.exe from Sysinternals would be your best bet. Just run a simple batch file or something like that and it will tell you who is logged on the remote pc. If you have multiple users via RDP and Console try using net sessions \\computer and that will return all the RDP sessions on that remote computer.

share|improve this answer
Nice idea, but it shows me two users logged on "locally" and I don't know which of them is the interactive user and which has a remote desktop session. – EMP Jul 12 '10 at 4:36
Getting tired and I can't think of it, but use psexec to execute the command I can't remember (here is where the time of night kicks in) to find the logged in session numbers, that should do it for you. I'll try to check again in the morning and see if I remember the way to do this. – David Remy Jul 12 '10 at 5:00

you could telnet to the other machine or use psexec, and execute a command

Could execute a script that does netstat -aon on the server, and looks at the IP and. then has another file with IPs and usernames one per line. find the line with that IP and it displays the line showing the username.


Each Client, could use psexec to write a file on C:\ that says their name in it.

To find out who is using the computer, when it is in use, you can run a script that displays what is in that file.

share|improve this answer
Sorry, but I don't think either of those are good solutions. Windows already knows who is logged on and I just need to ask it somehow. – EMP Jul 12 '10 at 23:06
in that case, you want to remotely execute this on the machine, and you'll see who the user is. C:\>echo %USERPROFILE% <ENTER> then it will display something like C:\Documents and Settings\Charlie – barlop Jul 13 '10 at 14:03
Hmm.. my echo %userprofile% won't work, because psexec only logs on as whichever user it logs on as, which is either the same user that is currently on on the local machine, or the user/pass you specify to be used on the remote machine. – barlop Jul 13 '10 at 22:13
Trying to understand your question.."we cannot just use RDP - the session must appear to be the 'interactive' session." Would an "interactive session" be defined as connecting remotely not directly? How can you have session with RDP that doesn't appear to be interactive. Wouldn't VNC sessions and RDP sessions both be interactive and appear as such? – barlop Jul 13 '10 at 22:52
Also, with psloggedon, it gives times.. so if it shows two, then would perhaps the earlier time be the locally logged on session, and the interactive session be the later one? – barlop Jul 13 '10 at 23:01

This may sound a little ghetto but it would work: You can add a batch script to everyones startup folder that does something like this-

echo %USERNAME% > CurrentlyLoggedIn.txt

then share that file on the machine and just create a shortcut to it from your machine. That way, when someone logs in they would automatically update that file, and if you ever needed to know who was logged in you would just double click the shortcut on your desktop to see.

share|improve this answer
Yes, but that would run whether they are logged on locally or remotely, wouldn't it? – EMP Oct 27 '10 at 5:31

You must log in to answer this question.

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