Cynagen Posted May 20, 2009 Share Posted May 20, 2009 (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 May 20, 2009 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. Link to comment Share on other sites More sharing options...
Triblade Posted May 20, 2009 Share Posted May 20, 2009 Works good. Simple, but effective My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger) Link to comment Share on other sites More sharing options...
wraithdu Posted May 20, 2009 Share Posted May 20, 2009 Keep in mind for _Process2Win() that it's almost guaranteed there will be more than one window associated to any given process. Link to comment Share on other sites More sharing options...
weaponx Posted May 20, 2009 Share Posted May 20, 2009 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 Link to comment Share on other sites More sharing options...
Cynagen Posted May 20, 2009 Author Share Posted May 20, 2009 (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.au3Apologies, 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 May 20, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now