Jump to content

Activate one window after another, but the windows have the same name/title


Recommended Posts

Hello

I have a number of command windows opened by 

Run("C:\Windows\System32\cmd.exe")

I want to activate each window one after another.

I can't use winactivate since they have the same title/name.

How do I do it ?

 

Thank you for your responses

Link to post
Share on other sites

With this code https://www.autoitscript.com/forum/topic/19370-autoit-wrappers/?do=findComment&comment=417610

by @Valuater you can address your command boxes by preserving the PIDs, when launching them:

 

#include <MsgBoxConstants.au3>
Dim $aPIDs[4]=[3]

for $i = 1 to $aPIDs[0]
    $aPIDs[$i]=Run("C:\Windows\System32\cmd.exe")
Next


for $i = 1 to $aPIDs[0]
    $hWin=_WinGetHandleByPID($aPIDs[$i],-1)
    WinActivate($hWin)
    MsgBox($MB_TOPMOST, '', "Activated #" & $i & " with PID " & $aPIDs[$i])
Next




Func _WinGetHandleByPID($vProc, $nVisible = 1)
    $vProc = ProcessExists($vProc);
    If Not $vProc Then Return SetError(1, 0, 0)
    Local $aWL = WinList()
    Local $aTemp[UBound($aWL)][2], $nAdd = 0
    For $iCC = 1 To $aWL[0][0]
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then
            $nAdd += 1
            $aTemp[$nAdd][0] = $aWL[$iCC][0]
            $aTemp[$nAdd][1] = $aWL[$iCC][1]
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then
            $nAdd += 1
            $aTemp[$nAdd][0] = $aWL[$iCC][0]
            $aTemp[$nAdd][1] = $aWL[$iCC][1]
        ElseIf $nVisible > 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then
            $nAdd += 1
            $aTemp[$nAdd][0] = $aWL[$iCC][0]
            $aTemp[$nAdd][1] = $aWL[$iCC][1]
        EndIf
    Next
    If $nAdd = 0 Then Return SetError(2, 0, 0);No windows found
    ReDim $aTemp[$nAdd + 1][2]
    $aTemp[0][0] = $nAdd
    Return $aTemp
EndFunc

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...