views:

124

answers:

3

Hi All,

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 Uninstall hive of the registry. But i want to show the version of those softwares also.

Can some one help me out in this regard?

Thanks in Advance. Anjan

+3  A: 

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.

Tomasz Łazarowicz
+1  A: 

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.

Martin
+1 I've also set the file version information with this tool http://www.elphin.com/downloads/stampver/.
kenny
Thanks Martin, I have already visited this article. By this approcah one can query Install Size , frequency of use but how to go about version i am not sure...
Anjan
+2  A: 

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;
}
bdhar
I can get the information if by some way we can get the location of the executable by reading the file version information. But Uninstall path present in the registry is not consistent.
Anjan
I have edited my post. See if the above code is useful. Source: http://beta.unclassified.de/code/cpp/getfileversion/GetFileVersion.cpp
bdhar
thanks bdhar. But how to get the path of the file.
Anjan
@Anjan.. I am not sure, sorry. Perhaps someone else might be able to help you with that!
bdhar
The "uninstall path" in the registry probably lists the path to the uninstaller. That uninstaller probably has a version distinct from the software it uninstalls.
MSalters