diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py new file mode 100644 index 00000000..2942ae38 --- /dev/null +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/Monitor.py @@ -0,0 +1,10 @@ +from pyOpenRPA.Robot import UIDesktop +#Check for session is closed +def Monitor(inGlobalDict, inListUpdateTimeout): + lUIOSelectorList=[] + for lItem in inGlobalDict["RDPList"]: + lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']} — .*", "backend": "win32"}]) + while True: + lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout) + for lItem in lRDPDissappearList: + #Session start \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py index fbff9341..9aa900ed 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/RDPConnector.py @@ -4,6 +4,7 @@ import os #os for process run import uuid #temp id for Template.rdp import tempfile #Temporary location import time +import subprocess #Connect to RDP session """ { @@ -58,7 +59,7 @@ def LoginPassSet(inHost,inLogin,inPassword): os.system(f"cmdkey /generic:TERMSRV/{inHost} /user:{inLogin} /pass:{inPassword}") return None #Create current .rdp file with settings -#Return full path to file +#Return (full path to file, session hex) def RDPConfigurationCreate(inConfiguration): #RobotRDPActive folder path lFileFullPath=__file__ @@ -82,4 +83,51 @@ def RDPConfigurationCreate(inConfiguration): 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 \ No newline at end of file + return (lRDPCurrentFileFullPath, (lRDPCurrentFileFullPath.split("\\")[-1])[0:-4]) +#RDPSessionStart +def RDPSessionStart(inRDPFilePath): + #run rdp session + lItemArgs = [inRDPFilePath] + subprocess.Popen(lItemArgs, shell=True) + #Wait for UAC unknown publisher exists + lRDPFileName = (inRDPFilePath.split("\\")[-1])[0:-4] + lWaitResult = UIDesktop.UIOSelectorsSecs_WaitAppear_List( + [ + [{"title": "Подключение к удаленному рабочему столу", "class_name": "#32770", "backend": "win32"}, + {"title": "Боль&ше не выводить запрос о подключениях к этому компьютеру", "friendly_class_name": "CheckBox"}], + [{"title_re": f"{lRDPFileName} — .*", + "class_name": "TscShellContainerClass", "backend": "win32"}] + ], + 60 + ) + #Click if 0 is appear + if 0 in lWaitResult: + #Check the box do not retry + UIDesktop.UIOSelector_Get_UIO([{"title": "Подключение к удаленному рабочему столу", "backend": "win32"}, + {"title": "Боль&ше не выводить запрос о подключениях к этому компьютеру", "friendly_class_name": "CheckBox"}]).check() + #Go to connection + UIDesktop.UIOSelector_Get_UIO([{"title": "Подключение к удаленному рабочему столу", "backend": "win32"}, + {"title":"Подкл&ючить", "class_name":"Button"}]).click() + lWaitResult = UIDesktop.UIOSelectorsSecs_WaitAppear_List( + [ + [{"title_re": f"{lRDPFileName} — .*", + "class_name": "TscShellContainerClass", "backend": "win32"}] + ], + 60 + ) + #Prepare little window + SessionLittleScreen(lRDPFileName) + return None +#Set fullscreen for app +def SessionFullScreen(inSessionHex): + #Prepare little window + lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{lRDPFileName} — .*", "backend": "win32"}]) + lRDPWindow.maximize() + return None +#Set Little window of the session +def SessionLittleScreen(inSessionHex): + #Prepare little window + lRDPWindow = UIDesktop.UIOSelector_Get_UIO([{"title_re": f"{lRDPFileName} — .*", "backend": "win32"}]) + lRDPWindow.restore() + lRDPWindow.move_window(10,10,550,100) + return None diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py b/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py index 549e7d43..66c12585 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/SettingsExample.py @@ -1,6 +1,21 @@ #Robot RDPActive settings def Settings(): mDict = { - + "RDPList": + [ + { + "Host": "77.77.22.22", # Host address + "Port": "7777", # RDP Port + "Login": "test", # Login + "Password": "test", # Password + "Screen": { + "Resolution": "FullScreen", + # "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" + }, + "SessionHex":"" # Hex is created when robot runs + } + ] } return mDict \ No newline at end of file diff --git a/Sources/pyOpenRPA/Tools/RobotRDPActive/Template.rdp b/Sources/pyOpenRPA/Tools/RobotRDPActive/Template.rdp index b298abcf..0213438e 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 55d4e879..031ad081 100644 --- a/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py +++ b/Sources/pyOpenRPA/Tools/RobotRDPActive/__main__.py @@ -4,28 +4,42 @@ import sys import subprocess #start process async import os #path, run, remove import time #timer +import importlib #lFolderPath = "\\".join(__file__.split("\\")[:-4]) lFolderPath = "/".join(__file__.split("/")[:-4]) sys.path.insert(0, lFolderPath) +#Единый глобальный словарь (За основу взять из Settings.py) +global mGlobalDict +#Call Settings function from argv[1] file +################################################ +lSubmoduleFunctionName = "Settings" +lFileFullPath = sys.argv[1] +lModuleName = (lFileFullPath.split("\\")[-1])[0:-3] +lTechSpecification = importlib.util.spec_from_file_location(lModuleName, lFileFullPath) +lTechModuleFromSpec = importlib.util.module_from_spec(lTechSpecification) +lTechSpecificationModuleLoader = lTechSpecification.loader.exec_module(lTechModuleFromSpec) +mGlobalDict = None +if lSubmoduleFunctionName in dir(lTechModuleFromSpec): + # Run SettingUpdate function in submodule + mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() +################################################# ######################################################### from pyOpenRPA.Tools.RobotRDPActive import RDPConnector -mConfiguration={ - "Host": "77.77.22.22", #Host address - "Port": "7777", #RDP Port - "Login": "test", # Login - "Password": "test", #Password - "Screen": { - "Resolution":"FullScreen", #"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" - } -} -#RDPConnector.SessionConnect(mConfiguration) -#RDPConnector.LoginPassSet("111.222.222.111","ww","dd") -lRDPFile = RDPConnector.RDPConfigurationCreate(mConfiguration) -#run rdp session -lItemArgs = [lRDPFile] -subprocess.Popen(lItemArgs, shell=True) -#Remove temp file -time.sleep(2) #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 \ No newline at end of file +#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 +#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 new file mode 100644 index 00000000..4e67d906 --- /dev/null +++ b/Utils/RobotRDPActive/pyOpenRPA.Tools.RobotRDPActive_x64.cmd @@ -0,0 +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" +pause >nul \ No newline at end of file