Reputation: 1367
GetWindowThreadProcessId
i get
the pid of it's process, GetModuleFileNameEx
i get the
executable path (I use PathFindFileName
to get the
executable name).However, I can't seem to find any way (if there is any) to get the program's name. For example, for the executable chrome.exe, I'd like to get the name "Google Chrome".
Could you please help me out?
Edit:
Thank you all! Using the references you recommended, I came up with this:
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;
}
... which works as expected... but only for the application calling it. If the executable name is an other one, it returns null, and cchFileDesc is set to 0.
I've read that "If the specified version-information structure exists, and version information is available, the return value is nonzero." Is it possible that I don't have enough rights to read that information? Because it sure exists - task manager prints it for the process's details. Does calling these functions depend on anything else than the process's path?
Upvotes: 4
Views: 2881
Reputation: 1833
Here, as an answer :)
How to get information about a Windows executable (.exe) using C++
Upvotes: 3