briankyncl

Case Structure for WinExists()

4 posts in this topic

#1 ·  Posted

Hello, I have an in-house app installation that I'm attempting to script. It lacks any silent install parameters so I'm stuck scripting GUI interactions. A predecessor of mine used a series of WinWaitActive() to click through the installation wizard but I would like to do this with a case structure so that the interaction is (slightly) more robust. Basically reacting to a specific window when it appears, no matter when it appears, all while the setup.exe process is still running.

Something like this:

Func watchSetupExe()
    While ProcessExists("setup.exe")
        Switch WinExists()
            case ("Window Title", "some identifying text")
                ControlClick("Window Title", "some identifying text", "[CLASS:Button; INSTANCE:4]")
            case ("Window Title", "different identifying text")
                ControlClick("Window Title", "different identifying text", "[CLASS:Button; INSTANCE:2]")
        EndSwitch
    WEnd
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

@briankyncl take a look at AdLibRegister in the help file, with it you can point to a function and have it continually check that function every x ms.

Regarding the Switch, since WinExists cannot be called without at least one arg, look at either an If>>ElseIf statement or a Select statement:

Select
    Case WinExists("Notepad1", "")
        ;Do X
    Case WinExists("Notepad2", "")
        ;Do Y
    Case WinExists("Notepad3", "")
        ;Do Z
EndSelect

Lastly, if this in-house app is difficult to manage the install of, I would suggest employing Wix or equivalent to repackage the application into an MSI. Then you can set your configurations once and forget about them.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

@JLogan3o13 thanks for your example. Select>Case was the structure I was needing. I see now even If>ElseIf would've worked. I ended up monitoring the running process elsewhere.

I am running the "watcher" script as a separate executable but I think I see how I could use AdLibRegister instead, and keep everything in one. I use ShellExecuteWait() to start setup.exe and it looks like this would pause AdLibRegister, correct?

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Actually the other way around, AdLibRegister runs the function every x milliseconds, and the body of your script is paused during its execution. So ensure you keep the function you're calling simple (a WinExists Select or If statement is sufficiently quick) and watch the time on the AdLibRegister call so as not to overwork the CPU.


√-1 2^3 ∑ π, and it was delicious!

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