Jump to content
Sign in to follow this  
rahul603

Does AutoIT support error handling?

Recommended Posts

rahul603

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

Share this post


Link to post
Share on other sites
PsaltyDS

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.

:mellow:


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

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
rahul603

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.

Share this post


Link to post
Share on other sites
rahul603

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?

Share this post


Link to post
Share on other sites
Fireworker

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 by Fireworker

Share this post


Link to post
Share on other sites
Gariputo

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 by Gariputo

Share this post


Link to post
Share on other sites
rahul603

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?

Share this post


Link to post
Share on other sites
UEZ

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
Endfunc

BR,

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
bo8ster

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 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]

Share this post


Link to post
Share on other sites
kalucas

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?

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×