How to Automatically MSTSC or RDP into Windows Server without entering Password again & again

Like always will come directly to point:

Disclaimer:
This saves password in clear text in batch file so think before using it on a shared system.If this doesn't bothers you and its really necessary as your connection is too fluctuating go ahead and read below how you can do it.

This is a 2 part process :
  1. Create batch file with all the commands given below and save it as NameOfBatchScript.bat this name is used in VBScript so make sure you replace it accordingly.
  2. Create a VBScript file with commands  given below to load the batch file we created in above step without showing the mstsc yes no prompts, save this file with any name you like(May be your Jump Server Name is best Choice for its name in case you have multiple due to multiple clients) but make sure to save it with extension  as .VBS
Note: Replace the DomainName, Username & Password accordingly also IP with Server name\IP of server you are trying to connect if in same domain or with its FQDN if not in below scripts in SET parameters.

Thing to note: If you have passwords with special characters like % & " make sure to escape them like % in your password should be replaced with %% , & should be replaced with ^& as otherwise cmd skips them considering them as special characters and you will receive password incorrect error, to make sure your password is correctly set try printing it on cmd by adding echo %PASSWORD% right after SET PASSWORD line in batch script for test and then remove it if its all good.

Batch file content:

@echo off
SET IP=172.X.Y.XY
SET USERNAME=DOMAIN_NAME_REPLACE\USERNAME_REPLACE
SET PASSWORD=PASSWORD_REPLACE
cmd /c cmdkey /add:TERMSRV/%IP% /user:%USERNAME% /pass:%PASSWORD%
cmd /c "cmdkey /generic:TERMSRV/%IP% /user:%USERNAME% /pass:%PASSWORD%"
cmd /c "mstsc /f /v:%IP%"
cmd /c "timeout /t 0 /nobreak"
cmd /c "cmdkey /delete:TERMSRV/%IP%"

VBScript content:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "NameOfBatchScript.bat" & Chr(34), 0
Set WshShell = Nothing

How to use:

  • Make sure you have both these files saved in the same folder. 
  • To use it just double click on the VBScript file and wait for Remote Session to Server to get loaded.

Comments

Popular posts from this blog

Enabling fixed Sidebar for blogger Contempo template for screen sizes smaller than 1440px

Adding Home Older Newer Post Buttons in new Blogger templates such as Contempo

Adding copy to clipboard button to every google code prettify pre blocks in blogger