Sign in to follow this  
Followers 0
Akshay07

WinActivate: how to identify the right window when several windows have the same title?

3 posts in this topic

Hello all,

I am facing a problem with the use of WinActivate/WinWaitActive.

Both functions use the title and/or text to identify the window that should be used.

My problem is that I could end up by having several existing windows with exactly the same title (text unknown). I am talking about a Command Prompt window. This is not due to the way the script is made (the script will use only one instance of Command Prompt), I am just trying to consider the use case in which the user would open "manually" another Command Prompt while the script is running.

The script can of course know which PID is associated to the Command Prompt it should use, but I couldn't figure out a way to use the PID to identify a specific window that can be used with WinActivate/WinActive function.

One solution I though of was to disable the possibility of starting the same program manually while the script is running but:

1/ I have no idea how to do that

2/ I would prefer to use a solution that does not give any limitation to the user

Any direction to where to look at would be very welcome!

Thanks.

Share this post


Link to post
Share on other sites



You can use the pid returned by Run to identify it and you can set the title to identify it.

Func m1()

    $pid = Run("cmd", @scriptDir, @SW_SHOWNORMAL, $STDIN_CHILD + $STDOUT_CHILD)
    StdinWrite($pid, "title somethingunique876" & @CRLF);set the title
    sleep(4000);time to let you see the title
    StdinWrite($pid, "dir" & @CRLF)

    StdinWrite($pid, "exit" & @CRLF)
    While 1
    $line = $line & StdoutRead($pid)
    If @error Then ExitLoop
    WEnd

    MsgBox(0, "Stdout", $line)
    ProcessClose($pid)

EndFunc ;==>m1

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Martin, you are (as often) my savior :mellow:

Your example works like a charm. I need to work on it to adapt it to my script, but this is perfect!

Thank you very much :(

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  
Followers 0