#1.0.28 #RobotRDPActive is ready for test

dev-linux
Ivan Maslov 5 years ago
parent 78a97d1051
commit c71394fa52

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

@ -1,10 +1,17 @@
from pyOpenRPA.Robot import UIDesktop 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): def Monitor(inGlobalDict, inListUpdateTimeout):
lUIOSelectorList=[] while True:
# UIOSelector list init
lUIOSelectorList = []
for lItem in inGlobalDict["RDPList"]: for lItem in inGlobalDict["RDPList"]:
lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']} — .*", "backend": "win32"}]) lUIOSelectorList.append([{"title_re": f"{lItem['SessionHex']} — .*", "backend": "win32"}])
while True: #Run wait command
lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout) lRDPDissappearList = UIDesktop.UIOSelectorsSecs_WaitDisappear_List(lUIOSelectorList, inListUpdateTimeout)
for lItem in lRDPDissappearList: for lItem in lRDPDissappearList:
#pdb.set_trace()
#Session start #Session start
Connector.Session(inGlobalDict["RDPList"][lItem])
return None

@ -9,7 +9,8 @@ def Settings():
"Login": "test", # Login "Login": "test", # Login
"Password": "test", # Password "Password": "test", # Password
"Screen": { "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 # "640x480" or "1680x1050" or "FullScreen". If Resolution not exists set full screen
"FlagUseAllMonitors": False, # True or False "FlagUseAllMonitors": False, # True or False
"DepthBit": "32" # "32" or "24" or "16" or "15" "DepthBit": "32" # "32" or "24" or "16" or "15"

@ -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 parent folder to import current / other packages
######################################################### #########################################################
import sys import sys
@ -24,22 +28,16 @@ if lSubmoduleFunctionName in dir(lTechModuleFromSpec):
mGlobalDict = getattr(lTechModuleFromSpec, lSubmoduleFunctionName)() 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 #Disable certificate warning
lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f' lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f'
os.system(lCMDString) os.system(lCMDString)
#time.sleep() #time.sleep()
for lConfigurationItem in mGlobalDict["RDPList"]: for lConfigurationItem in mGlobalDict["RDPList"]:
#RDPConnector.SessionConnect(mConfiguration) Connector.Session(lConfigurationItem)
#RDPConnector.LoginPassSet("111.222.222.111","ww","dd") #Run monitor
(lRDPFile, lSessionHex) = RDPConnector.RDPConfigurationCreate(lConfigurationItem) Monitor.Monitor(mGlobalDict, 1)
#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 #Enable certificate warning
lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 2 /f' lCMDString = 'reg add "HKEY_CURRENT_USER\\Software\\Microsoft\\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 2 /f'
os.system(lCMDString) os.system(lCMDString)

@ -1,3 +1,3 @@
cd %~dp0..\..\Sources 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 pause >nul

@ -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 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] [1.0.26]
Robot UIDesktop bug fix in Safe other process function Robot UIDesktop bug fix in Safe other process function
[1.0.25] [1.0.25]

Loading…
Cancel
Save