Sign in to follow this  
Followers 0
smashly

How to get the Title assosciated with a PID?

8 posts in this topic

Is there an easy way to get the associated win Title or classname from an executed files PID ?

WinGetProcess gives the PID associated with a Window Title , classname or handle.

But how do I do it the other way round when I don't know what the window will be and I know the executable that will be run?

Hope this question makes sense ...lol

tyia for any assistance

cheers.

Share this post


Link to post
Share on other sites



Is there an easy way to get the associated win Title or classname from an executed files PID ?

WinGetProcess gives the PID associated with a Window Title , classname or handle.

But how do I do it the other way round when I don't know what the window will be and I know the executable that will be run?

Hope this question makes sense ...lol

tyia for any assistance

cheers.

I've made functions to do both, you could start by searching the few posts I've ever made :P

[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

Thank you for the lightnig fast response :P

It's greatly appreciated.

but sifting through 6,453 of your posts with not a mention of a name or keyword to your created functions is not my Idea of "an easy way " to find a solution.

Looks like I'll just do the learning curve thing once again..lol

Good part of of your answer shows me that it's not a straight out function I'm overlooking in the Help file...All Good.

Cheers all the same :nuke:

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this just gets the title of the first ie window found

tried to get title from mozilla (MozillaWindowClass) but it doesn't work

AutoItSetOption("WinTitleMatchMode", 4)

$handle = WinGetHandle("classname=IEFrame")
$title = WinGetTitle($handle)
MsgBox(0, "Full title read was:", $title)

use "AutoIt Window Info" to get the classname of the program you want to get title of

Edited by CWorks

Share this post


Link to post
Share on other sites

Yep CWorks I can get a handle , title or classbame providing I know the executable I'm launching , but in this case I'm it could be any executable I may be launching. So the only definate thing I have is the PID for the run process.

What I need to find is a way to find the classname or Title or handle that's associated with the PID.

nvm , I'll work it out eventually , no biggy.

Cheers for the help all the same. :P

Share this post


Link to post
Share on other sites

Is there an easy way to get the associated win Title or classname from an executed files PID ?

You can look at the help file for ProcessExists or ProcessList.

EX: NotePad.exe

If you know it is a single process running

$PID = ProcessExists("notepad.exe")
If $PID <> 0 Then
    MsgBox(0, "Example", "Notepad is running." & @CRLF & 'PID: ' & $PID)
EndIf
oÝ÷ Øêâ*.«Þém^²Æ¦zèqë,®éçxºÚ"µÍÌÍÛÝHØÙÜÓÝ
    ][ÝÛÝY^I][ÝÊBÜ    ÌÍÚHHHÈ ÌÍÛÝÌVÌBÙØÞ
    ÌÍÛÝÉÌÍÚWVÌK   ÌÍÛÝÉÌÍÚWVÌWJB^

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You can look at the help file for ProcessExists or ProcessList.

EX: NotePad.exe

If you know it is a single process running

$PID = ProcessExists("notepad.exe")
If $PID <> 0 Then
    MsgBox(0, "Example", "Notepad is running." & @CRLF & 'PID: ' & $PID)
EndIf
oÝ÷ Øêâ*.«Þém^²Æ¦zèqë,®éçxºÚ"µÍÌÍÛÝHØÙÜÓÝ
    ][ÝÛÝY^I][ÝÊBÜ    ÌÍÚHHHÈ ÌÍÛÝÌVÌBÙØÞ
    ÌÍÛÝÉÌÍÚWVÌK   ÌÍÛÝÉÌÍÚWVÌWJB^oÝ÷ Ûú®¢×ºsë¡Ç¬°¸¬·­­¥ªÚë^®Æ§v+pYeËZZk¡Ç¬±ëÛaêÏ ;éìyªÜØ^jºÚÉú+¶

Cheers!

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Or you can just take CWorks a step further

If _FindExeWin('my.exe') Then
    MsgBox(64, 'Info', 'The window PID matched the exe PID')
EndIf

Func _FindExeWin($sExe)
    $OptWTMM = Opt('WinTitleMatchMode', 4)
    Local $iWPID = WinGetProcess(WinGetHandle('classname=IEFrame'))
    Opt('WinTitleMatchMode', $OptWTMM)
    Local $iPID = ProcessExists($sExe)
    If $iWPID = $iPID Then Return 1
    Return SetError(1, 0, 0)
EndFuncoÝ÷ ØGb´êâ*.Á©íz÷§ÞuëZWwèÂ+a¢ëd"ayì^©jëh×6
$ArrayGetInfo = _ReturnExe2Win()
If IsArray($ArrayGetInfo) Then
    MsgBox(64, 'Info', _
    'Window Title = ' & $ArrayGetInfo[0] & @CR & _
    'Process owning window name = ' & $ArrayGetInfo[1] & @CR & _
    'Process owning window PID = ' & $ArrayGetInfo[2])
EndIf

Func _ReturnExe2Win()
    Local $aPList = ProcessList(), $aReturn[3]
    $OptWTMM = Opt('WinTitleMatchMode', 4)
    Local $sTitle = WinGetTitle('classname=IEFrame')
    Local $iWPID = WinGetProcess(WinGetHandle($sTitle))
    Opt('WinTitleMatchMode', 4)
    For $iCC = 1 To $aPList[0][0]
        If $aPList[$iCC][1] = $iWPID Then
            $aReturn[0] = $sTitle
            $aReturn[1] = $aPList[$iCC][0]
            $aReturn[2] = $aPList[$iCC][1]
            Return $aReturn
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc
Will return the window name/exe name/exe PID

Edit2:

Had a 2 Dim array when there was no need for it, I think I set out to return multiple windows and multiple functions but settled for just the one... who knows!

Edited by SmOke_N

[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

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