Jump to content

Constant check through out a script if a certain window is active


Recommended Posts

As the title say, i want a script that runs a certain task in chrome but if chrome where to shut down before the script finished i want it to relaunch chrome and start from the beginning. so i tried something like this

i have a "winexists" function that check if the window exist and then

while 1
If $winexist = 0 Then
LaunchChrome()
EndIf
WEnd

But what happens is that if i were to shut down chrome it keeps going through the script and once it's finished it starts chrome again.

I want it to stop where it's at and relaunch chrome(if chrome where to be shut down that is) and start over again. anyone think they can help? :>

Link to comment
Share on other sites

Can you post the whole script? Function WinExists and how you call it?

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

WinActivate("Google - Google Chrome")
$winexist = WinExists("Google - Google Chrome")
Global $winexist
HotKeySet("{F9}", "end")

click()

while 1
If $winexist = 0 Then
LaunchChrome()
EndIf
WEnd

func Click()
MouseClick("left",142,389,1)
MouseMove(502,691)
MouseDown("left")
MouseMove(503,691)
MouseUp("left")
MouseMove(1119,558)
MouseDown("left")
MouseMove(1120,557)
MouseUp("left")
MouseClick("left",1017,295,1)
MouseMove(691,760)
MouseDown("left")
MouseMove(683,764)
MouseUp("left")
MouseMove(206,410)
MouseDown("left")
MouseMove(203,404)
MouseUp("left")
MouseMove(1407,57)
MouseDown("left")
MouseMove(1408,57)
MouseUp("left")
MouseMove(767,820)
MouseDown("left")
MouseMove(762,812)
MouseUp("left")
Send("{ALTDOWN}{ALTUP}")
EndFunc

Func LaunchChrome()
ShellExecute("chrome.exe")
WinActivate("Ny Flik - Google Chrome")
MouseClick("left",190,50,1)
sleep(2000)
Send("www.google.se{ENTER}")


sleep(2000)
click()
EndFunc



Func end()
ToolTip('Closing...')
Sleep(500)
ToolTip("")
Exit
EndFunc

Edited by Sulfuri
Link to comment
Share on other sites

$winexist is only set at the start of the script. You'll have to do the window check in the While loop.

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

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