- I have HWND windows,
- with
GetWindowThreadProcessId I get the pid of this process, - and
GetModuleFileNameEx I get the executable path (I use PathFindFileName to get the executable name ).
However, I cannot find a way (if any) to get the name of the program. For example, for the chrome.exe executable, I would like to get the name "Google Chrome".
Could you help me?
Edit:
Thanks everyone! Using the recommendations you recommended, I came up with the following:
CString csProductName; DWORD cbFileVersionInfo = GetFileVersionInfoSize(pszProcessPath, NULL); if (cbFileVersionInfo) { BYTE *fileVersionInfo = new BYTE[cbFileVersionInfo]; TCHAR *pszFileDesc = NULL; DWORD cchFileDesc; if (GetFileVersionInfo(pszProcessPath, 0, cbFileVersionInfo, fileVersionInfo)) { CString csFileDescSubBlock; csFileDescSubBlock.Format(L"\\StringFileInfo\\040904E4\\ProductName"); DWORD cbLanguageInfoSize = VerQueryValue(fileVersionInfo, csFileDescSubBlock.GetString(), (LPVOID*)&pszFileDesc, (PUINT)&cchFileDesc); } csProductName = pszFileDesc; delete[] fileVersionInfo; }
... works as expected ... but only for the application calling it. If the executable name is different, it returns null, and cchFileDesc returns 0.
I read that "If the specified structure of version information exists and version information is available , the return value is non-zero." Is it possible that I do not have sufficient permissions to read this information? Since it is defined, it exists - the task manager prints it for the details of the process. Does these functions cause dependence on anything other than the process path?
source share