Automating Remote Desktop Logon for multiple servers

Post your working scripts, libraries and tools for AHK v1.1 and older
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

Automating Remote Desktop Logon for multiple servers

01 Oct 2018, 09:42

I've been trying to automate the following, and have got it working, but as an AutoHotkey beginner, I think that my solution is not optimal (things like sleeping for a while instead of using functions that can properly wait for the window to be active etc?) and was hoping that some people could give me some advice on how to improve this.

In particular, I am really hoping to get advice on a way to a) select each RDP window that I open, and then b) resize and position that window to a particular location on the screen. Does anyone have a recipe for achieving that (very generally useful to me to be able to pick a window a resize as required!)?

Code: Select all

/*
Remote Desktop Logon
Logon to Remote Desktop and size the windows correctly for a split screen setup
Note that in a dual screen display can have a Start Bar or no Start Bar.

These settings are for a screen with resolution of 1920x1200, and no Start Bar.
Easy to adjust for other resolutions.
height := 1126  ; perfect height if have a Start Bar on this display for the RDP session
height := 1176  ; perfect height for Start Bar and maximise to left of screen
*/

servername := "server1.mydomain.net"
username   := "mydomain\myusername"
password   := "mypassword"
width  := 952   ; halfway for a 1920 wide display, 957 if can find a way to maximise to left/right
height := 1168  ; correct height to account for window borders, use 1126 / 1176 if Start Bar present

; MsgBox, ,RDP Details, %servername%`n%username%`n%password%`n%width% %height%, 2
Run, mstsc /console /v:%servername% /w:%width% /h:%height%
Sleep, 6000
WinActivate, Windows Security
Send, %password%
Send, {ENTER}

servername := "server2.mydomain.net"
username   := "mydomain\myusername"
password   := "mypassword"
width  := 952   ; halfway for a 1920 wide display
height := 1168

; MsgBox, ,RDP Details, %servername%`n%username%`n%password%`n%width% %height%, 2
Run, mstsc /console /v:%servername% /w:%width% /h:%height%
Sleep, 6000
WinActivate, Windows Security
Send, %password%
Send, {ENTER}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 57 guests