Jump to content

Recommended Posts

Posted

I was wondering if anyone had come across a way to find the title of a window if you know the pid and/or the process name?

I've been scratching my head on this one for a bit and figured i'd ask around.

Thanks for any help one might be able to lend me.

p.s. If there is a way i will post in the idea lab _ProcessGetWinTitle() ???

#NoTrayIcon
#include <Process.au3>

Opt('WinTitleMatchMode', 2)

If $CmdLine[0] < 1 Then Exit

Global $programpath = $CmdLine[1]
Global $pid = Run($programpath)
Global $process = _ProcessGetName($pid)
Posted

I was wondering if anyone had come across a way to find the title of a window if you know the pid and/or the process name?

I've been scratching my head on this one for a bit and figured i'd ask around.

Thanks for any help one might be able to lend me.

p.s. If there is a way i will post in the idea lab _ProcessGetWinTitle() ???

The only thing I can think of is doing a WinList and then a WinGetProcess for all of the open windows. Then you can match up the process names to the process you have running. Then you will know which window matches which process.

Hope this helps.

Posted

Just made for the task

$pid = 5568; A Known PID for example

$array = WinList()
If IsArray($array) Then
    $title = ''
    For $i = 1 To UBound($array)-1
        $winpid = WinGetProcess($array[$i][0])
        If $winpid = $pid Then
            $title = $array[$i][0]
            ExitLoop
        EndIf
    Next
EndIf
MsgBox(0, '', $title)

Uses WinGetProcess to loop through until a match of PID, then uses the title that the match succeeded with.

:)

  • Moderators
Posted

Or

MsgBox(0, '', _ProcessGetWin('notepad.exe'))

Func _ProcessGetWin($aPID, $i_ReturnArray = 0)
    Local $aWinList = WinList()
    Local $aReturnValue = ''
    $aPID = ProcessExists($aPID)
    For $icount = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$icount][0]) = $aPID And BitAND($aWinList[$icount][1], 2) = 2 Then
            $aReturnValue = $aWinList[$icount][0] & @LF
        EndIf
    Next
    If $i_ReturnArray = 0 Then 
        Return $aReturnValue
    ElseIf $i_ReturnArray = 1 Then
        Return StringSplit(StringTrimRight($aReturnValue, 1), @LF); Returns an Array
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

The only thing I can think of is doing a WinList and then a WinGetProcess for all of the open windows. Then you can match up the process names to the process you have running. Then you will know which window matches which process.

Hope this helps.

Smoke_N wrote something up for this a while back (not sure if he'd posted it, but i remember him talking about it) and i want to say that he did it the way you're suggesting SK. something to the effect of:

$pid = Run("Notepad.exe")
$list = WinList()
Dim $TheTitle
for $x = 1 to $list[0][0]
    If WinGetProcess($list[$x][0]) = $pid Then 
        $TheTitle = $list[$x][0]
        MsgBox(0,"title",$TheTitle)
        ExitLoop
    EndIf
Next

***edit** haha, in the time it took for me to try to re-create smoke's code, he put something else up. bastard.

Edited by cameronsdad

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...