Question

I have code in C++ that has the purpose of finding the Windows version:

OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;

int iRet = OS_UNKNOWN;

ZeroMemory ( & osvi, sizeof ( OSVERSIONINFOEX ) );
osvi.dwOSVersionInfoSize = sizeof ( OSVERSIONINFOEX );

if ( !( bOsVersionInfoEx = GetVersionEx ( ( OSVERSIONINFO * ) & osvi ) ) )
{
    osvi.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
    if ( ! GetVersionEx ( ( OSVERSIONINFO * ) & osvi ) )
        return OS_UNKNOWN;      
}
//the rest is irrelevant ...

iRet will return an internal enum value identifying the Windows version. It will be ajusted according to the values returned in osvi.dwPlatformId, osvi.dwMajorVersion and osvi.dwMinorVersion.

According to MSDN, for Windows 8 the value of MajorVersion is 6 and the value for MinorVersion is 2.

I have this code compiled in a dll and the code actually works if I call the DLL from a test EXE program.

But if I call THE SAME CODE FROM THE SAME DLL from within a Custom Action within a windows installer package (MSI), GetVersionEx() returns 0 for the MinorVersion field.

Did anybody else experience this bug? Does anybody know how to work around it?

Was it helpful?

Solution

Turns out Windows Installer lies about the version by default when using GetVersion(Ex) on Windows 7+. The answer is always Vista SP0. You can use the VersionNT MSI value instead.

Source: http://blogs.msdn.com/b/cjacks/archive/2009/05/06/why-custom-actions-get-a-windows-vista-version-lie-on-windows-7.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top