Jump to content

if WinExists, WinActivate, and ControlClick problem


Recommended Posts

Hello, and thank you in advance. This is my first post.. I decided to try after searching existing posts (and the internet) with no luck.

I am writing a simple script that uninstalls then reinstalls an app by running through unwise.exe

The problem I have arises on machines during the uninstall process. As part of the uninstaller process, some of the workstations have a window that appears asking if I want to "Remove Shared Components". If the window appears, I simply want to click "Yes to all" so my script can continue running. I have spend quite a bit of time tweaking the script, but I only get one chance to test per machine I have. The second time I uninstall, I do not get the "Remove Shared Component" screen. My script executes flawlessley when this screen does not appear, I am just missing something on this one particular window. Here is the portion of code I have been working with.

CODE

If WinExists("Remove Shared Component", "The system indicates that the following") = 1 Then

WinActivate("Remove Shared Component", "The system indicates that the following")

WinWaitActive("Remove Shared Component", "The system indicates that the following")

ControlClick("Remove Shared Component", "The system indicates that the following", 1007)

EndIf

My script ALWAYS stalls here (if the window appears). Can anyone offer suggestions? I just need to know if anyone may know why it is not clicking the "Yes to all" button.

From Window Info:

ControlID: 1007

ClassNameNN: Button4

Text: Yes &to All

Thank you. I will be happy to provide more info if needed.

Link to comment
Share on other sites

The only place that this code could hang is the WinWaitActive line. Have you tried it without it? You can set a timer on the WinWait line, so you still have a delay. You could also set up a loop with WinExists() cases to select between different windows at the same time.

Link to comment
Share on other sites

Thanks for the ideas.

I have been messing around with this off and on for awhile. I have tried several variations, from simply:

CODE
If WinExists("Remove Shared Component", "The system indicates that the following") Then

ControlClick("Remove Shared Component", "The system indicates that the following", 1007)

EndIf

I have been adding to the above code thinking maybe the problem was the window being "out of focus" for a lack of better terms. I took your suggestion and removed the WinWaitActive, then replaced it with a WinWait that has a 5 sec wait. Same results, no luck. :D

The window appears immediately and appears to be active, it just won't click for me. If I click "Yes to all" manually, the script picks right back up and finishes. I am pretty new to Autoit, so it has been more trial and error than anything up to this point.

Link to comment
Share on other sites

Without a loop to keep the program running your script might have finished before the expected window existed.

Maybe isolate your controlclick to verify that it will work for you manually

HotKeySet("{ESC}", "_Terminate")
HotKeySet("{F7}", "_DoSomething")

While 1
    Sleep(100) ; usually a good idea to put this in so you dont max your cpu
    ToolTip("Press F7 to activate, or ESC to Quit")
WEnd

Func _Terminate()
    Exit 0
EndFunc   ;==>_Terminate

Func _DoSomething()
    ControlClick("Remove Shared Component", "The system indicates that the following", 1007)
EndFunc   ;==>_DoSomething

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

First off see if the thing can correctly find the control remember you can use different methods for looking up the control. ControlID is one of them as well as ClassNameNN.

HotKeySet("{ESC}", "_Terminate")
HotKeySet("{F7}", "_DoSomething")

While 1
    Sleep(100) ; usually a good idea to put this in so you dont max your cpu
    ToolTip("Press F7 to activate, or ESC to Quit")
WEnd

Func _Terminate()
    Exit 0
EndFunc   ;==>_Terminate

Func _DoSomething()
    $hHandle = WinGetHandle("Remove Shared Component", "The system indicates that the following")

    If WinExists($hHandle) Then
        If WinActivate($hHandle) Then WinWaitActive($hHandle, , 5) ; not sure why you need this if you are controlclick-ing
        $hControlHandle = ControlGetHandle($hHandle, "", "[ID:1007")
        If @error Then
            MsgBox(0, "Error", "Cannot find the control with ID:1007")
            Exit 0
        EndIf
        ControlClick($hHandle, , $hControlHandle)
    EndIf
EndFunc   ;==>_DoSomething

I used SpookMeister layout

Edited by TerarinK

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

I was able to verify that my ControlClick is working correctly. This single line clicked the button when I executed it (after the window was open):

ControlClick("Remove Shared Component", "The system indicates that the following", 1007)

I should have included the entire code in my original post, my question probably would have made more sense. This may paint a clearer picture, some details have been replaced with XXXX.

CODE
run("c:\XXXXXX\unwise.exe")

WinWait("Select Uninstall Method")

ControlClick("Select Uninstall Method","Welcome to the XXXXXXX", 1)

WinWait("Perform Rollback")

ControlClick("Perform Rollback","You selected to backup files that were", 1)

WinWait("Perform Uninstall")

ControlClick("Perform Uninstall", "You are now ready to uninstall", 1)

If WinExists("Remove Shared Component", "The system indicates that the following") = 1 Then

WinActivate("Remove Shared Component", "The system indicates that the following")

WinWait("Remove Shared Component", "The system indicates that the following", 5)

ControlClick("Remove Shared Component", "The system indicates that the following", 1007)

EndIf

WinWaitClose("Perform Uninstall")

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