Jump to content

Skip steps?


Recommended Posts

Hi!

I have a program that sometimes pop up a different window than usual a lot earlier than supposed to. When this happen; is it possible to skip steps and go straight to the part where it continues correctly?

It's a matter of a popup with a warning, instead of the original popping up.

I was thinking about using an if and just pasting the steps from there, but it doesn't really feel correct. Is it possible to get the script to skip steps and go straight to a specific line?

Thank you and good day/night.

Link to comment
Share on other sites

I am not 100% sure what you are after however you can try using the WinExists function to check if the window is open. Depending on whether the window is found or not you can run a different part of your script, try something like below.

If WinExists("Window Title", "") Then
ConsoleWrite("Found Window")
Else
ConsoleWrite("Window Not Found")
EndIf

Edit: WinWait and WinWaitActive might also be useful; you should read up on them.

Edited by Venix
Link to comment
Share on other sites

WinWait and WinWaitActive have a timeout parameter. So you can wait for a specified amount of time for the "unwanted" window to pop up. If it doesn't pop up the script is continued.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

WinWait and WinWaitActive have a timeout parameter. So you can wait for a specified amount of time for the "unwanted" window to pop up. If it doesn't pop up the script is continued.

If he did that, Its going to slow his scrip down correct?

With Switch its going to keep running the scrip till whatever happens and switches over for that func()

then return doing whatever it was doing...Im new myself so im learning at the same time asking this.

Link to comment
Share on other sites

The switch statement is only run once unless it's in a loop.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You could use AdLibRegister to register a function that is called every n milliseconds to check for the unwanted pop up and do whatever is needed. The script isn't slowed down this way.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

It depends when the different window pops up. If it can happen at any time during script execution I would stick with the AdlLibRegister approach and set a flag in the function called by AdLibRegister. Then I would query this flag in the main script and act accordingly.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

It depends when the different window pops up. If it can happen at any time during script execution I would stick with the AdlLibRegister approach and set a flag in the function called by AdLibRegister. Then I would query this flag in the main script and act accordingly.

Mind you, I am *very* new with scripting in autoit, or any language for that matter. I will try my best to explain the issue:

;Checks if the program is up and running. If this is the case it will close the process - accounts to the login screen as well.
If ProcessExists("ControleCaixa1.exe") And WinExists("Menu") Then
WinActivate("Menu")
ControlClick("Menu", "", "[NAME:lblColuna4]")
Sleep(1000)
WinWaitActive("[Erro]", "", "")
ControlClick("", "", "[NAME:btnSim]")
WinWaitActive("C:\WINDOWS\system32\cmd.exe")
WinWaitClose("C:\WINDOWS\system32\cmd.exe")
ElseIf ProcessExists("ControleCaixa1.exe") And WinExists("frmLoginMexico") Then
WinActivate("frmLoginMexico")
Sleep ( 300 )
Send ("{esc}")
EndIf

;Goes to valid string in program to find the unique name for the program if the text files doesn't already exist.
If FileExists ("C:\Programfiler\AutoKey\Datanavn.ini") = 0 Then
Run ("C:\IGS\CAS\ControleCaixa1.exe")
;THIS IS A PROBLEM SPOT FOR POSSIBLE POPUP;
Sleep (3000)
WinWaitActive ("frmLoginMexico")
Sleep (1000)
ControlSend ("frmLoginMexico", "", "[NAME:txtUsuario]", "USER")
Sleep (1000)
ControlSend ("frmLoginMexico", "", "[NAME:txtSenha]", "PASSWORD")
ControlClick ("frmLoginMexico", "", "[NAME:btnOk]")
WinWaitActive ("Menu", "Angi parametere | ")
Sleep (1000)
ControlClick ("Menu", "", "[NAME:lblColuna5]")
Sleep (1000)
Send ("{down}{enter}")
Sleep (2000)
WinWaitActive ("Menu", "Tittelopplysning")
Sleep (300)
$husnavn = ControlGetText ("Menu", "", "[NAME:txtNomeCasa]")
Filewrite ("C:\Programfiler\Autokey\Datanavn.ini", $husnavn)
Sleep (1000)
ProcessClose ("ControleCaixa1.exe")
Else
$Datanavn = FileRead ("C:\Programfiler\AutoKey\Datanavn.ini")
EndIf

;after the program has been completely closed it will move a file which is required for the program to boot up without the error,
; then start automate the process of the new registry window.

;It will also store the name as the variable located in the computername.ini file (datanavn).
;after that, it will transfer the new keyfile to dropbox in a specific location with its unique name.
FileMove("C:\IGS\CAS\Cashcontrol.dll", "C:\Programfiler\AutoKey\tempdirectorypat\Cashcontrol.dll", 9)
Run("C:\IGS\CAS\ControleCaixa1.exe")
;HERE THE POPUP IS EXPECTED;
WinWaitActive("[Erro]")
Sleep(1000)
ControlClick("", "Ja", "[NAME:btnSim]")
WinWaitActive("Register")
Sleep(1000)
ControlClick("", "", "[NAME:GenerateKey]")
WinWaitActive("Guardar como")
Sleep(1000)
ControlClick("Guardar como", "", 1148)
Sleep(500)
ControlSend("Guardar como", "", "Edit1", $Datanavn)
Sleep(200)
ControlClick("Guardar como", "", "Button2")
Sleep(2000)
WinWaitActive("", "Aceptar")
Sleep(200)
ControlClick("", "", "Button1")
Sleep(200)
WinClose("Register")
Sleep(200)
FileMove("C:\Programfiler\AutoKey\tempdirectorypat\Cashcontrol.dll", "C:\IGS\CAS\Cashcontrol.dll", 0)
Sleep(3000)
Run("C:\IGS\CAS\ControleCaixa1.exe")

;transfers file from desktop to dropbox.
FileMove("C:\Documents and Settings\Administrador\Escritorio\" & $Datanavn & ".txt", "C:\Documents and Settings\Administrador\Mis documentos\Dropbox\patricktest", 1)
Sleep (5000)
Exit

I am wondering if this is a very, very bad way to script. I have written where the popup might show up, and where the popup is expected. Is there a function, command or anything that tells the script to jump to the line where I have prepared a code to expect it, if it pops up? Or should I just copy/paste the script I have made further down in an IF statement. It just doesn't feel like good programming practice.

Link to comment
Share on other sites

I'm not really sure what you are trying to do. Could you please explain in two or thre sentences?

What program do you want to automate? Why do you (sometimes) get a warning window? Is the warning message something you should act upon?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

My company's applications have tons of popups depending on any number of things. What I do, is use ProcessGetWindow, to return ALL windows of the process, and loop through till I find the one that is active, and fulfill it. I've made it much more complex, where I use the array returned to match up against other arrays of possible windows, and then log when windows outside of my array are found.

Func ProcessGetWindow($p_PID, $p_ReturnBestGuess = False)
; #FUNCTION# ============================================================================================================================
; Name...........: WGe_ProcessGetWindow
;
; Description ...: Returns an array of HWNDs containing all windows owned by the process $p_PID, or optionally a single "best guess."
;
; Syntax.........: WGe_ProcessGetWindow( $p_PID [, $p_ReturnBestGuess = False ])
;
; Parameters ....: $p_PID - The PID of the process you want the Window for.
;                $p_ReturnBestGuess - If True, function will return only 1 reult on a best-guess basis.
;                                        The "Best Guess" is the VISIBLE window owned by $p_PID with the longest title.
;
; Return values .: Success   - Return $_array containing HWND info.
;                                    $_array[0] = Number of results
;                                    $_array[n] = HWND of Window n
;
;                Failure     - Returns 0
;
;                Error   - Returns -1 and sets @error
;                                        1 - Requires a non-zero number.
;                                        2 - Process does not exist
;                                        3 - WinList() Error
;
; Author ........: Andrew Bobulsky, contact: RulerOf <at that public email service provided by Google>.
; Remarks .......: The reverse of WinGetProcess()
; =======================================================================================================================================
Local $p_ReturnVal[1] = [0]
Local $p_WinList = WinList()
If @error Then ;Some Error handling
SetError(3)
Return -1
EndIf
If $p_PID = 0 Then ;Some Error handling
SetError(1)
Return -1
EndIf
If ProcessExists($p_PID) = 0 Then ;Some Error handling
ConsoleWrite("WGe_ProcessGetWindow: Process " & $p_PID & " doesn't exist!" & @CRLF)
SetError(2)
Return -1
EndIf
For $i = 1 To $p_WinList[0][0] Step 1
Local $w_PID = WinGetProcess($p_WinList[$i][1])
; ConsoleWrite("Processing Window: " & Chr(34) & $p_WinList[$i][0] & Chr(34) & @CRLF & " with HWND: " & $p_WinList[$i][1] & @CRLF & " and PID: " & $w_PID & @CRLF)
If $w_PID = $p_PID Then
;ConsoleWrite("Match: HWND " & $p_WinList[$i][1] & @CRLF)
$p_ReturnVal[0] += 1
_ArrayAdd($p_ReturnVal, $p_WinList[$i][1])
EndIf
Next
If $p_ReturnVal[0] > 1 Then
If $p_ReturnBestGuess Then
Do
    Local $i_State = WinGetState($p_ReturnVal[2])
    Local $i_StateLongest = WinGetState($p_ReturnVal[1])
    Select
     Case BitAND($i_State, 2) And BitAND($i_StateLongest, 2) ;If they're both visible
     If StringLen(WinGetTitle($p_ReturnVal[2])) > StringLen(WinGetTitle($p_ReturnVal[1])) Then ;And the new one has a longer title
     _ArrayDelete($p_ReturnVal, 1) ;Delete the "loser"
     $p_ReturnVal[0] -= 1 ;Decrement counter
     Else
     _ArrayDelete($p_ReturnVal, 2) ;Delete the failed challenger
     $p_ReturnVal[0] -= 1
     EndIf
     Case BitAND($i_State, 2) And Not BitAND($i_StateLongest, 2) ;If the new one's visible and the old one isn't
     _ArrayDelete($p_ReturnVal, 1) ;Delete the old one
     $p_ReturnVal[0] -= 1 ;Decrement counter
     Case Else ;Neither window is visible, let's just keep the first one.
     _ArrayDelete($p_ReturnVal, 2)
     $p_ReturnVal[0] -= 1
    EndSelect
Until $p_ReturnVal[0] = 1
EndIf
Return $p_ReturnVal
ElseIf $p_ReturnVal[0] = 1 Then
Return $p_ReturnVal ;Only 1 window.
Else
Return 0 ;Window not found.
EndIf
EndFunc ;==>ProcessGetWindow
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I'm not really sure what you are trying to do. Could you please explain in two or thre sentences?

What program do you want to automate? Why do you (sometimes) get a warning window? Is the warning message something you should act upon?

In the commented line ;HERE THE POPUP IS EXPECTED; I have just recently removed a file from the program's installation folder, hence forcing the error to appear. This is good, because it is the only way to get the register program to open is by forcing the error popup.

Where I have commented ;PROBLEM SPOT FOR POPUP; I am trying to get the script to open the CAS program to open and login, because I am trying to find an unique string I can save to a file for future use (instead of using pc name because on almost every pc it has the same name). The problem is that when there is X amounts of days left the program will launch this warning on random occasions (usually everytime you open the program and there is less than a month less, but it's a bit random).

The program I am automating is called CAS, which is a program that is designed to create tickets for our customers so they may play on the slotmachines. Every 6 months they expect a new key code, otherwise they lock up. Call it a serial key for our subscription, if you will.

I will try some clever use with the IF function. I think I may have found a solution. However, is there a different way of doing this? I mean, skipping straight to a specific line in the script upon some condition being true?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...