rahul603 Posted June 1, 2010 Share Posted June 1, 2010 I am creating a script to install an application. I want to automate this process. I know i can easily automate the installation process using AutoIT. But my question here is that if any error comes during installation process. Which method or function should i use to handle such type of errors using AutoIT. Please provide some solution.. Thanks, Rahul Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 1, 2010 Share Posted June 1, 2010 There isn't any one solution. You can check the return values of all the AutoIt functions you use by what's expected according to the help file. You also need to assume external actions may hang/timeout/fail and come up with ways of detecting those. Including strong logging to a file simplifies doing some forensics when things go wrong. The particulars are too situation specific to be detailed in reply to such a general question. Provide an example of the kind of error you want to handle. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
water Posted June 1, 2010 Share Posted June 1, 2010 What application do you want to install? Does this application have any kind of automated installation (MSI, batch installer ...)? If yes you can direct all messages to a log file and after installation check the log file for any errors or a success message. But it depends on the application. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
rahul603 Posted June 1, 2010 Author Share Posted June 1, 2010 What application do you want to install?Does this application have any kind of automated installation (MSI, batch installer ...)? If yes you can direct all messages to a log file and after installation check the log file for any errors or a success message.But it depends on the application. Link to comment Share on other sites More sharing options...
rahul603 Posted June 1, 2010 Author Share Posted June 1, 2010 Here is my script....I am trying to install WinRAR on my machine. #include "include\file.au3" #include "include\versioncompare.au3" #include "include\filecopyprogress.au3" ;in case UAC is on #requireadmin Dim $Appfile Dim $logfile Dim $CurrentVer $logfile = "C:\application_logs.txt" $Appfile = "C:\Program Files\WinRAR\WinRAR.exe" $SourceDir = "C:\source" ; start installation _FileWriteLog($logfile, "Installing WinRar 3.93 32-Bit on test machine") _FileWriteLog($logfile, "Launching Setup now...") Run("C:\source\wrar393_32-bit.exe") _FileWriteLog($logfile, "Installing WinRar 3.93 in the default location C:\Program Files\WinRar") WinWaitActive("WinRAR 3.93", "Install") ControlClick("WinRAR 3.93", "", "[CLASS:Button; ID:1; TEXT:Install; INSTANCE:2]") _FileWriteLog($logfile, "Clicked on Install button to initiate the installation process") WinWaitActive("WinRAR Setup", "These options") ControlClick("WinRAR Setup", "", "[CLASS:Button; ID:1; TEXT:OK; INSTANCE:27]") _FileWriteLog($logfile, "Clicked on 'OK' button on WinRAR Setup screen") WinWaitActive("WinRAR Setup", "Thank you") ControlClick("WinRAR Setup", "", "[CLASS:Button; ID:1; TEXT:Done; INSTANCE:1]") _FileWriteLog($logfile, "Clicked on Done button to complete the installation process") Sleep(2000) Send("!{ALT}") sleep(2000) ;Send("(F)") sleep(1000) Send("{DOWN 6}") sleep(2000) send("{ENTER}") ; To verify that correct version of WinRar is installed on the test machine") $CurrentVer = FileGetVersion($Appfile) _FileWriteLog($logfile, "The current version of WinRAR is: " & $CurrentVer) I have created a batch file which runs 3-4 automated script for different installers in one go. Now, if any installer fails, i want to capture that error (that error can be installer crashed or any error message pop-up). Also in that case my other script does not execute. I just want that my script should handle those errors and move further with other script execution. Can you help in this? Link to comment Share on other sites More sharing options...
Fireworker Posted June 1, 2010 Share Posted June 1, 2010 (edited) Hi, i have not complete read your problem, but... You want to install WINRAR3x.exe. Try... $APPTITLE = "WinRAR_3x" $SYSDRIVE = EnvGet("SystemDrive") $LOGFILE_PATH = @SystemDir & "\Installer\LOG" $LOGFILE = $LOGFILE_PATH & "\" & $APPTITLE & ".log" $INST_PATH = $SYSDRIVE & "\INSTALLER" $INST_FILE = $INST_PATH & "\wrar393d.exe" $INST_PARM = "/S" $INST_EXEC = '"' & $INST_FILE & '"' & " " & $INST_PARM If FileExists($INST_FILE) Then $RC = RunWait($INST_EXEC, $INST_PATH, @SW_HIDE) If $RC = "0" Or $RC = "1641" Or $RC = "3010" Then $EXIT_REC = $RC _FileWriteLog($LOGFILE, " -> Installation finished successfully, returned " & '"' & $RC & '"') Else _FileWriteLog($LOGFILE, " -> Installation failed, returned " & '"' & $RC & '"' & " Abort!") EndIf Else _FileWriteLog($LOGFILE, " . Installation sources not found, ABORT...") $EXIT_RC = "1" EndIf Exit($EXIT_RC) Edited June 1, 2010 by Fireworker Link to comment Share on other sites More sharing options...
Gariputo Posted June 1, 2010 Share Posted June 1, 2010 (edited) WinRAR has a switch to do a silent install with the default settings. Execute "winrarinstallername.exe /s". Then after the install, registration information should be stored in some reg file you could edit with your script. I think it is in the WinRAR program directory. It could help cut down on the errors you run into since you dont have to click any buttons with your script. Oh and here is the WinRAR knowledge base which might have errors the installer will run into: http://www.win-rar.com/knowledgebase.html Edited June 1, 2010 by Gariputo Link to comment Share on other sites More sharing options...
rahul603 Posted June 1, 2010 Author Share Posted June 1, 2010 Hi All, Thanks for the response. But i need to run the multiple AutoIT scripts in a batch file. Now, if any scripts fails during execution, then the remaining number of scripts does not executes. So that's why i was looking for a solution to handle all the unexpected errors. Are there any functions/methods in AutoIT that i can use to handle errors during script execution? Link to comment Share on other sites More sharing options...
UEZ Posted June 1, 2010 Share Posted June 1, 2010 You can use the internal error handler to bypass internal errors -> search in help file for ObjEvent()Example:... $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler ... ; This is my custom defined error handler Func MyErrFunc() Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) Local $err = $oMyError.number If $err = 0 Then $err = -1 $g_eventerror = $err ; to check for after this function returns EndfuncBR,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
bo8ster Posted June 2, 2010 Share Posted June 2, 2010 (edited) Hi All, Thanks for the response. But i need to run the multiple AutoIT scripts in a batch file. Now, if any scripts fails during execution, then the remaining number of scripts does not executes. So that's why i was looking for a solution to handle all the unexpected errors. Are there any functions/methods in AutoIT that i can use to handle errors during script execution? You can use Exit() to indercate the exit status of a script then see what program returned. All programs return an exit status which can be seen by the calling process. (Can't remember the exact process off the top of my head). Edit: You can do something like this in a bat file @echo off myscript.exe if errorlevel 1 ( echo Failure Reason Given is %errorlevel% exit /b %errorlevel% ). I do not know how to do it in AutoIt however I would run one autoscript that runs the rest as autoit gives you better control and functionality. EnvGet("errorlevel") is a start. Source: http://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line http://en.wikipedia.org/wiki/Exit_status @ AdmiralAlkex - realised my mistake as soon as I posted - thanks. Edited June 2, 2010 by bo8ster Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 2, 2010 Share Posted June 2, 2010 (edited) @bo8sterYou're thinking about Exit, not Return Edit: You got me this time Edited June 2, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
kalucas Posted February 28, 2014 Share Posted February 28, 2014 Hi, i have not complete read your problem, but... You want to install WINRAR3x.exe. Try... $APPTITLE = "WinRAR_3x" $SYSDRIVE = EnvGet("SystemDrive") $LOGFILE_PATH = @SystemDir & "\Installer\LOG" $LOGFILE = $LOGFILE_PATH & "\" & $APPTITLE & ".log" $INST_PATH = $SYSDRIVE & "\INSTALLER" $INST_FILE = $INST_PATH & "\wrar393d.exe" $INST_PARM = "/S" $INST_EXEC = '"' & $INST_FILE & '"' & " " & $INST_PARM If FileExists($INST_FILE) Then $RC = RunWait($INST_EXEC, $INST_PATH, @SW_HIDE) If $RC = "0" Or $RC = "1641" Or $RC = "3010" Then $EXIT_REC = $RC _FileWriteLog($LOGFILE, " -> Installation finished successfully, returned " & '"' & $RC & '"') Else _FileWriteLog($LOGFILE, " -> Installation failed, returned " & '"' & $RC & '"' & " Abort!") EndIf Else _FileWriteLog($LOGFILE, " . Installation sources not found, ABORT...") $EXIT_RC = "1" EndIf Exit($EXIT_RC) I realize this thread is 4 years old and the person who posted the above code is probably no longer here, but maybe someone else can answer. It doesn't look like this code actually performs the install. I tried this and it didn't install anything until I put an additional RunWait statement below the $RC = RunWait... Now I'm not sure if this is the best way to do this, or if I'm ever going to get a return code other than 0. Any thoughts? Link to comment Share on other sites More sharing options...
water Posted February 28, 2014 Share Posted February 28, 2014 Your best bet is to start a new thread and to link to this one. Necroing old threads doesn't attrack many readers. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
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