Qvintus Posted June 28, 2011 Share Posted June 28, 2011 Hello I was wondering if it's possible to get the hwnd using PID? Currently I found: WinList - Though this requires the window name, wich could be the same for 2 instances in some situations. ProcessList - Can return PID but not hwnd WinGetHandle - Requires window name again Anything I have overlooked for now? Or is ther some sort of bypass somewhere? Basicly I want to finde the hwnd using a ProcessList where 2 windows mostly will have the same name, meaning I can't finde it using the window name. Any ideas? Link to comment Share on other sites More sharing options...
JoHanatCent Posted June 28, 2011 Share Posted June 28, 2011 Hello I was wondering if it's possible to get the hwnd using PID?Currently I found:WinList - Though this requires the window name, wich could be the same for 2 instances in some situations.ProcessList - Can return PID but not hwndWinGetHandle - Requires window name againAnything I have overlooked for now? Or is ther some sort of bypass somewhere?Basicly I want to finde the hwnd using a ProcessList where 2 windows mostly will have the same name, meaning I can't finde it using the window name.Any ideas?WinList()&WinGetProcess() Link to comment Share on other sites More sharing options...
Qvintus Posted June 28, 2011 Author Share Posted June 28, 2011 I already know how to get PID, I need to use the PID to somehow get the hwnd. If I can use WinList for that then please explain a little more of what parameter it should be in. Also if I should use "[PID:" & $pid &"]" or something wiered like that? Link to comment Share on other sites More sharing options...
MvGulik Posted June 28, 2011 Share Posted June 28, 2011 (edited) WinGetProcess()---To be used on your hwnd's from winlist to see if its the PID your looking for.But, this can return multiple matches, as a process can have multiple windows. so some additional window title information is probably needed to make sure you get the one your after.---See example in next message. Edited June 28, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
JoHanatCent Posted June 28, 2011 Share Posted June 28, 2011 I already know how to get PID, I need to use the PID to somehow get the hwnd. If I can use WinList for that then please explain a little more of what parameter it should be in. Also if I should use "[PID:" & $pid &"]" or something wiered like that? Just an Example: Global $PID2 = "" $Amow = 100 $hWnd2 = "" $aPID = Run("Notepad.exe") Sleep($Amow) $theWinlist = Winlist() Do For $i = 1 To $theWinlist[0][0] If $theWinlist[$i][0] <> "" Then $iPID2 = WinGetProcess($theWinlist[$i][1]) If $iPID2 = $aPID Then $hWnd2 = $theWinlist[$i][1] ExitLoop EndIf EndIf Next Until $hWnd2 <> 0 MsgBox(0, "Handle is", $hWnd2) WinClose($hWnd2) VenusProject2 1 Link to comment Share on other sites More sharing options...
Qvintus Posted June 28, 2011 Author Share Posted June 28, 2011 (edited) Thx for your replys but I ended out using the WinAPIEx.au3 _WinAPI_EnumProcessWindows(PID) Post I found it in: Edited June 28, 2011 by Qvintus MONaH-Rasta 1 Link to comment Share on other sites More sharing options...
Baporing Posted February 12, 2012 Share Posted February 12, 2012 Perfect code, JoHanatCent. As long as there is only one exe with that name, it works on everything I tried 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