ijourneaux Posted August 23, 2010 Posted August 23, 2010 I have a AutoIt script that is used to automate an application. The script runs as a scheduled task. 90% of the time the script works correctly. The other 10% or so, the script fails waiting for the Print dialog to appear. I was wondering if anyone had thoughts on how to troubleshoot a problem like this as when I run the script manually it always seems to work. Here is the subroutine that prints the display. I use WinMenuSelectItem("InfoStore Client", "", "&File", "&Print") to execute the print command. This always returns success (1). Func PrintDisplay() WriteToLogFile(@ScriptDir & $LogFileName, "In Print Display") $Count = 0 Do Sleep(1000) $status = WinMenuSelectItem("InfoStore Client", "", "&File", "&Print") $Count = $Count + 1 if($Count = 10) Then $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $FromAddress, "Print Display: IFM Report " & $FileName & " did not print!", "", "", $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) $hWnd = WinGetHandle("InfoStore Client") ;~ _ScreenCapture_CaptureWnd (@ScriptDir & "\Temp\CurrentScreen_" & @hour & @MIN & @sec & ".jpg", $hWnd) ProcessClose ("InfoStore.exe") Exit EndIf until ($status = 1) ; WinWaitActive("Print") call("WaitForControl", "Print", "&Print", "[CLASS:Button; INSTANCE:13]", $DefaultTimeOut) ControlClick("Print", "&Print", "Button13") call("WaitForControl", "InfoStore Client", "", "[CLASS:ThunderRT6ComboBox; INSTANCE:3]", $DefaultTimeOut) EndFunc Then I use WaitForControl (see below) to wait for the &Print button on the print dialog to appear. When it works, the print dialog shows up in 10-15sec or so. When it fails, the scrpt timesout at 200sec. I tried capturing the screen to see if I could see some reason why the print dialog dod not appear but all I get is a black screen. Func WaitForControl($sTitle, $text, $sControlID, $iTimeout = 5, $Exit = 'True') Local $iTimer = TimerInit() While (ControlFocus($sTitle, $text, $sControlID) = 0) WriteToLogFile(@ScriptDir & $LogFileName, "Wait") if (TimerDiff($iTimer) / 1000) >= $iTimeout then WriteToLogFile(@ScriptDir & $LogFileName, "Exit without Focus - " & $sTitle & " - " & $text) if($exit = "True") then $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $FromAddress, "IFM Report " & $FileName & " did not print! " - TimerDiff($iTimer) / 1000, "", "", $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) $hWnd = WinGetHandle("InfoStore Client") _ScreenCapture_CaptureWnd (@ScriptDir & "\Temp\CurrentScreen_" & @hour & @MIN & @sec & ".jpg", $hWnd) ProcessClose ("InfoStore.exe") Exit EndIf EndIf Sleep(5000) ;~ WriteToLogFile(@ScriptDir & $LogFileName, "Activate - " & $sTitle) If (TimerDiff($iTimer) / 1000) >= $iTimeout/2 Then WinActivate($sTitle, $text) WEnd WriteToLogFile(@ScriptDir & $LogFileName, "Title = " & $sTitle & ": Timer = " & TimerDiff($iTimer) / 1000) Sleep(3000) return 1 EndFunc Apprecaite any thoughts on how I could troubleshoot this. Ian
Juvigy Posted August 23, 2010 Posted August 23, 2010 You can try putting in the schedule the option : onerror Restart - it will restart the script when you receive the error.
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