Skip to content

Instantly share code, notes, and snippets.

Last active February 17, 2021 06:40
Show Gist options
  • Save flow4u/f286479e78a1146369cc6ea4399bb5ec to your computer and use it in GitHub Desktop.
Save flow4u/f286479e78a1146369cc6ea4399bb5ec to your computer and use it in GitHub Desktop.
.bat: MyDRE easy open session with 2 monitors (mutlimonitor is restricted to 2), also works with 1
:: This script for Windows make it easier to run RDP files on Windows
:: After downloading the RDP, run this script
:: It picks up the latest RDP-file from downloads, copies it to MyDRE.RDP
:: Adds a few lines to the RDP for magic (customize in the section: CUSTOM
:: Deletes the downloaded RDP file to prevent clutter in your Downloads
:: Runs the script
:: Par3: select the monintors to be used, make sure these monitors are adjecent
:: E.g.: 0,1 = Use Monitor 0 and 1
SET Par1=span monitors:i:1
SET Par2=use multimon:i:1
SET Par3=selectedmonitors:s:0,1
:: Finds the latest RDP-file in downloads and ends script if no RDP-file is present
SET Location=\Downloads\
SET SearchFor=*.rdp
SET SearchString="%UserProfile%%Location%%SearchFor%"
FOR /F "eol=| delims=" %%I IN ('DIR %SearchString% /A-D /B /O-D /TW 2^>nul') DO (
SET NewestFile=%%I
GOTO FoundFile
ECHO No *.rdp file found!
:: Skips adding lines to MyDRE.RDP if MyDRE.RDP is the latest RDP-file
:: Copies the latest RDP-file to MyDRE.RDP, removes the latest RDP-file
:: Adds multimonitor support the MyDRE.RDP
IF "%NewestFile%"==MyDRE.rdp GOTO OpenRDP
ECHO Newest *.rdp file is: %NewestFile%
SET Source="%UserProfile%%Location%%NewestFile%"
SET TargetFile=MyDRE.rdp
SET Target="%UserProfile%%Location%%TargetFile%
COPY %Source% %Target%
ECHO.>> %Target%
ECHO %Par1% >> %Target%
ECHO %Par2% >> %Target%
ECHO %Par3% >> %Target%
DEL %Source%
:: Opens MyDRE.RDP
start mstsc.exe %Target%
Copy link

flow4u commented Jan 27, 2021

How to use (assuming you put a shortcut on Windows Taskbar):

  1. Download the RDP file as usual
  2. Press MyDRE RDP icon on the Windows Taskbar
  3. Fill in your details, and if you have 2 or more monitors, monitor 0 and 1 (and only those) will be used for the VM
  • In the background the downloaded RDP file will be deleted (preventing cluttering your downloads)
  • It always takes the latest RDP file (either downloaded, or modified by the script)

You can download a nice icon: app.ico.

Alternatively, download the Extract it in c:\users\public\shortcuts and drag the MyDRE - Shortcut to Windows task bar and you're good to go.

Some organizations block zips with extensions, download this zip and read the instructions.

A small modification, already in the zip, of the shortcut was needed in order to be able to put it on the Windows Taskbar:
The shortcut has:

  • Target: C:\Windows\System32\cmd.exe /c "C:\Users\Public\Shortcuts\MyDRE.bat"

  • Start in: C:\Users\Public\Desktop

  • Change icon: %SystemDrive%\Users\Public\Shortcuts\app.ico

  • A Python version with the same functionality can be found here.

  • A .bat version with the same functionality can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment