How to get the software version?

I am working on getting the version of software that is installed on the computer. I have implemented the logic for reading the registry of Uninstall utilities, but I noticed that some of the programs do not have version entries in the registry registry utility. But I also want to show the version of these programs.

Can someone help me in this regard?

0
source share
4 answers

Delivering a version of the software to the Windows registry is optional. If the software developer you are looking at has decided not to display the version there or simply did not know about such a possibility, I cannot point you to another place that he prefers to use or know. In fact, the software may not even have a version number / name.

+4
source

Ask yourself: Where else is the detailed information about the software version, if not in the registry? If it is available somewhere else than the registry, ask us if you can get this part using C ++. I think this will be the best approach to solving your problem.


Added information below as OP is looking for file version

, .

CString GetFileVersionInfo(CString strFile, CString strProperty)
{
    int rc;
    UINT nLen;
    DWORD nSize;
    DWORD dwHandle = 0;
    CString strBuffer;
    CString strValue;
    CString strBlock;
    void *lpPropertyBuffer;

    struct LANGANDCODEPAGE
    {
      WORD wLanguage;
      WORD wCodePage;
    } *lpTranslate;

    nSize = GetFileVersionInfoSize(strFile.GetBuffer(strFile.GetLength()), &dwHandle);
    ::GetFileVersionInfo(strFile.GetBuffer(strFile.GetLength()), 0, nSize, strBuffer.GetBuffer(nSize));

    // Read the list of languages and code pages.
    if (VerQueryValue(strBuffer.GetBuffer(strBuffer.GetLength()), "\\VarFileInfo\\Translation", (LPVOID *) &lpTranslate, &nLen))
    {
        strBlock.Format("\\StringFileInfo\\%04x%04x\\%s",
            lpTranslate->wLanguage,
            lpTranslate->wCodePage,
            strProperty);
        rc = VerQueryValue(strBuffer.GetBuffer(strBuffer.GetLength()), strBlock.GetBuffer(nSize), &lpPropertyBuffer, &nLen);
        if (rc != 0 && nLen > 0)
        {
            strncpy(strValue.GetBuffer(nLen + 1), (char *) lpPropertyBuffer, nLen);
            strValue.ReleaseBuffer(nLen);
        }
    }

    return strValue;
}

user version.lib , winver.h . ,

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    int nRetCode = 0;

    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
        // TODO: change error code to suit your needs
        cerr << _T("Fatal Error: MFC initialization failed") << endl;
        nRetCode = 1;
    }
    else
    {
        AfxMessageBox(GetFileVersionInfo("shell32.dll", "ProductVersion"));
    }

    return nRetCode;
}
+3

, . , , " ".

+1

Uninstall, .

You can find where the application is installed. But even if you have a path, an application can consist of several .exe files, which can have different versions and product names. If you add DLLs to the candidate list for version information, your results will become even less predictable.

0
source

Source: https://habr.com/ru/post/1785734/


All Articles