How can I automatically launch a terminal services session when the server boots?

Posted on 2009-05-13
Medium Priority
Last Modified: 2012-05-06
I have a Server running 2003 Server Standard.  It functions primarily as a terminal server, but also runs a background application that needs to be started at system startup and remain running indefinitely.  The background app runs on it's own account in a ts session that is usually disconnected, though I do need to be able to connect to it now and again.
I've tried a number of methods without success:
1. Start the background app using the windows task scheduler.  (This runs the app, but not in a session that I can connect to.)
2. Start an mstsc session using the windows task scheduler.  (After it boots, I can see the mstsc.exe in task manager processes, but the account does not logon on successfully.  Terminal Services Manager shows no sessions other than the console.)
3. Use autoadminlogon to automatically log on an account with a logon script that launches the mstsc session, then logs itself off, leaving the mstsc session active but disconnected.  (This works, except that the defaultusername setting changes as different people log on to the console session, causing the autoadminlogon to fail.)  Strangely the same script that works here does not work if launched by task scheduler.
Any help would be greatly appreciated.
Question by:3mCanada
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 51

Assisted Solution

Netman66 earned 960 total points
ID: 24391112
You should be able to do this like so:

1)  From the Run box, type in mstsc - then ENTER
2)  Click the Options arrow (lower left).
3) Setup the connection with username and password
4) Check the box for Allow me to Save credentials.
5) From the first tab, Save As - save it somewhere you can find it.
6) You can create a batch file using the following syntax:

mstsc.exe Connection.rdp

Where Connection.rdp is the full path to the RDP file you saved above.

7)  Save the .cmd file above to the Administrator's startup folder.  As long as the Administrator logs in this will run.  You may need to configure Autologon and include a way to lock the console afterwards (easy enough).  Do not do this on a DC because the builtin Administrator is also Domain Admin and Enterprise Admin.  You'd rather run this from a member server.

This should launch the TS client using the RDP file for input.

Let us know how you make out.

Author Comment

ID: 24398499
Thank you Hetman66.

This is similar to my #3 attempt, other than firing the cmd file from the startup folder rather than as a logon script.  The problem that arises is that it ties up the console session.  (This server is on an isolated network, so the only outside world connection is the KVM, which of course connects to the console session.  Different people with  different security priviledges need remote access to the server, so I can't tie up that console session.)  I tried putting a logoff in the cmd file, but that just creates an endless loop of logging the console session on and off.  Also, when different people log on to the console session, the defaultusername changes, which of course interferes with AutoAdminLogon.
LVL 51

Expert Comment

ID: 24398994
Not sure I follow your logic.

If you're using RDP (mstsc) to the server then the KVM has nothing to do with that.  The only way you'd be on the console is if you're using the -console switch when launching mstsc.

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.


Author Comment

ID: 24399403
Sorry, I'll try to explain better...
Within the building, we're using RDP.  For security reasons, the LAN on which this server resides is isolated.  That is, there is no physical network connection to our office lan, or the internet, or any other external network.  However, we do occasionally need to perform tasks remotely, for which we have a KVM that sits on our regular office lan, allowing limited external access.
The problem is that AutoAdminLogon logs on as the console session, so it is not possible  to connect via the KVM with any credentials other than those of the AutoAdminLogon account.  (Both administrators and non-administrators need occasional KVM access.)
I hope this clarifies my dilemma.
LVL 51

Expert Comment

ID: 24400412
What if you were to hook the KVM to an XP workstation on the same segment then logon to it?

From that box, RDP to the server with whatever credentials you need.

Accepted Solution

3mCanada earned 0 total points
ID: 24434328
That would work, though I'd have to dedicate a machine to it, as all the existing ones are used as process controllers and have logon restrictions.

In any case, I figured out the problem and a work-around.  It appears that if mstsc is launched too soon after booting, the connection attempt is rejected, which is why my attempt to launch mstsc from task scheduler was failing.  (Even launching it from the startup folder of the autoadminlogon account was only intermittently successful.)

I now have task scheduler launching a .cmd file with a 60s delay (ping localhost -n60) prior to the mstsc call, and that seems to work.  If I reduce the delay to around 10s it starts failing again.
LVL 51

Expert Comment

ID: 24435772
Okay, thanks for the update.

Glad you got it sorted.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The HP utility "HP Lights-Out Online Configuration Utility for Windows Server 2003/2008" could be of great use when it comes to remotely configure a HP servers ILO WITHOUT rebooting the server. We would only need to create and run scripts using thi…
Learn about cloud computing and its benefits for small business owners.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question