How to get process name given a HWND?
How to get process name given a HWND?
Must work in Win95!
[61 byte] By [
M A V] at [2007-11-17 22:39:57]

# 1 Re: How to get process name given a HWND?
i think GetWindowModuleFileName should do the trick for 95
doesn't seem to work in NT or 2K
I just looked at the docs, haven't tested
Hope this helps
Steven Roelants
# 2 Re: How to get process name given a HWND?
Requirements
Windows NT/2000 or later: Requires Windows NT 4.0 SP3 or later.
Windows 95/98/Me: Requires Windows 98 or later.
Copied from MSDN
M A V at 2007-11-10 8:42:41 >

# 3 Re: How to get process name given a HWND?
Originally posted by s. roelants
i think GetWindowModuleFileName should do the trick for 95
doesn't seem to work in NT or 2K
This function is available in Windows 98, Windows NT Service Pack or higher. Therefore it will work in NT and Windows 2000 but not in Windows 95...
# 4 Re: How to get process name given a HWND?
What kind of window is the given HWND? The main window? A process can have more than one main window.
Nevertheless, take a look at the following article ( http://msdn.microsoft.com/msdnmag/issues/02/07/CQA/default.aspx). It might help in your case depending on the question above...
# 5 Re: How to get process name given a HWND?
How can I emulate GetWindowModuleFileName() in Win95?
M A V at 2007-11-10 8:45:45 >

# 6 Re: How to get process name given a HWND?
this article
http://support.microsoft.com/default.aspx?scid=KB;EN-US;228469&
says it works will retrieve info in 2K and NT about modules and windows in the calling process, but that it works with other processes in 95 and 98
in msdn it says that it would work with the following os's:
Minimum operating systems: Included in Windows 95, Windows NT 4.0 SP3
article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/GetWindowModuleFileName.asp
# 7 Re: How to get process name given a HWND?
Originally posted by s. roelants
this article
http://support.microsoft.com/default.aspx?scid=KB;EN-US;228469&
says it works will retrieve info in 2K and NT about modules and windows in the calling process, but that it works with other processes in 95 and 98
in msdn it says that it would work with the following os's:
Minimum operating systems: Included in Windows 95, Windows NT 4.0 SP3
article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/GetWindowModuleFileName.asp
Well...they both seem outdated...the library of October 2001 definitely states that it works in Windows 98 or higher.
Basically I would say just test it and see if you can compile it...if it is not available you should end up with an undeclared identifier...
That is basically one common problem of the MSDN...there are different explanations on the same topic and you never know which one is correct. I usually tend to go with the latest one... :cool:
# 8 Re: How to get process name given a HWND?
I've found the following solution:
HINSTANCE hInst = (HINSTANCE)::GetClassLong(hwnd,GCL_HMODULE);
CString str;
GetModuleFileName(hInst,str.GetBuffer(101),100);
str.ReleaseBuffer();
But it seems to return incorrect module name...
What's wrong?
M A V at 2007-11-10 8:48:48 >

# 9 Re: How to get process name given a HWND?
See MS KB article 175030 - HOWTO: Enumerate Applications Using Win32 APIs (http://support.microsoft.com/default.aspx?scid=KB;EN-US;228469). It says that for that kind of stuff "under Windows NT, you must use functions from the PSAPI library of APIs" but it says that for all other Win32 versions you can use functions from the ToolHelp32 library of APIs.