Retrieve File Description an Application VerQueryValue

前端 未结 1 1780
太阳男子
太阳男子 2021-01-22 18:20

I really confuse with this function. currently i success to retrieve File Version and Product Version. now i want to retrieve more information within application. like FileDescr

1条回答
  •  -上瘾入骨i
    2021-01-22 18:59

    VerQueryValue(test, "\\StringFileInfo\\%04x%09x\\FileDescription",
       (LPVOID*)&sCompanyName, &pLenFileInfo);
    

    The second parameter should be of this format "\\StringFileInfo\\NxM\\FileDescription" where N and M are wLanguage and wCodePage. Following the example in comment section, you can use "%04x%04x" as print format specifier to create a string. Example:

    BOOL foo()
    {
        const char* filename = "c:\\windows\\hh.exe";
        int dwLen = GetFileVersionInfoSize(filename, NULL);
        if(!dwLen)
            return 0;
    
        auto *sKey = new BYTE[dwLen];
        std::unique_ptr skey_automatic_cleanup(sKey);
        if(!GetFileVersionInfo(filename, NULL, dwLen, sKey))
            return 0;
    
        struct LANGANDCODEPAGE {
            WORD wLanguage;
            WORD wCodePage;
        } *lpTranslate;
    
        UINT cbTranslate = 0;
        if(!VerQueryValue(sKey, "\\VarFileInfo\\Translation",
            (LPVOID*)&lpTranslate, &cbTranslate))
            return 0;
    
        for(unsigned int i = 0; i < (cbTranslate / sizeof(LANGANDCODEPAGE)); i++)
        {
            char subblock[256];
            //use sprintf if sprintf_s is not available
            sprintf_s(subblock, "\\StringFileInfo\\%04x%04x\\FileDescription",
                lpTranslate[i].wLanguage, lpTranslate[i].wCodePage);
            char *description = NULL;
            UINT dwBytes;
            if(VerQueryValue(sKey, subblock, (LPVOID*)&description, &dwBytes))
                MessageBox(0, description, 0, 0);
        }
        return TRUE;
    }
    

    0 讨论(0)
提交回复
热议问题