Sign in to follow this  
Followers 0
Cynagen

Window Title <-> Process Name/ID

5 posts in this topic

#1 ·  Posted (edited)

; Window to Process
; Now making Window name and executables/PIDs interchangable!
; Credit to Cynagen
func _Win2Process($wintitle)
    if isstring($wintitle) = 0 then return -1
    $wproc = WinGetProcess($wintitle)
    return _ProcessName($wproc)
endfunc
func _Process2Win($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][0]
        EndIf
    next
    return -1
endfunc
func _ProcessName($pid)
    if isstring($pid) then $pid = processexists($pid)
    if not isnumber($pid) then return -1
    $proc = ProcessList()
    for $p = 1 to $proc[0][0]
        if $proc[$p][1] = $pid then return $proc[$p][0]
    Next
    return -1
EndFunc

I whipped this up in response to finding and correctly identifying windows for process names. It's from my MSNStatus project. It is able to successfully identify the title of a window for a process under Vista, including Valve's Source based games/mods. Figured this might be handy to somebody else, I'm just glad I have it now. If anyone finds it particularly handy, I was thinking of maybe submitting it for official UDF inclusion to the next release of AutoIt. Lemme know. ;-)

Edited by Cynagen

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

Share this post


Link to post
Share on other sites



Keep in mind for _Process2Win() that it's almost guaranteed there will be more than one window associated to any given process.

Share this post


Link to post
Share on other sites

These functions have already been created a few times, and we already have _ProcessGetName included with AutoIt.

http://www.autoitscript.com/fileman/users/Helge/udfs/_ProcessGetHWnd.au3

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Keep in mind for _Process2Win() that it's almost guaranteed there will be more than one window associated to any given process.

This script picks only the most recently active & visible window, so it's likely to be more accurate in it's choice, however I have seen a few misfires.

These functions have already been created a few times, and we already have _ProcessGetName included with AutoIt.

http://www.autoitscript.com/fileman/users/Helge/udfs/_ProcessGetHWnd.au3

Apologies, I didn't check the UDF list in the help file right away when I was writing this, I didn't think it would be there (lot of stuff I cooked up before wasn't there), but to be fair I did include other functions here. Only one of which is superseded by the function you mentioned. Edited by Cynagen

Blah, blah, blah... lip service... lip service.Working on a number of projects right now, just waiting for my time to post them here on AutoIt forums.

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