Running batch file on Remote Desktop login fails

batch-fileremote desktop

As just extra protection, I am wanting to backup remote sql db to my location nightly. There is no VPN so…

I created a user on the 2008 db server for the sole purpose to log on from my office and download the db bak file nightly. Gave this user read permission on the backup directory (T:\Backup) and added to the remote users group.

I created a Automated task on my workstation that calls a rdp file that successfully connects to the db server as this user.

The rdp file specifies in the "Start a program" tab the following path:
C:\Windows\System32\mstsc.exe T:\Backup\copydb.bat

I have tested both parts:
1) Double-clicking the rdp file will login automatically. (WORKS)
2) I can then manualy open the dos prompt and run the bat file. (WORKS)

However, the bat file does not seem to execute on connection . There is no cmd window. I can douple-click on the bat file and the cmd window will flash and go away but does not execute. The only way I've been able to get it to execute is to open the prompt and then the file.

I thought that's what this would do:
C:\Windows\System32\mstsc.exe T:\Backup\copydb.bat

What am I missing?

Best Answer

This might be your problem.

Refer to this MS support article You cannot create a terminal server session to a Windows Server 2008-based computer by using an .rdp file that runs an initial program

To work around this problem, add the program path to the RemoteApp Programs list. To do this, follow these steps:

  1. Click Start, click Run, type remoteprograms.msc, and then click OK.

  2. In the actions pane, click Add RemoteApp Programs, and then click Next.

  3. Click Browse, locate the program that you want to approve, click Next, and then click Finish.