Jump to content

Case Structure for WinExists()


Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@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?

 

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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