Wie kann ich aus einer Pid ein Handle machen?

    • Offizieller Beitrag

    Schau dir das an:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $sProcess = "firefox.exe";Hier kann auch das PID eingefügt werden
    $WinInfo = _WinGetInfoByPID(ProcessExists($sProcess))
    _ArrayDisplay($WinInfo)
    $Title = $WinInfo[2][1]
    MsgBox(0, "", $Title)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _WinGetInfoByPID($sPID)
    Local $aPList = ProcessList(), $iPID
    For $iiCount = 1 To $aPList[0][0]
    If $aPList[$iiCount][1] = $sPID Then
    If $sPID = 0 Then Return 0
    $iPID &= $aPList[$iiCount][1] & Chr(01)
    EndIf
    Next
    $iPID = StringSplit($iPID, Chr(01))
    If $iPID = 0 Then Return SetError(1, 0, 0)
    Local $aStoreHwndAndText[2][9], $nCount = 1
    $OptWSC = Opt('WinSearchChildren', 1)
    $OptWDHT = Opt('WinDetectHiddenText', 1)
    Local $aWinList = WinList()
    For $iCount = 1 To $aWinList[0][0]
    For $xCount = 1 To $iPID[0]
    If WinGetProcess($aWinList[$iCount][1]) = $iPID[$xCount] And _
    $aWinList[$iCount][0] <> '' Then
    Local $aWinPos = WinGetPos($aWinList[$iCount][1])
    Local $aWinClient = WinGetClientSize($aWinList[$iCount][1])
    $nCount += 1
    ReDim $aStoreHwndAndText[$nCount][9]
    $aStoreHwndAndText[$nCount - 1][1] = $aWinList[$iCount][0]
    $aStoreHwndAndText[$nCount - 1][2] = $aWinList[$iCount][1]
    $aStoreHwndAndText[$nCount - 1][3] = WinGetText($aWinList[$iCount][1])
    $aStoreHwndAndText[$nCount - 1][4] = $aWinPos[0]
    $aStoreHwndAndText[$nCount - 1][5] = $aWinPos[1]
    $aStoreHwndAndText[$nCount - 1][6] = $aWinClient[0]
    $aStoreHwndAndText[$nCount - 1][7] = $aWinClient[1]
    $aStoreHwndAndText[$nCount - 1][8] = WinGetClassList($aWinList[$iCount][1])
    EndIf
    Next
    Next
    Opt('WinSearchChildren', $OptWSC)
    Opt('WinDetectHiddenText', $OptWDHT)
    If $nCount = 1 Then Return SetError(2, 0, 0)
    Return $aStoreHwndAndText
    EndFunc ;==>_WinGetInfoByPID

    [/autoit]


    Oder das:

    Spoiler anzeigen
    [autoit]

    Run("notepad", "", @SW_HIDE)

    [/autoit] [autoit][/autoit] [autoit]

    Sleep(3000)
    MsgBox(0,"","Notepad versteckt gestartet")

    [/autoit] [autoit][/autoit] [autoit]

    $hwnd = _WinShowByProcessName('notepad.exe',1)
    WinActivate($hwnd)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _WinShowByProcessName()
    ; Description ...: Shows a window by its process name.
    ; Syntax ........: _WinShowByProcessName($sProcessName[, $iInstance = 0])
    ; Parameters ....: $sProcessName - Name of the process.
    ; $iInstance - [optional] Instance of the Window. (default:0)
    ; |0 - All windows
    ; |1 - fist window
    ; |n - n'th window
    ; Return values .: Success
    ; |$iInstance (0) - Returns array of handles which were activated
    ; |$iInstance(1) - Returns handle of the activated window
    ; Failure - Returns 0 and sets @error to
    ; |1 - Could not get process- or winlist
    ; |2 - Error while changed the window's state
    ; |3 - No Match
    ; Author ........: Oscar (WinActivateByProcessName)
    ; Modified ......: Changed by SEuBo
    ; =================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinShowByProcessName($sProcessName, $iInstance = 0)
    Local $aProcessList, $aWinList, $iCnt
    $aProcessList = ProcessList($sProcessName)
    If @error Then Return SetError(1, 0, 0)
    Local $aWinList = WinList(), $iErr, $sHwnd
    If $aWinList[0][0] = 0 Then Return SetError(1, 0, 0)
    For $i = 1 To $aWinList[0][0]
    For $j = 1 To $aProcessList[0][0]
    If WinGetProcess($aWinList[$i][1]) = $aProcessList[$j][1] Then
    $iCnt += 1
    If $iInstance > 0 Then
    If $iCnt = $iInstance Then Return SetError((WinSetState($aWinList[$i][1], "", @SW_SHOW) <> 1) * 2, 0, $aWinList[$i][1])
    Else
    $sHwnd &= "|" & $aWinList[$i][1]
    WinSetState($aWinList[$i][1], "", @SW_SHOW)
    $iErr += @error
    EndIf
    EndIf
    Next
    Next
    If Not $iCnt Then Return SetError(3, 0, 0)
    If $iErr Then Return SetError(2, 0, 0)
    Return SetError(0, $iCnt, StringSplit(StringTrimLeft($sHwnd, 1), "|"))
    EndFunc ;==>_WinShowByProcessName

    [/autoit]