简体   繁体   English

Windows 8次要版本返回0而不是2

[英]windows 8 minor version returning 0 instead of 2

I have code in C++ that has the purpose of finding the Windows version: 我有C ++代码,其目的是查找Windows版本:

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. iRet将返回一个内部枚举值,用于标识Windows版本。 It will be ajusted according to the values returned in osvi.dwPlatformId, osvi.dwMajorVersion and osvi.dwMinorVersion. 它将根据osvi.dwPlatformId,osvi.dwMajorVersion和osvi.dwMinorVersion中返回的值进行调整。

According to MSDN, for Windows 8 the value of MajorVersion is 6 and the value for MinorVersion is 2. 根据MSDN,对于Windows 8,MajorVersion的值为6,而MinorVersion的值为2。

I have this code compiled in a dll and the code actually works if I call the DLL from a test EXE program. 我已将此代码编译到dll中,并且如果我从测试EXE程序调用DLL,则该代码实际上可以工作。

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. 但是,如果我从Windows安装程序包(MSI)中的“自定义操作”中从相同的DLL调用相同的代码,则GetVersionEx()为MinorVersion字段返回0。

Did anybody else experience this bug? 还有其他人遇到此错误吗? Does anybody know how to work around it? 有人知道如何解决吗?

Turns out Windows Installer lies about the version by default when using GetVersion(Ex) on Windows 7+. 事实证明,在Windows 7+上使用GetVersion(Ex)时,默认情况下Windows Installer涉及该版本。 The answer is always Vista SP0. 答案始终是Vista SP0。 You can use the VersionNT MSI value instead. 您可以改用VersionNT MSI值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM