tuffgong

Reliability of Compiled Scripts (Only Obj Type Variables Allowed...)

10 posts in this topic

I have learned a lot from this forum and I was hoping to hear some views on this topic that is concerning me. I have written some programs that have been well received here at my job which has allowed me more time to spend writing scripts - all good. However, I have noticed that some of my programs work for several weeks and then come up with errors. I was wondering if there is something I could do to make them more robust.

Example: management complained that our very old PCs took too long to boot and start the intranet based application the users require. The age of the PCs, the high level of network security, and the touchscreens on these PCs can make things difficult for the users. I wrote a script that runs when the user logs in. It pings the server and when it gets a response, it loads the application in full screen.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form= ; This part makes the GUI message
$Form2 = GUICreate("Form2", 1579, 772, 192, 132)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("C:\Program Files (x86)\AppStart\One-Moment-Please-front-cover.jpg", 8, 8, 577, 753)
$Pic2 = GUICtrlCreatePic("C:\Program Files (x86)\AppStart\Logo.bmp", 856, 56, 481, 121)
$Label1 = GUICtrlCreateLabel("Stand By", 920, 200, 385, 133)
GUICtrlSetFont(-1, 72, 400, 4, "Palatino Linotype")
$Label2 = GUICtrlCreateLabel("Your Application Will Start", 824, 360, 587, 68)
GUICtrlSetFont(-1, 36, 400, 0, "Palatino Linotype")
$Label3 = GUICtrlCreateLabel("Momentarily", 984, 456, 282, 68)
GUICtrlSetFont(-1, 36, 400, 0, "Palatino Linotype")
$Pic3 = GUICtrlCreatePic("C:\Program Files (x86)\QCAppStart\images (1).jpg", 1016, 576, 225, 153)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Local $iPing = Ping ("server", 4000) ; PING server in a loop. Will not proceed until successfull PING
Local $urlQC = "http://server/app"
If $iPing Then ; If PING is successfull THEN...
   Global $oIE = _IECreate("about:blank", 0, 0, 1, 1) ; open a blank, invisible instance of IE
   _IENavigate($oIE, $urlQC, 1) ; navigate to wmsextender URL
   With $oIE ; set properties for page - makes page visible
   .Left = 0
   .Top = 0
   .MenuBar = True
   .Resizable = False
   .StatusBar = False
   .TheaterMode = False
   .Toolbar = True
   .Fullscreen = False
   .Visible = True
EndWith
WinSetState("Quality Control - Internet Explorer", "", @SW_MAXIMIZE) ; maximize web page
   ExitLoop
Else
   Sleep(3000) ; wait 3 seconds before next PING
EndIf
WEnd
Local $iStatus = WinGetState("Quality Control - Internet Explorer") ; is IE Window maximized? Get status
; MsgBox($MB_SYSTEMMODAL, "IE Status", $iStatus)
GUISetState(@SW_DISABLE) ; close GUI
If BitAND ($iStatus, 32) Then ; this section double checks to make sure window is maximized before ending
   Exit
Else
  WinSetState("Quality Control - Internet Explorer", "", @SW_MAXIMIZE) ; if not maximized, DO IT NOW!!!!!
EndIf
Exit

This script has been working for weeks and was a big hit. It is still working for the most part but several computers display the GUI for awhile then error out with "Only object type variables allowed in a with statement." Now, I have been in IT for a long time and all of my troubleshooting skills tell me that our admittedly old computers are mostly to blame: most PCs run the script fine, a few do not, the ones that do not work DID work for weeks. The ones that fail always display the same error and a reboot does not fix it. Even if it is a bad/slow/old PC, if the error is cleared the intranet app will run fine if started manually. So, the PC is okay to run the app but not my script. The PC displays no other outward signs of trouble.

Not sure what I am looking for here. Maybe something to make this script a little more robust? Maybe some shared experience or discussion on making these scripts run well on older Windows 7 computers? I have other examples of some scripts that run on some computers but not others, or scripts that run for days or weeks on certain PCs then just stop working and no reboot will resolve but the PC is otherwise fine. All of these PCs are created with the same image so settings should be the same.

Share this post


Link to post
Share on other sites



The IE* functions set @error in case of a problem. So you need to add some error checking. Example:

Global $oIE = _IECreate("about:blank", 0, 0, 1, 1) ; open a blank, invisible instance of IE
If @error Then Exit MsgBox(0, "Error", "_IECreate returned error: " & @error)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

BTW: You create the IE instance inside your while loop. So you might end up with a lot of instances. Move it outside the loop to save ressources.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Good tips. I will employ the fixes on the PCs that are not working and see if that helps.

Share this post


Link to post
Share on other sites

In this script, isn't the IE instance only created if the ping is successful? I realize the create statement is within the loop but I thought the IF statement would prevent it from creating multiple IE instances.

Share this post


Link to post
Share on other sites

Hi tuffgong,

I like to split the actions in functions, your while loop for example:

_CheckServer("server") ; PING server in a loop. Will not proceed until successfull PING or will exit if timeout

_CreateIE()

GUIDelete()
Exit

Func _CreateIE($hTimeout = 120000) ;2 min default timeout
    Local $hTimer = TimerInit()

    While TimerDiff($hTimer) < $hTimeout
        Global $oIE = _IECreate("http://server/app", 1, 0) ; open an invisible instance of IE
        If @error Or Not IsObj($oIE) Then
            While ProcessExists("iexplore.exe") And TimerDiff($hTimer) < $hTimeout
                ProcessClose("iexplore.exe")
            WEnd
            Sleep(5000)
            ContinueLoop
        EndIf

        With $oIE ; set properties for page - makes page visible
            .Left = 0
            .Top = 0
            .MenuBar = True
            .Resizable = False
            .StatusBar = False
            .TheaterMode = False
            .Toolbar = True
            .Fullscreen = False
            .Visible = True
        EndWith

        Local $hWnd = _IEPropertyGet($oIE, "hwnd")
        If Not @error And IsHWnd($hWnd) Then
            Do
                WinSetState($hWnd, "", @SW_MAXIMIZE) ; maximize web page
                If TimerDiff($hTimer) > $hTimeout Then ExitLoop 2
            Until Sleep(1000) And BitAND(WinGetState($hWnd), 32)
        Else
            Do
                WinSetState("Quality Control - Internet Explorer", "", @SW_MAXIMIZE) ; maximize web page
                If TimerDiff($hTimer) > $hTimeout Then ExitLoop 2
            Until Sleep(1000) And BitAND(WinGetState("Quality Control - Internet Explorer"), 32)
        EndIf

        Return
    WEnd

    Exit MsgBox(0,"Timeout","Could not create IE object.")
EndFunc   ;==>_CreateIE

Func _CheckServer($sAddress, $hTimeout = 300000) ;5 min default timeout
    Local $hTimer = TimerInit()
    Do
        If TimerDiff($hTimer) > $hTimeout Then Exit MsgBox(0,"Timeout","Server not responding.")
    Until Sleep(3000) And Ping($sAddress)
EndFunc   ;==>_CheckServer

 

Share this post


Link to post
Share on other sites

This is a good suggestion. I absolutely need to employ more functions in my scripts. This is a good opportunity to learn and to add some much needed efficiency. Thank you.

Share this post


Link to post
Share on other sites

Also don't forget to add a COM error handler.

Share this post


Link to post
Share on other sites

MichaelHB (or anyone still listening), I went on PTO right after I posted this and I didn't see your last response about COM error handling until now. I am breaking this script down into functions as suggested - just to get more familiar with functions if anything. I have been reading the AutoIt section on COM/Obj and also some documentation from Microsoft on the subject. However, I am wondering if you could provide a small example (if you are still there!)

The only thing this script does is:

Create GUI

PING/Check Server

Open IE/Close GUI

Where would you employ COM error checking. I am creating many scripts as part of my job and I would love to learn more tools to make these scripts more stable.

Thanks you!

Share this post


Link to post
Share on other sites

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

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