VerifyVersionInfo

 

Description

 

Compares a set of operating system version requirements to the corresponding values for the currently running version of the system.

 

C++ Syntax

 

BOOL WINAPI VerifyVersionInfo(

__in LPOSVERSIONINFOEX lpVersionInfo,

__in DWORD dwTypeMask,

__in DWORDLONG dwlConditionMask

);

 

PowerBASIC Syntax

 

FUNCTION VerifyVersionInfo ( _

BYREF lpVersionInfo AS OSVERSIONINFOEX, _

BYVAL dwTypeMask AS DWORD, _

BYVAL dwlConditionMask AS QUAD _

) AS LONG

 

Parameters

 

lpVersionInfo

 

[in] A pointer to an OSVERSIONINFOEX structure containing the operating system version requirements to compare. The dwTypeMask parameter indicates the members of this structure that contain information to compare.

 

You must set the dwOSVersionInfoSize member of this structure to SIZEOF(OSVERSIONINFOEX). You must also specify valid data for the members indicated by dwTypeMask. The function ignores structure members for which the corresponding dwTypeMask bit is not set.

 

dwTypeMask

 

[in] A mask that indicates the members of the OSVERSIONINFOEX structure to be tested. This parameter can be one or more of the following values.

 

Value

Meaning

VER_EQUAL

1

The current value must be equal to the specified value.

VER_GREATER

2

The current value must be greater than the specified value.

VER_GREATER_EQUAL

3

The current value must be greater than or equal to the specified value.

VER_LESS

4

The current value must be less than the specified value.

VER_LESS_EQUAL

5

The current value must be less than or equal to the specified value.

 

dwlConditionMask

 

[in] The type of comparison to be used for each lpVersionInfo member being compared. To build this value, call the VerSetConditionMask function or the VER_SET_CONDITION macro once for each OSVERSIONINFOEX member being compared.

 

Return Value

 

If the currently running operating system satisfies the specified requirements, the return value is a nonzero value.

 

If the current system does not satisfy the requirements, the return value is zero and GetLastError returns ERROR_OLD_WIN_VERSION.

 

If the function fails, the return value is zero and GetLastError returns an error code other than ERROR_OLD_WIN_VERSION.

 

Remarks

 

The VerifyVersionInfo function retrieves version information about the currently running operating system and compares it to the valid members of the lpVersionInfo structure. This enables you to easily determine the presence of a required set of operating system version conditions. It is preferable to use VerifyVersionInfo rather than calling the GetVersionEx function to perform your own comparisons.

 

Typically, VerifyVersionInfo returns a nonzero value only if all specified tests succeed. However, major, minor, and service pack versions are tested in a hierarchical manner because the operating system version is a combination of these values. If a condition exists for the major version, it supersedes the conditions specified for minor version and service pack version. (You cannot test for major version greater than 5 and minor version less than or equal to 1. If you specify such a test, the function will change the request to test for a minor version greater than 1 because it is performing a greater than operation on the major version.)

 

The function tests these values in this order: major version, minor version, and service pack version. The function continues testing values while they are equal, and stops when one of the values does not meet the specified condition. For example, if you test for a system greater than or equal to version 5.1 service pack 1, the test succeeds if the current version is 6.0. (The major version is greater than the specified version, so the testing stops.) In the same way, if you test for a system greater than or equal to version 5.1 service pack 1, the test succeeds if the current version is 5.2. (The minor version is greater than the specified versions, so the testing stops.) However, if you test for a system greater than or equal to version 5.1 service pack 1, the test fails if the current version is 5.0 service pack 2. (The minor version is not greater than the specified version, so the testing stops.)

 

To verify a range of system versions, you must call VerifyVersionInfo twice. For example, to verify that the system version is greater than 5.0 but less than or equal to 5.1, first call VerifyVersionInfo to test that the major version is 5 and the minor version is greater than 0, then call VerifyVersionInfo again to test that the major version is 5 and the minor version is less than or equal to 1.

 

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.

 

To verify whether the current operating system is either the Media Center or Tablet PC version of Windows, call GetSystemMetrics.

 

C++ Example1

 

The following example determines whether the application is running on Windows XP with Service Pack 2 (SP2) or a later version of Windows, such as Windows Server 2003 or Windows Vista.

 

#include <windows.h>

#include <stdio.h>

 

BOOL Is_WinXP_SP2_or_Later ()

{

 OSVERSIONINFOEX osvi;

 DWORDLONG dwlConditionMask = 0;

 int op=VER_GREATER_EQUAL;

 

 // Initialize the OSVERSIONINFOEX structure.

 

 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

 osvi.dwMajorVersion = 5;

 osvi.dwMinorVersion = 1;

 osvi.wServicePackMajor = 2;

 osvi.wServicePackMinor = 0;

 

 // Initialize the condition mask.

 

 VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );

 VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );

 VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMAJOR, op );

 VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMINOR, op );

 

 // Perform the test.

 

 return VerifyVersionInfo(

    &osvi,

    VER_MAJORVERSION | VER_MINORVERSION |

    VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,

    dwlConditionMask);

}

 

void main()

{

  if(Is_WinXP_SP2_or_Later())

      printf("The system meets the requirements.\n");

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

}

 

PowerBASIC Example1

 

#COMPILE EXE

#DIM ALL

#INCLUDE "windows.inc"

 

FUNCTION Is_WinXP_SP2_or_Later () AS LONG

 

 LOCAL osvi AS OSVERSIONINFOEX

 LOCAL dwlConditionMask AS QUAD

 

 ' // Initialize the OSVERSIONINFOEX structure.

 osvi.dwOSVersionInfoSize = SIZEOF(OSVERSIONINFOEX)

 osvi.dwMajorVersion = 5

 osvi.dwMinorVersion = 1

 osvi.wServicePackMajor = 2

 osvi.wServicePackMinor = 0

 

 ' // Initialize the condition mask.

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_MAJORVERSION, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_MINORVERSION, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_SERVICEPACKMAJOR, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_SERVICEPACKMINOR, %VER_GREATER_EQUAL)

 

 ' // Perform the test.

 FUNCTION = VerifyVersionInfo(osvi, %VER_MAJORVERSION OR %VER_MINORVERSION OR _

            %VER_SERVICEPACKMAJOR OR %VER_SERVICEPACKMINOR, dwlConditionMask)

 

END FUNCTION

 

FUNCTION PBMAIN

 

 IF Is_WinXP_SP2_or_Later() THEN

    PRINT "The system meets the requirements."

 ELSE

    PRINT "The system does not meet the requirements."

 END IF

 

 WAITKEY$

 

END FUNCTION

 

C++ Example2

 

The following code verifies that the application is running on Windows 2000 Server or a later server, such as Windows Server 2003 or Windows Server 2008.

 

#include <windows.h>

#include <stdio.h>

 

BOOL Is_Win_Server()

{

 OSVERSIONINFOEX osvi;

 DWORDLONG dwlConditionMask = 0;

 int op=VER_GREATER_EQUAL;

 

 // Initialize the OSVERSIONINFOEX structure.

 

 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

 osvi.dwMajorVersion = 5;

 osvi.dwMinorVersion = 0;

 osvi.wServicePackMajor = 0;

 osvi.wServicePackMinor = 0;

 osvi.wProductType = VER_NT_SERVER;

 

 // Initialize the condition mask.

 

 VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );

 VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );

 VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMAJOR, op );

 VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMINOR, op );

 VER_SET_CONDITION( dwlConditionMask, VER_PRODUCT_TYPE, VER_EQUAL );

 

 // Perform the test.

 

 return VerifyVersionInfo(

    &osvi,

    VER_MAJORVERSION | VER_MINORVERSION |

    VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR |

    VER_PRODUCT_TYPE,

    dwlConditionMask);

}

 

void main()

{

  if(Is_Win_Server())

      printf("The system meets the requirements.\n");

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

}

 

PowerBASIC Example2

 

#COMPILE EXE

#DIM ALL

#INCLUDE "windows.inc"

 

FUNCTION Is_Win_Server () AS LONG

 

 LOCAL osvi AS OSVERSIONINFOEX

 LOCAL dwlConditionMask AS QUAD

 

 ' // Initialize the OSVERSIONINFOEX structure.

 osvi.dwOSVersionInfoSize = SIZEOF(OSVERSIONINFOEX)

 osvi.dwMajorVersion = 5

 osvi.dwMinorVersion = 0

 osvi.wServicePackMajor = 0

 osvi.wServicePackMinor = 0

 osvi.wProductType = %VER_NT_SERVER

 

 ' // Initialize the condition mask.

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_MAJORVERSION, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_MINORVERSION, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_SERVICEPACKMAJOR, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_SERVICEPACKMINOR, %VER_GREATER_EQUAL)

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_PRODUCT_TYPE, %VER_GREATER_EQUAL)

 

 ' // Perform the test.

 FUNCTION = VerifyVersionInfo(osvi, %VER_MAJORVERSION OR %VER_MINORVERSION OR _

            %VER_SERVICEPACKMAJOR OR %VER_SERVICEPACKMINOR OR %VER_PRODUCT_TYPE, dwlConditionMask)

 

END FUNCTION

 

FUNCTION PBMAIN

 

 IF Is_Win_Server() THEN

    PRINT "The system meets the requirements."

 ELSE

    PRINT "The system does not meet the requirements."

 END IF

 

 WAITKEY$

 

END FUNCTION

 

C++ Example3

 

The following example uses the VerifyVersionInfo function to determine whether the specified product suite(s) are installed on the local computer.

 

This example uses the VER_AND flag. If two flags are specified in the suite mask, the function returns TRUE only if both product suites are present. If the example were changed to use the VER_OR flag, VerifyVersionInfo would return TRUE if either product suite were present.

 

#include <windows.h>

#include <stdio.h>

 

BOOL CheckProductSuite ( WORD wSuite )

{

OSVERSIONINFOEX osvi;

DWORDLONG dwlConditionMask = 0;

 

// Initialize the OSVERSIONINFOEX structure.

 

ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

osvi.wSuiteMask = wSuite;

 

// Set up the condition mask.

 

VER_SET_CONDITION( dwlConditionMask,

        VER_SUITENAME, VER_AND );

 

// Perform the test.

 

return VerifyVersionInfo(

        &osvi,

        VER_SUITENAME,

        dwlConditionMask);

}

 

void main()

{

  if( CheckProductSuite(VER_SUITE_ENTERPRISE) )

      printf( "The system meets the requirements.\n" );

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

}

 

PowerBASIC Example3

 

#COMPILE EXE

#DIM ALL

#INCLUDE "windows.inc"

 

FUNCTION CheckProductSuite (BYVAL wSuite AS WORD) AS LONG

 

 LOCAL osvi AS OSVERSIONINFOEX

 LOCAL dwlConditionMask AS QUAD

 

 ' // Initialize the OSVERSIONINFOEX structure.

 osvi.dwOSVersionInfoSize = SIZEOF(OSVERSIONINFOEX)

 osvi.wSuiteMask = wSuite

 

 ' // Set up the condition mask.

 dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_SUITENAME, %VER_AND)

 

 ' // Perform the test.

 FUNCTION = VerifyVersionInfo(osvi, %VER_SUITENAME, dwlConditionMask)

 

END FUNCTION

 

FUNCTION PBMAIN

 

 IF CheckProductSuite(%VER_SUITE_ENTERPRISE) THEN

    PRINT "The system meets the requirements."

 ELSE

    PRINT "The system does not meet the requirements."

 END IF

 

 WAITKEY$

 

END FUNCTION

 

Valid XHTML 1.0 Transitional