Jump to content

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


Akshay07
 Share

Recommended Posts

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.

Link to comment
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.
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...