tuffgong Posted July 22, 2016 Posted July 22, 2016 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. expandcollapse popup#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.
water Posted July 22, 2016 Posted July 22, 2016 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 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
water Posted July 22, 2016 Posted July 22, 2016 (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 July 22, 2016 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
tuffgong Posted July 22, 2016 Author Posted July 22, 2016 Good tips. I will employ the fixes on the PCs that are not working and see if that helps.
tuffgong Posted July 22, 2016 Author Posted July 22, 2016 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.
MichaelHB Posted July 22, 2016 Posted July 22, 2016 Hi tuffgong, I like to split the actions in functions, your while loop for example: expandcollapse popup_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
tuffgong Posted July 22, 2016 Author Posted July 22, 2016 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.
tuffgong Posted August 2, 2016 Author Posted August 2, 2016 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!
mLipok Posted August 2, 2016 Posted August 2, 2016 Please read: How to use IE.au3 UDF with AutoIt v3.3.14.x Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * 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 * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * 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 * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX 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) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * 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 *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "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" , 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: 2023-04-24
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