Batch file to automatically reconnect RDP session

{the long part of the story}

I have been experimenting with VDI type stuff at work, and recently, I turned my work PC into a XenServer, using version 6.  It’s mostly just a test, but it was kind of necessary because the PCs I ordered which utilize the image I’ve put on my FOG Server are backordered, and I needed a PC A.S.A.P (according to the people nagging me about it). Additionally, my servers are getting MAXXED on resources.  So due to my limited resources here at the office, I decided to repurpose one of the old Dell Optiplex 170L’s that only have 512MB of ram, and use it as a thin client.

After getting a Windows 7 guest running and configured to accept RDP connections, I found I was in need of a way to automatically reconnect a Remote Desktop Connection if either a user logs off, or lost connection, etc..  Because I didn’t want the user to have to enter credentials twice, I configured the system to login automatically locally, and changed the shell from explorer.exe to a batch file:

  • Step 1 – Create an RDP file (not going into details)
    • load mstsc.exe, configure it as required (I entered hostname, disabled the connection bar, full screen) , and save it somewhere.
  • Step 2 – Configure automatic logins
    • in registry, HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon
      • Make sure the following String Values are set:
        • DefaultUserName = [local-username]
        • DefaultPassword = [local-password]
        • DefaultDomain = [local-computername]
        • AutoAdminLogon = 1
  • Step 3 – Create the batch file below (see below)
  • Step 4 – Set shell to the batch file:
    • in registry, HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon
      • set shell string value to: c:\your-bat-file.bat


{the batch file}

the batch file, which I saved to c:\connect.bat simply consists of:

echo off
start /wait c:\windows\system32\mstsc.exe c:\connect.rdp
goto start

Did you like this? Share it:
This entry was posted in Tips and tricks and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *