比如:
Google Chrome:
类似于任务管理器中显示名字,见下图
那么我们就需要使用VerQueryValue,
从指定的版本信息资源中检索指定的版本信息。若要检索适当的资源,在调用VerQueryValue之前,必须首先调用GetFileVersionInfoSize函数,然后再调用GetFileVersionInfo函数
代码示例:
#include <Windows.h> #include <iostream> #include <strsafe.h> #pragma comment(lib,"Version.lib") struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; } *lpTranslate; int main() { HANDLE handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, appid); wchar_t pszFile[MAX_PATH] = L""; DWORD len = MAX_PATH; if (handle) QueryFullProcessImageName(handle, 0, pszFile, &len); UINT dwBytes, cbTranslate; DWORD dwSize = GetFileVersionInfoSize(pszFile, (DWORD*)&dwBytes); if (dwSize == 0) { int err = GetLastError(); return 0; } LPVOID lpData = (LPVOID)malloc(dwSize); ZeroMemory(lpData, dwSize); if (GetFileVersionInfo(pszFile, 0, dwSize, lpData)) { VerQueryValue(lpData, L"\VarFileInfo\Translation", (LPVOID*)&lpTranslate, &cbTranslate); wchar_t strSubBlock[MAX_PATH] = { 0 }; wchar_t* lpBuffer; for (int i = 0; i < (cbTranslate / sizeof(struct LANGANDCODEPAGE)); i++) { StringCchPrintf(strSubBlock, 50, L"\StringFileInfo\%04x%04x\FileDescription", lpTranslate[i].wLanguage, lpTranslate[i].wCodePage); VerQueryValue(lpData, strSubBlock, (void**)&lpBuffer, &dwBytes); std::wcout << lpBuffer << std::endl; } } if (lpData) free(lpData); if (handle) CloseHandle(handle); return 0; }
Note: 这对普通的win32窗口包括控制台似乎不起作用