diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py similarity index 72% rename from Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py rename to Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py index 9aa900ed..0282360d 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Connector.py @@ -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 diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py index 2942ae38..3d7f5b93 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py @@ -1,10 +1,17 @@ from pyOpenRPA.Robot import UIDesktop -#Check for session is closed +from . import Connector +import pdb +#Check for session is closed. Reopen if detected. Always keep session is active def Monitor(inGlobalDict, inListUpdateTimeout): - lUIOSelectorList=[] - for lItem in inGlobalDict["RDPList"]: - lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']} — .*", "backend": "win32"}]) while True: + # UIOSelector list init + lUIOSelectorList = [] + for lItem in inGlobalDict["RDPList"]: + lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']} — .*", "backend": "win32"}]) + #Run wait command lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout) for lItem in lRDPDissappearList: - #Session start \ No newline at end of file + #pdb.set_trace() + #Session start + Connector.Session(inGlobalDict["RDPList"][lItem]) + return None \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py index 66c12585..02deb771 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py @@ -9,7 +9,8 @@ def Settings(): "Login": "test", # Login "Password": "test", # Password "Screen": { - "Resolution": "FullScreen", + "Width": 1680, #Width of the remote desktop in pixels + "Height": 1050, #Height of the remote desktop in pixels # "640x480" or "1680x1050" or "FullScreen". If Resolution not exists set full screen "FlagUseAllMonitors": False, # True or False "DepthBit": "32" # "32" or "24" or "16" or "15" diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Template.rdp b/Sources/pyOpenRPA/Tools/RobotRDPActive/Template.rdp index 0213438e..10193862 100644 Binary files a/Sources/pyOpenRPA/Tools/RobotRDPActive/Template.rdp and b/Sources/pyOpenRPA/Tools/RobotRDPActive/Template.rdp differ diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py index 031ad081..a3d0fe99 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py @@ -1,3 +1,7 @@ +#Run example +#cd %~dp0..\..\Sources +#..\Resources\WPy64-3720\python-3.7.2.amd64\python.exe -m pyOpenRPA.Tools.RobotRDPActive "C:\Abs\Archive\scopeSrcUL\Settings.py" +#pause >nul #Import parent folder to import current / other packages ######################################################### import sys @@ -24,22 +28,16 @@ if lSubmoduleFunctionName in dir(lTechModuleFromSpec): mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() ################################################# ######################################################### -from pyOpenRPA.Tools.RobotRDPActive import RDPConnector +from pyOpenRPA.Tools.RobotRDPActive import Connector +from pyOpenRPA.Tools.RobotRDPActive import Monitor #Disable certificate warning lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f' os.system(lCMDString) #time.sleep() for lConfigurationItem in mGlobalDict["RDPList"]: - #RDPConnector.SessionConnect(mConfiguration) - #RDPConnector.LoginPassSet("111.222.222.111","ww","dd") - (lRDPFile, lSessionHex) = RDPConnector.RDPConfigurationCreate(lConfigurationItem) - #Set session hex in globalDict - lConfigurationItem["SessionHex"] = lSessionHex - #Start session - RDPConnector.RDPSessionStart(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 + Connector.Session(lConfigurationItem) +#Run monitor +Monitor.Monitor(mGlobalDict, 1) #Enable certificate warning lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 2 /f' os.system(lCMDString) \ No newline at end of file diff --git a/Utils/RobotRDPActive/pyOpenRPA.Tools.RobotRDPActive_x64.cmd b/Utils/RobotRDPActive/pyOpenRPA.Tools.RobotRDPActive_x64.cmd index 4e67d906..dc05d29d 100644 --- a/Utils/RobotRDPActive/pyOpenRPA.Tools.RobotRDPActive_x64.cmd +++ b/Utils/RobotRDPActive/pyOpenRPA.Tools.RobotRDPActive_x64.cmd @@ -1,3 +1,3 @@ cd %~dp0..\..\Sources -..\Resources\WPy64-3720\python-3.7.2.amd64\python.exe -m pyOpenRPA.Tools.RobotRDPActive "C:\Abs\Archive\scopeSrcUL\OpenRPA_Creds\RobotRDPActive\SettingsRusmed.py" +..\Resources\WPy64-3720\python-3.7.2.amd64\python.exe -m pyOpenRPA.Tools.RobotRDPActive "C:\Abs\Archive\scopeSrcUL\OpenRPA_Creds\RobotRDPActive\SettingsVSK.py" pause >nul \ No newline at end of file diff --git a/changelog.md b/changelog.md index e1c6417d..be060588 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,6 @@ Beta before 1.0.1 (new way of OpenRPA with improovments. Sorry, but no backward compatibility)/ Backward compatibility will start from 1.0.1 +[1.0.28] +RobotRDPActive first version is ready! [1.0.26] Robot UIDesktop bug fix in Safe other process function [1.0.25] diff --git a/v1.0.27 b/v1.0.28 similarity index 100% rename from v1.0.27 rename to v1.0.28