# ATTENTION! HERE IS NO Relative import because it will be imported dynamically # All function check the flag SessionIsWindowResponsibleBool == True else no cammand is processed # All functions can return None, Bool or Dict { "IsSuccessful": True } from pyOpenRPA.Tools.RobotRDPActive import CMDStr # Create CMD Strings from pyOpenRPA.Tools.RobotRDPActive import Connector # RDP API #ATTENTION gSettings = None # Gsettings will be initialized after the import module def ProcessStartIfNotRunning(inSessionIndex, inProcessName, inFilePath, inFlagGetAbsPath=True): global gSettings inGlobalDict = gSettings lResult = True lCMDStr = CMDStr.ProcessStartIfNotRunning(inProcessName,inFilePath, inFlagGetAbsPath= inFlagGetAbsPath) # Calculate the session Hex lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] # Check is Session is responsible if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: # Run CMD Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="RUN") else: # Write in logger - warning inGlobalDict["Logger"].warning(f"Defs_SessionIndex.ProcessStartIfNotRunning: SessionIndex: {str(inSessionIndex)}, ProcessName: {inProcessName}:: Session is not responsible!") lResult = False # Set false result - function has not been done return lResult # Create CMD str to stop process def ProcessStop(inSessionIndex, inProcessName, inFlagForceClose): global gSettings inGlobalDict = gSettings lResult = True lCMDStr = f'taskkill /im "{inProcessName}" /fi "username eq %USERNAME%"' if inFlagForceClose: lCMDStr+= " /F" # Calculate the session Hex lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] # Check is Session is responsible if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: # Run CMD Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="RUN") else: # TODO Write in logger - warning inGlobalDict["Logger"].warning(f"Defs_SessionIndex.ProcessStop: SessionIndex: {str(inSessionIndex)}, ProcessName: {inProcessName}:: Session is not responsible!") lResult = False # Set false result - function has not been done return lResult # Send file from Host to Session RDP using shared drive in RDP def FileStoredSend(inSessionIndex, inHostFilePath, inRDPFilePath): global gSettings inGlobalDict = gSettings lResult = True lCMDStr = CMDStr.FileStoredSend(inHostFilePath = inHostFilePath, inRDPFilePath = inRDPFilePath) # Calculate the session Hex lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] # Check is Session is responsible if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: # Run CMD Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="LISTEN", inClipboardTimeoutSec = 120) else: # Write in logger - warning inGlobalDict["Logger"].warning(f"Defs_SessionIndex.FileStoredSend: SessionIndex: {str(inSessionIndex)}, HostFilePath: {inHostFilePath}:: Session is not responsible!") lResult = False # Set false result - function has not been done return lResult # Recieve file from Session RDP to Host using shared drive in RDP def FileStoredRecieve(inSessionIndex, inRDPFilePath, inHostFilePath): global gSettings inGlobalDict = gSettings lResult = True lCMDStr = CMDStr.FileStoredRecieve(inRDPFilePath = inRDPFilePath, inHostFilePath = inHostFilePath) # Calculate the session Hex lSessionHex = inGlobalDict["RDPList"][inSessionIndex]["SessionHex"] # Check is Session is responsible if inGlobalDict["RDPList"][inSessionIndex]["SessionIsWindowResponsibleBool"]: # Run CMD Connector.SessionCMDRun(inSessionHex=lSessionHex, inCMDCommandStr=lCMDStr, inModeStr="LISTEN", inClipboardTimeoutSec = 120) else: # Write in logger - warning inGlobalDict["Logger"].warning(f"Defs_SessionIndex.FileStoredRecieve: SessionIndex: {str(inSessionIndex)}, HostFilePath: {inHostFilePath}:: Session is not responsible!") lResult = False # Set false result - function has not been done return lResult