开发者

How to get Version of the software?

I am working on getting the version of the Software which is installed on the Computer. I have implemented the logic for reading the Uninstall hive of registry, but i have observed that some of the software are not having version entries in the Unin开发者_如何学Cstall hive of the registry. But i want to show the version of those softwares also.

Can some one help me out in this regard?


Supplying a software version to the registry of Windows is voluntary. If the developer of the software you're looking at chose to not display the version there or was simply unaware of such possibility, I am unable to point you to any other location he would choose to use or be aware of. In fact, the software might not even have a version number/name.


Ask yourself this: Where else is the Version detail of the software available if not in the registry? If it is available somewhere else other than registry, ask us if you could get that detail using C++. I guess this would be a better approach to solve your issue.


Added the information below since OP is looking for file version

See if the below code could help you.

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 while linking and you might need winver.h for compilation. You can call the function like this

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;
}


I'd say look at the file version information. And you might find this article useful on how the Add/Remove Programs dialog gets its information.


If the software developers chose not to add version information into Uninstall information, then there's no reliable way to get it.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜