'How to get the Window handle (hwnd) by Executable path or name?
Is there a way to get the hwnd-object from a specific window by only providing the executable path or name?
Like GetForegroundWindow() from win32gui but not just the foreground window.
Id imagine something like this: GetWindowByPath("C:/mypath/Spotify.exe") or GetWindowByName("Spotify"). Maybe with ahk? (I have no clue about AHK)
I've now read other questions and docs for hours and havn't found a way. Thanks in advance :)
Solution 1:[1]
There is no direct way, you need to approach it from each end and meet in the middle which is the process id.
If this was native code you could use the Toolhelp functions to enumerate all the processes and look at the filename of each. When you find a match, remember the process id.
Then you can call EnumWindows to find all top-level windows. In the callback you would call GetWindowThreadProcessId on each window until you find one that matches the process id you found earlier.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anders |
