Pelicer Posted March 11, 2019 Posted March 11, 2019 Hello, all! I'm developing a change to a RPA in which it should warn my database if it is currently running. If not, it should warn too. My approach was to create a function that will check in a config file if I want to report. If so, report either 1 (active) or 0 (innactive). The code below is working really fine when I run it from .au3. expandcollapse popupOnAutoItExitRegister("_ReportActivity") ;============================================================================================================================== ; Function: _ReportActivity() ; ; Description: Call WEB service to report DSL that the RPA is currently running ; ; Parameter(s): - ; ; Return Value(s): Void ; ; Author (s): Silva, William ;=============================================================================================================================== Func _ReportActivity() ; Mandatory for Error Code Control Local $l_szFuncName = "_ReportActivity" ;Local vars Local $szSetupFile = @ScriptDir & "\ini\SETUP.ini" Local $szSetupData = "" Local $szReturn = "" Local $nStatus _FileWriteLog(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & ".log", "[" & $l_szFuncName & " @ " & 1 & "] " & "Trying to report DSL..." & @CRLF ) ConsoleWrite(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & "[" & $l_szFuncName & " @ " & 1 & "] " & "Trying to report DSL..." & @CRLF ) ;Code If Bool($_bReportActivity) Then If Not FileExists( $szSetupFile ) Then ;Write error log _FileWriteLog(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & ".log", "[" & $l_szFuncName & " @ " & 1 & "] " & "Setup.ini file not found. Could not contact DSL to report activity." & @CRLF ) Else ;Reads the file $szSetupData = BinaryToString(base64(FileRead ( FileOpen( $szSetupFile,0)), False)) EndIf $szReturn = _CallWebServiceDSL($nStatus , _IniMem_Read($szSetupData, "DSL_DATA","POST",""), _IniMem_Read ($szSetupData,"DSL_DATA","HOST",""), _IniMem_Read ($szSetupData,"DSL_DATA","ConType",""), _IniMem_Read ($szSetupData,"DSL_DATA","SoapAct","") , "2D42AC0A-9643-4780-9198-BDE886A958CF", _ _IniMem_Read ($szSetupData,"DSL_DATA","Module",""), "UpdateSoftwareBundleSettings", _IniMem_Read($szSetupData,"DSL_DATA", "inkjet_name")&";ACTIVE;PARAMETER;"&$_nActive,_IniMem_Read ($szSetupData,"DSL_DATA","SEPARATOR",";")) _FileWriteLog(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & ".log", "[" & $l_szFuncName & " @ " & 1 & "] " & "Report to DSL is Enabled. Reported: " & $_nActive & @CRLF ) ConsoleWrite(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY &"[" & $l_szFuncName & " @ " & 1 & "] " & "Report to DSL is Enabled. Reported: " & $_nActive & @CRLF) If($_nActive == 0) Then _FileWriteLog(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & ".log", "[" & $l_szFuncName & " @ " & 1 & "] " & "Code: " & @exitCode &" Method: " & @exitMethod) Endif ;Sets the $_nActive to its opposite $_nActive = ($_nActive = 1) ? 0 : 1 Else _FileWriteLog(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & ".log", "[" & $l_szFuncName & " @ " & 1 & "] " & "Report to DSL is Disabled." & @CRLF ) ConsoleWrite(@ScriptDir & "\" & @YEAR & "-" & @MON & "-" & @MDAY & "[" & $l_szFuncName & " @ " & 1 & "] " & "Report to DSL is Disabled." & @CRLF ) EndIf Endfunc Func Main() _ReportActivity() ... Endfunc Main() When the above is running from .exe, it reports active. But on exit (I'm trying by clicking the close button of the prompt window), it does not call the function. I was having a problem previously in which the RPA would crash any time I tried to exit it. I figured out that a global variable that was being used as parameter to call another function from _ReportActivity caused that error. I fixed it, and then tried to remove all kinds of global variables from the function, but It still won't work when running from .exe.
Nine Posted March 11, 2019 Posted March 11, 2019 I use it all the time in exe and it is working fine. I suggest you make a small runable snippet that reproduces the problem. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Pelicer Posted March 11, 2019 Author Posted March 11, 2019 I have just run more tests. Apperantly, the .exe is not calling OnAutoItExitRegister when the prompt is closed by clicking the close button of the window.
Nine Posted March 11, 2019 Posted March 11, 2019 oh, you mean you open a DOS window (cmd.exe), you start your exe and in the middle of the script you close the DOS window ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
water Posted March 11, 2019 Posted March 11, 2019 Even in this case the function gets called: #include <GUIConstantsEx.au3> OnAutoItExitRegister("_Exit") Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example") Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _Exit() MsgBox(0, "Exit", "Program is now closed!") EndFunc My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Nine Posted March 11, 2019 Posted March 11, 2019 @water I think he means DOS window, not GUI window... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
water Posted March 11, 2019 Posted March 11, 2019 In this case we need a reproducer script! This kind of automation should be possible without an open DOS window. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Pelicer Posted March 11, 2019 Author Posted March 11, 2019 Yes, @Nine. I'm sorry for the confusion. So the problem is: there's a batch file that makes the decision if it should open x64 or x86 version. The .exe IS calling the OnAutoItExitRegister when a exit event is ran. But when I close the DOS, I'm not actually closing the .exe... What I need right now, I think, is to somehow have a OnExit event on CMD, to end the .exe from there.
water Posted March 11, 2019 Posted March 11, 2019 (edited) You could either translate the bat file to AutoIt as well or use one of the described tips how to run a bat file without DOS window (so the user can't close).https://www.raymond.cc/blog/hidden-start-runs-batch-files-silently-without-flickering-console/ https://www.robvanderwoude.com/battech_hideconsole.php Edited March 11, 2019 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Nine Posted March 11, 2019 Posted March 11, 2019 @Pelicer Understand. Could you simply test repeatedly if the cmd.exe window still exists, and if not, exit the script. Or you could start a second script from the first that would check for that DOS window still exists, and close your 1st script in case DOS window is close “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now