Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
System Services
System Information
 GetVersionEx function
GetVersionEx function

Applies to: desktop apps only

Retrieves information about the current operating system.

Syntax

BOOL WINAPI GetVersionEx(
  __inout  LPOSVERSIONINFO lpVersionInfo
);

Parameters

lpVersionInfo [in, out]

An OSVERSIONINFO or OSVERSIONINFOEX structure that receives the operating system information.

Before calling the GetVersionEx function, set the dwOSVersionInfoSize member of the structure as appropriate to indicate which data structure is being passed to this function.

Return value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError. The function fails if you specify an invalid value for the dwOSVersionInfoSize member of the OSVERSIONINFO or OSVERSIONINFOEX structure.

Remarks

Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, test for the presence of the feature itself. For more information, see Operating System Version.

The GetSystemMetrics function provides additional information about the current operating system.

ProductSetting
Windows XP Media Center EditionSM_MEDIACENTER
Windows XP Starter EditionSM_STARTER
Windows XP Tablet PC EditionSM_TABLETPC
Windows Server 2003 R2SM_SERVERR2

 

To check for specific operating systems or operating system features, use the IsOS function. The GetProductInfo function retrieves the product type.

To retrieve information for the operating system on a remote computer, use the NetWkstaGetInfo function, the Win32_OperatingSystem WMI class, or the OperatingSystem property of the IADsComputer interface.

To compare the current system version to a required version, use the VerifyVersionInfo function instead of using GetVersionEx to perform the comparison yourself.

If compatibility mode is in effect, the GetVersionEx function reports the operating system as it identifies itself, which may not be the operating system that is installed. For example, if compatibility mode is in effect, GetVersionEx reports the operating system that is selected for application compatibility.

Examples

When using the GetVersionEx function to determine whether your application is running on a particular version of the operating system, check for version numbers that are greater than or equal to the desired version numbers. This ensures that the test succeeds for later versions of the operating system. For example, if your application requires Windows XP or later, use the following test.

C++
#include <windows.h>
#include <stdio.h>

void main()
{
    OSVERSIONINFO osvi;
    BOOL bIsWindowsXPorLater;

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

    GetVersionEx(&osvi);

    bIsWindowsXPorLater = 
       ( (osvi.dwMajorVersion > 5) ||
       ( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));

    if(bIsWindowsXPorLater)
        printf("The system meets the requirements.\n");
    else printf("The system does not meet the requirements.\n");
}

For an example that identifies the current operating system, see Getting the System Version.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

GetVersionExW (Unicode) and GetVersionExA (ANSI)

See also

GetVersion
Operating System Version
OSVERSIONINFO
OSVERSIONINFOEX
System Information Functions
VerifyVersionInfo

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
see various version numbers here      rogerdpack   |   Edit   |   Show History
Tags What's this?: Add a tag
Flag as ContentBug
What they don't tell you.      Jamie Marchant   |   Edit   |   Show History
What they don't tell you is if you want to use OSVERSIONINFOEX, you have to set the size and cast it to LPOSVERSIONINFO like this:
osviex.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 GetVersionEx ((LPOSVERSIONINFO)&;;osviex);
Tags What's this?: Add a tag
Flag as ContentBug
GetVersionEx within msiexec on Windows 7      Marco Borm   |   Edit   |   Show History
Hint for every install package developer:

The Version reported within a custom action is Windows Vista, because of
a "VistaRTMVersionLie" compatibility rule, which affects all msi
packages.


http://blogs.msdn.com/b/cjacks/archive/2009/05/06/why-custom-actions-get-a-windows-vista-version-lie-on-windows-7.asp
Tags What's this?: Add a tag
Flag as ContentBug
Managed code      feuerblitz03   |   Edit   |   Show History
In managed code you can use Environment.OSVersion.
Tags What's this?: Add a tag
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool GetVersionEx([In, Out] OSVERSIONINFO ver);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetVersionEx(<[In], Out> ByVal ver As OSVERSIONINFO) As Boolean
End Function
Flag as ContentBug
Windows 7 Beta      clackmannan   |   Edit   |   Show History
FYI the Windows 7 beta returns 6.1 as the major.minor version.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker