0

How to create a batch file to connect to Remote desktop and launch Microsoft Sql server and run some scripts. I tried creating a batch file to connect to using

@ECHO OFF
mstsc /v:"SERVERNAME"

But i was not able to pass username and password Can anyone advise on this.

EDIT

 psexec \\remotemachine-u username -p password ipconfig

Above one connects me to the remote machine and prints its Ip details.

Now I am trying to execute SQL script which is in D:\ of remote machine to execute in Microsoft SQL server (connection) in the remote machine. Is that possible.

useranon
  • 29,318
  • 31
  • 98
  • 146

1 Answers1

0

You can use MSTSC to create the connection, with credentials (be sure to check the box that says "Allow me to Save Credentials"), then save that information to an .RDP file

After you should be able to launch:

mstsc "MyConnectionFile.rdp"

In the connection configuration, there is also a tab: "Programs / Start the following programs on connection", which should get your scripts going.

In general, the issue is to set up everything via the GUI, save it to an RDP file, and use that file in the future.

abelenky
  • 63,815
  • 23
  • 109
  • 159