Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts



Detect remote desktop sessions from a batch file

Post image for Detect remote desktop sessions from a batch file

by Steve Wiseman on May 10, 2012 · 7 comments

in Terminal Services,Tips,Tools,Utility


Ryan asked this week:

“I have a scenario where an application starts when a particular user (generic admin account) logs on to the console. The problem is that when the same user account is also used to login to an RDP session, on the same server, the service tries to start again, and breaks…Is it possible for a logon script to recognize that it is logging on to the console? If so I could start the application from this script and not worry about it starting a second time if someone accidentally RDPs using the same account.”

RDP Session View

I originally thought that this could be easily detected by an environment variable, or even VB Script…but it turns out that those two methods are not reliable.

The %SESSIONNAME% variable is set if you are on a terminal server. If you just RDP to the console of a workstation, or server – it is empty.

So instead, we put together a free utility called RDPDetect. It returns 1 if you are in an RDP session, and 0 if you are not. The return value can be picked up as an error level, so you can use it in a bat file like this:

@echo off
goto END
echo This is a RDP Session
goto end
echo This is a not a RDP Session

You can find it in our download section:

IntelliAdmin Download Page

As always, it contains no spyware or adware…only freeware goodness.

It is free for commercial and personal use.

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 7 comments… read them below or add one }

1 Dave Smathers May 10, 2012 at 10:25 am

Excellent utility steve. I happen to have the same issue here. I work at a bank that uses software that needs to run at logon to process items through the day. Once in a while someone forgets that they can’t RDP into this system, since it has that same logon script! Then bam, the batch processing crashes and an hour later we get angry calls. With your little tool I can stop this madness once and for all.

2 Mike May 10, 2012 at 11:07 am

I get an error with Windows 2000. Is it supposed to work with it?

3 Steve Wiseman May 10, 2012 at 11:08 am

No, it won’t work with 2000. This is because it is lacking certain terminal service API calls.

I think it is really rare to see a 2000 TS these days 🙂

4 Mike May 10, 2012 at 11:09 am

Yea, it is an old machine. It is a cisco 4.x call manager server. Not a TS. But since it is 2000 server, it has RDP built in.

5 Jennifer May 10, 2012 at 5:34 pm

Great utility steve. I have run into this issue before. Thanks!

6 Muno May 11, 2012 at 9:42 am

Thanks for the free tool steve. Have a ctrix env here and this is a great little utility!

7 Naveen January 10, 2013 at 7:09 pm

Hi Steve,

I need a tool that specifies that system info like boot time,free disk space, server name on RDP Session background without logging into server.

Please Can you do that for me?

Thanks in Advance


Leave a Comment

Category Links - Windows Forum - Exchange Forum