Sign in to follow this  
Followers 0
MadSc13ntist

Finding A Window Title If You Know The Processname/pid

5 posts in this topic

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)

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.

:)

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


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
Sign in to follow this  
Followers 0