|
|
|
@ -19,40 +19,22 @@ import subprocess
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
def SessionConnect(inRDPSessionConfiguration):
|
|
|
|
|
#Run mstsc
|
|
|
|
|
from pywinauto.application import Application
|
|
|
|
|
lRDPApplication = Application(backend="uia").start("mstsc.exe")
|
|
|
|
|
lProcessId = lRDPApplication.process
|
|
|
|
|
#Expand the parameter section
|
|
|
|
|
UIDesktop.UIOSelector_Get_UIO(
|
|
|
|
|
[
|
|
|
|
|
{"process": lProcessId, "backend": "uia"},
|
|
|
|
|
{"class_name": "ToolbarWindow32"},
|
|
|
|
|
{"title": "Показать параметры ", "control_type": "Button"}]
|
|
|
|
|
).click()
|
|
|
|
|
#Select flag ask login/pass
|
|
|
|
|
UIDesktop.UIOSelector_Get_UIO(
|
|
|
|
|
[
|
|
|
|
|
{"process": lProcessId, "backend": "win32"},
|
|
|
|
|
{"title":"Общие"},
|
|
|
|
|
{"title":"Учетные данные"},
|
|
|
|
|
{"title":"&Всегда запрашивать учетные данные", "class_name":"Button"}]
|
|
|
|
|
).check()
|
|
|
|
|
#Set host:port
|
|
|
|
|
lHostPort=inRDPSessionConfiguration['Host']
|
|
|
|
|
if 'Port' in inRDPSessionConfiguration:
|
|
|
|
|
lHostPort=f"{lHostPort}:{inRDPSessionConfiguration['Port']}"
|
|
|
|
|
UIDesktop.UIOSelector_Get_UIO(
|
|
|
|
|
[
|
|
|
|
|
{"process": lProcessId, "backend": "uia"},
|
|
|
|
|
{"title": "Компьютер:"},
|
|
|
|
|
{"title": "Компьютер:", "control_type": "Edit"}]
|
|
|
|
|
).set_text(f"{lHostPort}")
|
|
|
|
|
#Set user
|
|
|
|
|
return
|
|
|
|
|
def Session(inRDPSessionConfiguration):
|
|
|
|
|
#RDPConnector.SessionConnect(mConfiguration)
|
|
|
|
|
#RDPConnector.LoginPassSet("111.222.222.111","ww","dd")
|
|
|
|
|
(lRDPFile, lSessionHex) = SessionConfigurationCreate(inRDPSessionConfiguration)
|
|
|
|
|
#Set session hex in globalDict
|
|
|
|
|
inRDPSessionConfiguration["SessionHex"] = lSessionHex
|
|
|
|
|
#Set login/password
|
|
|
|
|
SessionLoginPasswordSet(inRDPSessionConfiguration["Host"],inRDPSessionConfiguration["Login"],inRDPSessionConfiguration["Password"])
|
|
|
|
|
#Start session
|
|
|
|
|
SessionRDPStart(lRDPFile)
|
|
|
|
|
#Remove temp file
|
|
|
|
|
time.sleep(4) #Delete file after some delay - one way to delete and run the RDP before because RDP is not read file in one moment
|
|
|
|
|
os.remove(lRDPFile) # delete the temp rdp
|
|
|
|
|
return inRDPSessionConfiguration
|
|
|
|
|
#Add login/ password to the windows credentials to run RDP
|
|
|
|
|
def LoginPassSet(inHost,inLogin,inPassword):
|
|
|
|
|
def SessionLoginPasswordSet(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
|
|
|
|
@ -60,7 +42,7 @@ def LoginPassSet(inHost,inLogin,inPassword):
|
|
|
|
|
return None
|
|
|
|
|
#Create current .rdp file with settings
|
|
|
|
|
#Return (full path to file, session hex)
|
|
|
|
|
def RDPConfigurationCreate(inConfiguration):
|
|
|
|
|
def SessionConfigurationCreate(inConfiguration):
|
|
|
|
|
#RobotRDPActive folder path
|
|
|
|
|
lFileFullPath=__file__
|
|
|
|
|
lFileFullPath = lFileFullPath.replace("/","\\")
|
|
|
|
@ -72,10 +54,11 @@ def RDPConfigurationCreate(inConfiguration):
|
|
|
|
|
#Prepare host:port
|
|
|
|
|
lHostPort=inConfiguration['Host']
|
|
|
|
|
if 'Port' in inConfiguration:
|
|
|
|
|
lHostPort=f"{lHostPort}:{inConfiguration['Port']}"
|
|
|
|
|
if inConfiguration['Port']:
|
|
|
|
|
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("{Width}", inConfiguration.get('Screen',{}).get("Width",1680))
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{Height}", inConfiguration.get('Screen',{}).get("Height",1050))
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{BitDepth}", inConfiguration.get('Screen',{}).get("DepthBit","32"))
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{HostPort}", lHostPort)
|
|
|
|
|
lRDPTemplateFileContent = lRDPTemplateFileContent.replace("{Login}", inConfiguration['Login'])
|
|
|
|
@ -85,7 +68,7 @@ def RDPConfigurationCreate(inConfiguration):
|
|
|
|
|
#Return .rdp full path
|
|
|
|
|
return (lRDPCurrentFileFullPath, (lRDPCurrentFileFullPath.split("\\")[-1])[0:-4])
|
|
|
|
|
#RDPSessionStart
|
|
|
|
|
def RDPSessionStart(inRDPFilePath):
|
|
|
|
|
def SessionRDPStart(inRDPFilePath):
|
|
|
|
|
#run rdp session
|
|
|
|
|
lItemArgs = [inRDPFilePath]
|
|
|
|
|
subprocess.Popen(lItemArgs, shell=True)
|
|
|
|
@ -116,18 +99,18 @@ def RDPSessionStart(inRDPFilePath):
|
|
|
|
|
60
|
|
|
|
|
)
|
|
|
|
|
#Prepare little window
|
|
|
|
|
SessionLittleScreen(lRDPFileName)
|
|
|
|
|
SessionScreen100x550(lRDPFileName)
|
|
|
|
|
return None
|
|
|
|
|
#Set fullscreen for app
|
|
|
|
|
def SessionFullScreen(inSessionHex):
|
|
|
|
|
def SessionScreenFull(inSessionHex):
|
|
|
|
|
#Prepare little window
|
|
|
|
|
lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{lRDPFileName} — .*", "backend": "win32"}])
|
|
|
|
|
lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{inSessionHex} — .*", "backend": "win32"}])
|
|
|
|
|
lRDPWindow.maximize()
|
|
|
|
|
return None
|
|
|
|
|
#Set Little window of the session
|
|
|
|
|
def SessionLittleScreen(inSessionHex):
|
|
|
|
|
def SessionScreen100x550(inSessionHex):
|
|
|
|
|
#Prepare little window
|
|
|
|
|
lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{lRDPFileName} — .*", "backend": "win32"}])
|
|
|
|
|
lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{inSessionHex} — .*", "backend": "win32"}])
|
|
|
|
|
lRDPWindow.restore()
|
|
|
|
|
lRDPWindow.move_window(10,10,550,100)
|
|
|
|
|
return None
|