#include'winapiex.au3'
$run=Run('notepad.exe'); запускаем искомую программу
ProcessWait('notepad.exe',20)
$ha=_WinAPI_EnumProcessWindows($run); это определяет handle
MsgBox(0,'',$ha[1][0])
$nPID = Run('notepad.exe')
ProcessWait($nPID)
$hWnd = _Process2Handle($nPID)
MsgBox(0, 'Handle', $hWnd)
func _Process2Handle($pid)
if isstring($pid) then $pid = processexists($pid)
if $pid = 0 then return -1
$list = WinList()
for $i = 1 to $list[0][0]
if $list[$i][0] <> "" AND BitAnd(WinGetState($list[$i][1]),2) then
$wpid = WinGetProcess($list[$i][0])
if $wpid = $pid then return $list[$i][1]
EndIf
next
return -1
endfunc
а их и так не одно ..одно видим, другие в скрытом режиме. у всех есть дескрипторы..А если окно не одно
#include <WinAPI.au3>
#include <Array.au3>
$sFileExe = @WindowsDir & '\notepad.exe'
$sProcess = StringRegExpReplace($sFileExe, '^.*\\', '')
$iCount = 0
If Not ProcessExists($sProcess) Then
Run($sFileExe)
EndIf
$iPID = ProcessWait($sProcess, 5)
If Not $iPID Then
MsgBox(16, 'Error', 'Error')
Exit
EndIf
$aList = WinList()
If Not $aList[0][0] Then
MsgBox(16, 'Error', 'Error')
Exit
EndIf
Dim $aResult[$aList[0][0] + 1][4]
For $i = 1 To $aList[0][0]
If WinGetProcess($aList[$i][1]) = $iPID Then
$iCount += 1
$aResult[$iCount][0] = $aList[$i][0] ;Title
$aResult[$iCount][1] = $aList[$i][1] ;Handle
$aResult[$iCount][2] = _WinAPI_GetClassName($aList[$i][1]);ClassName
If BitAND(WinGetState($aList[$i][1]), 2) Then
$aResult[$iCount][3] = 'visible'
Else
$aResult[$iCount][3] = 'hide'
EndIf
EndIf
Next
If $iCount Then
ReDim $aResult[$iCount + 1][4]
$aResult[0][0] = $iCount
_ArrayDisplay($aResult, 'Все окна процесса ' & $sProcess)
MsgBox(0,'',$aResult[1][1]); тут как раз то, что надо
Else
MsgBox(16, 'Error', 'Error')
EndIf
$iPID = Run(@WindowsDir & "\Notepad.exe")
$hNotepad = _WinWaitByPID($iPID)
MsgBox(64, 'Title', WinGetTitle($hNotepad))
Func _WinWaitByPID($iPID, $iWaitTime = -1)
Local $iTimer = TimerInit()
Local $aWinList
While 1
$aWinList = WinList()
For $i = 1 To $aWinList[0][0]
If WinGetProcess($aWinList[$i][1]) = $iPID And BitAND(WinGetState($aWinList[$i][1]), 2) Then
Return $aWinList[$i][1]
EndIf
Next
If $iWaitTime > 0 And TimerDiff($iTimer) >= $iWaitTime * 1000 Then ExitLoop
WEnd
Return 0
EndFunc
В справке написано:посмотрите в справке
Эта функция является единственной из раздела функций "Процессы" не принимающая PID в качестве параметра "process". Поскольку PID распределяются случайным образом, ожидать процесс с конкретным PID не имеет смысла.
#Include <Array.au3>
#Include <WinAPIEx.au3>
$list = ProcessList("notepad.exe")
for $i = 1 to $list[0][0]
$Data=_WinAPI_EnumProcessWindows($list[$i][1], 1)
_ArrayDisplay($Data)
next
MsgBox(0,'',$Data[1][0])
Для ожидания окна по PID, возвращает Handle, заголовок получается через WinGetTitle.твой скрипт я так понял для получения заголовка?
Так мне же не pid explorer'a нужен, а handle окна.Если при shellexecute у тебя вызывается проводник, то зачем мучаться? используй
#include <WinAPIEx.au3>
$iPID = Run("Explorer.exe C:\")
ProcessWaitClose($iPID)
$aProcs = ProcessList("Explorer.exe")
$sWin = ''
For $i = 1 To UBound($aProcs)-1
$aWins = _WinAPI_EnumProcessWindows($aProcs[$i][1])
For $j = 1 To UBound($aWins)-1
If $aWins[$j][1] = 'CabinetWClass' Then
$sWin = WinGetTitle($aWins[$j][0])
EndIf
Next
Next
MsgBox(64, 'Title', $sWin)
#include <Array.au3>
$aWins1 = WinList('[CLASS:CabinetWClass]')
$iPID = Run("Explorer.exe C:\")
ProcessWaitClose($iPID)
While 1
$aWins2 = WinList('[CLASS:CabinetWClass]')
If $aWins2[1][0] <> 'Проводник' Then ExitLoop
WEnd
For $i = 1 To UBound($aWins2)-1
If _ArraySearch($aWins1, $aWins2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then
MsgBox(64, 'Title', $aWins2[$i][0])
ExitLoop
EndIf
Next