Jump to content

RUN and the possibility of existing equal windows


Recommended Posts

Let me begin by applauding the developer(s) of AutoIt: *clap clap*. I just started using it yesterday and am already a big fan!

Problem

A while ago I wrote a vbscript that - among other things - opens an application I work with (let's call it EXAMPLE.EXE). I'm rewriting it in AutoIt and trying to making sure I'm activating the right window, not the ones that possibly already exist. However, all instances share the same windowtitle and classname.

Question

Is the code below a good (failsafe) way to go or is it overdoing it?

$pid = Run("\\server\EXAMPLE.EXE")
For $try = 1 To 20                        ; give the window some time to appear
    Sleep(250)
    $arr = WinList(WinGetTitle("EXAMPLE"))
    $num = $arr[0][0]
    For $win = 1 To $num
        $ttl = $arr[$win][0]
        If WinGetProcess($ttl) == $pid Then ; If this equals our run process id
            $hnd = $arr[$win][1]            ; then we get our unique window handle
            $try = 20                   ; and we're done with trying
            ExitLoop                        ; so we don't have to check the other windows
        EndIf
    Next
Next
If WinActivate($hnd) Then
    Send("{ENTER}")
EndIf

There must be a thread around here somewhere that discusses this, but I couldn't find it between all the help im noob!!1 topics. Anyway, you're help is appreciated.

Edited by solithus
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...