|
|
@ -1,6 +1,8 @@
|
|
|
|
#Import parent folder to import current / other packages
|
|
|
|
#Import parent folder to import current / other packages
|
|
|
|
from pyOpenRPA.Robot import UIDesktop #Lib to access RDP window
|
|
|
|
from pyOpenRPA.Robot import UIDesktop #Lib to access RDP window
|
|
|
|
import os #os for process run
|
|
|
|
import os #os for process run
|
|
|
|
|
|
|
|
import uuid #temp id for Template.rdp
|
|
|
|
|
|
|
|
import tempfile #Temporary location
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
#Connect to RDP session
|
|
|
|
#Connect to RDP session
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -47,4 +49,37 @@ def SessionConnect(inRDPSessionConfiguration):
|
|
|
|
{"title": "Компьютер:", "control_type": "Edit"}]
|
|
|
|
{"title": "Компьютер:", "control_type": "Edit"}]
|
|
|
|
).set_text(f"{lHostPort}")
|
|
|
|
).set_text(f"{lHostPort}")
|
|
|
|
#Set user
|
|
|
|
#Set user
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
#Add login/ password to the windows credentials to run RDP
|
|
|
|
|
|
|
|
def LoginPassSet(inHost,inLogin,inPassword):
|
|
|
|
|
|
|
|
#Clear old login/password if it exists
|
|
|
|
|
|
|
|
#os.system(f"cmdkey /delete:TERMSRV/{inHost}") #Dont need to delete because new user password will clear the previous creds
|
|
|
|
|
|
|
|
#Set login password for host
|
|
|
|
|
|
|
|
os.system(f"cmdkey /generic:TERMSRV/{inHost} /user:{inLogin} /pass:{inPassword}")
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
#Create current .rdp file with settings
|
|
|
|
|
|
|
|
#Return full path to file
|
|
|
|
|
|
|
|
def RDPConfigurationCreate(inConfiguration):
|
|
|
|
|
|
|
|
#RobotRDPActive folder path
|
|
|
|
|
|
|
|
lFileFullPath=__file__
|
|
|
|
|
|
|
|
lFileFullPath = lFileFullPath.replace("/","\\")
|
|
|
|
|
|
|
|
lRobotRDPActiveFolderPath = "\\".join(lFileFullPath.split("\\")[:-1])
|
|
|
|
|
|
|
|
#Full path to Template.rdp file
|
|
|
|
|
|
|
|
lRDPTemplateFileFullPath = os.path.join(lRobotRDPActiveFolderPath, "Template.rdp")
|
|
|
|
|
|
|
|
#Open template file (.rdp encoding is USC-2 LE BOM = UTF-16 LE) http://qaru.site/questions/7156020/python-writing-a-ucs-2-little-endian-utf-16-le-file-with-bom
|
|
|
|
|
|
|
|
lRDPTemplateFileContent = open(lRDPTemplateFileFullPath, "r", encoding="utf-16-le").read()
|
|
|
|
|
|
|
|
#Prepare host:port
|
|
|
|
|
|
|
|
lHostPort=inConfiguration['Host']
|
|
|
|
|
|
|
|
if 'Port' in inConfiguration:
|
|
|
|
|
|
|
|
lHostPort=f"{lHostPort}:{inConfiguration['Port']}"
|
|
|
|
|
|
|
|
#Replace {Width}, {Height}, {BitDepth}, {HostPort}, {Login}
|
|
|
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{Width}", str(1680))
|
|
|
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{Height}", str(1050))
|
|
|
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{BitDepth}", inConfiguration.get('Screen',{}).get("DepthBit","32"))
|
|
|
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{HostPort}", lHostPort)
|
|
|
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{Login}", inConfiguration['Login'])
|
|
|
|
|
|
|
|
#Save template to temp file
|
|
|
|
|
|
|
|
lRDPCurrentFileFullPath = os.path.join(tempfile.gettempdir(), f"{uuid.uuid4().hex}.rdp")
|
|
|
|
|
|
|
|
open(lRDPCurrentFileFullPath, "w", encoding="utf-16-le").write(lRDPTemplateFileContent)
|
|
|
|
|
|
|
|
#Return .rdp full path
|
|
|
|
|
|
|
|
return lRDPCurrentFileFullPath
|