Click to See Complete Forum and Search --> : Find Windows By Exe Name


ilgar
May 6th, 1999, 08:31 AM
How can I find HWND by executable name, or executable name by window HWND?

Thanks.

BrianOG
May 6th, 1999, 08:39 AM
Get exename from hWnd: GetWindowModuleFileName

Get hwnd from exename:
dont think there is a direct way.
You could do an EnumWindows and for each window call GetWindowModuleFileName and see if it is the same as the one you want, then save the current hWnd somewhere. This is not very accurate though as a module could have more than one main window (which is probably why there is no API to do it ;-).
Also, when you get the window handle, you will have to make sure that it is the main window, and not a modal dialog currently running in the app.

ilgar
May 7th, 1999, 01:24 AM
This is exactly that I need. Thanks a lot.
Actually, first variant suits me perfectly.
I need to find .exe name from window's HWND.

But, in MSDN I found next:
[This is preliminary documentation and subject to change]. Maybe it won't work on some PC's?

Bye.

Thanks,
Ilgar Mashayev

May 12th, 1999, 05:26 PM
There actually IS an API for that!!

From VC++4 and upper, you can use:
ToolHelp functions for Win95 and WinNT5 (2000?)
PSAPI.DLL for WinNT4 from the WinNT4 DDK

Uli