When it is necessary to make an RDP connection to multiple terminals, I thought that it would be troublesome to manually connect by looking at the Excel list, so I tried to make RDP files collectively in Python. . !!
The input information and Python file are shown below.
Create the following two files.
Save it in your working directory as template.rdp, using "Computer Name" as "Computer Address", "User Name" as "UserName \ _for \ _RDP", and "Save As" as shown below. Put.
The RDP connection file (template.rdp) is as follows when opened with a text editor. It can be read that the password is not saved in the RDP file itself.
template.rdp
screen mode id:i:2
use multimon:i:1
desktopwidth:i:1920
desktopheight:i:1080
session bpp:i:32
winposstr:s:0,1,759,0,980,270
compression:i:1
keyboardhook:i:2
audiocapturemode:i:0
videoplaybackmode:i:1
connection type:i:7
networkautodetect:i:1
bandwidthautodetect:i:1
displayconnectionbar:i:1
enableworkspacereconnect:i:0
disable wallpaper:i:0
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1
full address:s:ComputerAddress
audiomode:i:0
redirectprinters:i:1
redirectcomports:i:0
redirectsmartcards:i:1
redirectclipboard:i:1
redirectposdevices:i:0
autoreconnection enabled:i:1
authentication level:i:2
prompt for credentials:i:0
negotiate security layer:i:1
remoteapplicationmode:i:0
alternate shell:s:
shell working directory:s:
gatewayhostname:s:
gatewayusagemethod:i:4
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:0
promptcredentialonce:i:0
gatewaybrokeringtype:i:0
use redirection server name:i:0
rdgiskdcproxy:i:0
kdcproxyname:s:
drivestoredirect:s:
camerastoredirect:s:*
devicestoredirect:s:*
username:s:UserName_for_RDP
RDP_File_Generator.py
# -*- coding: utf-8 -*-
"""
RDP file creation PGM
"""
import tkinter, tkinter.filedialog, sys, os
import pandas as pd
dir1 = r"C:\Users\XXXXX\Desktop\xxxxxx"
#↑ Specify the file path that stores the "RDP connection destination list" and "RDP template"
##The rule of tkinter.
root = tkinter.Tk()
root.withdraw()
msg1 = 'Please select a destination list'
typ1 = [('Excel file','*.xlsx')]
inFile1 = tkinter.filedialog.askopenfilename(title=msg1, filetypes = typ1, initialdir = dir1)
if (not inFile1): #[Cancel]Processing at the time of clicking
print('Please select a file.')
sys.exit
input_book1 = pd.ExcelFile(inFile1)
input_sheet_name1 = input_book1.sheet_names
input_sheet_df1 = input_book1.parse(input_sheet_name1[0],header=3)
df_s = input_sheet_df1.iloc[:,2:]
msg2 = 'Please select an RDP file'
typ2 = [('RDP file','*.rdp')]
inFile2 = tkinter.filedialog.askopenfilename(title=msg2, filetypes = typ2, initialdir = dir1)
if (not inFile1): #[Cancel]Processing at the time of clicking
print('Please select a file.')
sys.exit
path_name = os.path.dirname(inFile2)
output_folder_path = os.path.join(path_name,"output")
##Create RDP file output destination folder (exist)_ok:Skip if existing)
os.makedirs(output_folder_path,exist_ok = True)
##Open the RDP template file as a text file
with open(inFile2,encoding='utf_16') as f:
s = f.read()
##Generate as many RDP files as there are destinations in the destination list
for i in range(len(df_s)):
temp = s
temp = temp.replace("UserName_for_RDP", df_s["User ID"].iat[i])
temp = temp.replace("ComputerAddress", df_s["IP address"].iat[i])
path_w = os.path.join(output_folder_path,df_s["User ID"].iat[i]+".rdp")
with open(path_w,mode="w") as f:
f.write(temp)
Below is the execution image.
First, when you execute "RDP_File_Generator.py", a dialog by tkinter will be displayed, so select the connection destination list.
Then select a template for your RDP file.
An output folder is created, and RDP files are output in a batch in that folder! It's a success! !!
Since the password is not embedded in the RDP file, there is still the trouble of entering the password and saving the credentials on the connection source PC at the first connection, but I think it is convenient, so please refer to it if you like. I would be happy if you could!
Recommended Posts