Computer Hope

Microsoft => Microsoft DOS => Topic started by: Arrakis on November 08, 2012, 03:42:38 AM

Title: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 03:42:38 AM
Hi, I am a complete novice with zero experience.

I have daily tasks at work which require me to RDP to servers to check logs etc and was hoping I could create a batch file to launch on startup to save myself a bit of time.

Any help would be greatly appreciated.

So far all I have done is copy scripts I have found online but I'm struggling to find something suitable for my needs in this instance.  I have read some of the threads in this forum on similar requests but am baffled :/


Thanks

Adrian
Title: Re: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 03:46:02 AM
So far I have got this far..

start /d "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories" mstsc.exe

I'm such a n00b its almost embarrassing  :-\
Title: Re: Creating a batch file to run RDP and connect
Post by: foxidrive on November 08, 2012, 03:47:36 AM
I don't RDP anywhere - what did you want to automate?

What procedure do you use to RDP?
Title: Re: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 03:55:17 AM
Hi, did I not reply to your question above?

Ideally I want to automate logon to an exchange server and run services.msc or test-servicehealth.  This check is one of my daily checks.
Title: Re: Creating a batch file to run RDP and connect
Post by: foxidrive on November 08, 2012, 04:00:39 AM
http://windows.microsoft.com/en-AU/windows-vista/Use-command-line-parameters-with-Remote-Desktop-Connection

You can automate the connection here.

You might like to use PSEXEC to connect remotely and execute programs and get info, but not if you need GUI access.
Title: Re: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 04:19:51 AM
Not really sure what I need to add to make this work, there are no examples :/ I get further with what I've written already.  I need to automate the launch - connection - fill password field - connect.

I dont know if this is even possible.

Thanks for the link though.
Title: Re: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 04:37:24 AM
After further investigation I think a batch file maybe inappropriate for my needs, thoughts?
Title: Re: Creating a batch file to run RDP and connect
Post by: foxidrive on November 08, 2012, 04:51:37 AM
The link shows that you need a connection file, and that will allow you to connect to the remote server with few keystrokes.

You create/edit the connection file and write the batch file, call it R.BAT and put it in c:\Windows
Then press Windows + R, type R and press enter.  You should be connected.

The way I read it the link shows that with a connection file all you need is this:

Code: [Select]
@echo off
mstsc "%userprofile%\desktop\server1.rdp"


where you create the server1.rdp on your desktop.  You may be able to just double click the RDP file if the associations work.
Title: Re: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 07:35:07 AM
Well ive stumbled accross this online,

mstsc /v: "IPADDRESSHERE" /w:640 /h:480

Which gets me as far as putting my password in, any ideas for another line to add password and hit ok a few times?
Title: Re: Creating a batch file to run RDP and connect
Post by: Arrakis on November 08, 2012, 08:15:38 AM
Right I just need a command to fill the password field then im there.  Anyone help out?
Title: Re: Creating a batch file to run RDP and connect
Post by: gpl on November 08, 2012, 10:56:05 AM
Even if you do get your script working, you will save yourself a huge amount of effort using this if you keep having to log into different (windows) servers - the Remote Desktop Connection Manager
http://www.microsoft.com/en-us/download/details.aspx?id=21101 (http://www.microsoft.com/en-us/download/details.aspx?id=21101)
Title: Re: Creating a batch file to run RDP and connect
Post by: Cybertek on February 22, 2014, 07:15:49 AM
PowerShell can create that script. Will create a temp connection to the target machine.
set-location \\targetmachine\c$
Title: Re: Creating a batch file to run RDP and connect
Post by: clerkdon on August 21, 2014, 06:58:54 AM
Did you try dropping down to "cmd" and typing "mstsc /?"  This will give you all of the commands that remote desktop will use/require.
I use batch files in the same way you do with a choice command to go through the remote servers
Title: Re: Creating a batch file to run RDP and connect
Post by: nickzoolander on February 07, 2017, 08:19:01 AM
SOLUTION:
Best way to go about this is open mstsc enter all your connection details then click save as, save to the desktop and your done.  :)

However if you wish to run mstsc as an administrator or for any other elevated commands create a notepad and enter:   mstsc /v:rdp.mycompany.com /console /admin
save as RDP.bat
Title: Re: Creating a batch file to run RDP and connect
Post by: patio on February 07, 2017, 08:23:48 AM
They left 1 1/2 Years ago...