Jump to content
Sign in to follow this  
MrSheen

Terminate Script if program closes

Recommended Posts

MrSheen

Hello

I've been using the below script to always answer a pop-up box, just cant seem to get it to terminate as soon as program (installrite.exe) closes.

Run("C:\Program Files\Epsilon Squared\InstallRite\InstallRite.exe")
If $CmdLine[0] = 1 and $CmdLine[1] = '/QUIT' Then
    WinClose('InstallRite')
Else
    AutoItWinSetTitle('InstallRite')

    While 1=1
        WinWait("InstallRite 2.5c","Are you sure you wan")
        Send("{ENTER}")
    WEnd
EndIf

Tried to include (If ProcessExists),(If ProcessWaitClose),(If WinExists) and Sleep etc but the script does not terminate when the program is closed.

Any pointers would be appreciated.

Thanks

Share this post


Link to post
Share on other sites
prunesquallor

If I understand correctly, once your script enters:

While 1=1 
  WinWait("InstallRite 2.5c","Are you sure you wan") 
  Send("{ENTER}") 
WEnd

the script will never leave the loop. If you only expect the popup once, you could try:

WinWaitActive(("InstallRite 2.5c","Are you sure you wan") 
Send("{ENTER}")

Once the script has answered, it can drop through and exit.

ATB

Prune

Share this post


Link to post
Share on other sites
MrSheen

The program asks "do you want to delete?" all the time (so much, they should have had a option to turn that annoying box off), so that script works very well for that purpose but just cant get it to close when the program finishes being used.

Thanks for replying

Edited by MrSheen

Share this post


Link to post
Share on other sites
sahsanu

The program asks "do you want to delete?" all the time (so much, they should have had a option to turn that annoying box off), so that script works very well for that purpose but just cant get it to close when the program finishes being used.

Thanks for replying

Did you try to change 1=1 to ProcessExists("InstallRite.exe")?

While ProcessExists("InstallRite.exe")
        WinWait("InstallRite 2.5c","Are you sure you wan")
        Send("{ENTER}")
WEnd

Regards,

sahsanu

Share this post


Link to post
Share on other sites
MrSheen

Replaced 1=1 to ProcessExists("InstallRite.exe") and script was still running after installrite was close, so tried the other one you posted but again script does not close when installrite.exe closes.

Share this post


Link to post
Share on other sites
sahsanu

Replaced 1=1 to ProcessExists("InstallRite.exe") and script was still running after installrite was close, so tried the other one you posted but again script does not close when installrite.exe closes.

If Process exists then it will wait till window "InstallRite 2.5c" will active, if the process ends when it is waiting your program won't close. Sorry but I'm leaving now so I cannot provide a working script to you, I'll be back later.

Share this post


Link to post
Share on other sites
Juvigy

Run("C:\Program Files\Epsilon Squared\InstallRite\InstallRite.exe")
If $CmdLine[0] = 1 and $CmdLine[1] = '/QUIT' Then
    WinClose('InstallRite')
Else
    AutoItWinSetTitle('InstallRite')
    While ProcessExists("InstallRite.exe")<>0
        WinWait("InstallRite 2.5c","Are you sure you wan")
        Send("{ENTER}")
    WEnd
EndIf

Edited by Juvigy

Share this post


Link to post
Share on other sites
sahsanu

The program asks "do you want to delete?" all the time (so much, they should have had a option to turn that annoying box off), so that script works very well for that purpose but just cant get it to close when the program finishes being used.

Ok, try this "while", this should works:

While ProcessExists("InstallRite.exe")
   If WinExists("InstallRite 2.5c","Are you sure you wan") Then
      WinActivate("InstallRite 2.5c","Are you sure you wan"); Just to be sure that you get the focus to send the enter
      Send("{ENTER}") 
      Sleep(100)
   Else
      Sleep(100)
   EndIf
WEnd

Share this post


Link to post
Share on other sites
Richard Robertson

Run("C:\Program Files\Epsilon Squared\InstallRite\InstallRite.exe")
If $CmdLine[0] = 1 and $CmdLine[1] = '/QUIT' Then
    WinClose('InstallRite')
Else
    AutoItWinSetTitle('InstallRite')
    While ProcessExists("InstallRite.exe")<>0
        If WinWait("InstallRite 2.5c","Are you sure you wan", 1) Then Send("{ENTER}")
    WEnd
EndIf

The problem is that the script was stopping on WinWait after the program was gone. Timeouts solve this.

Share this post


Link to post
Share on other sites
norax

Hey man im not sure if everyone else missunderstood you or if i did lol but give this a try and let me know if it helps

Run("C:\Program Files\Epsilon Squared\InstallRite\InstallRite.exe")
If $CmdLine[0] = 1 and $CmdLine[1] = '/QUIT' Then
    $pid = ProcessExists("InstallRite.exe")
    ProcessClose($pid)
Else
    AutoItWinSetTitle('InstallRite')
    While 1
        if WinActive("InstallRite 2.5c","Are you sure you wan") = 1 Then
            Send("{ENTER}")
            Sleep(1000)
        Else
            $pid = ProcessExists("InstallRite.exe")
            if $pid = 0 then
                exit
            EndIf
        EndIf
    WEnd
EndIf
Edited by norax

Share this post


Link to post
Share on other sites
MrSheen

The last three are great, thank you guys for your assistance.

:mellow:

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.