IsWindowsVersionOrGreater function version

int IsWindowsVersionOrGreater(
  1. int wMajorVersion,
  2. int wMinorVersion,
  3. int wServicePackMajor
)

Indicates if the current OS version matches, or is greater than, the provided version information. This function is useful in confirming a version of Windows Server that doesn't share a version number with a client release.

Implementation

int IsWindowsVersionOrGreater(
    int wMajorVersion, int wMinorVersion, int wServicePackMajor) {
  final dwlConditionMask = VerSetConditionMask(
    VerSetConditionMask(
      VerSetConditionMask(0, VER_FLAGS.VER_MAJORVERSION, VER_GREATER_EQUAL),
      VER_FLAGS.VER_MINORVERSION,
      VER_GREATER_EQUAL,
    ),
    VER_FLAGS.VER_SERVICEPACKMAJOR,
    VER_GREATER_EQUAL,
  );

  final osvi = calloc<OSVERSIONINFOEX>()
    ..ref.dwMajorVersion = wMajorVersion
    ..ref.dwMinorVersion = wMinorVersion
    ..ref.wServicePackMajor = wServicePackMajor;

  try {
    return VerifyVersionInfo(
      osvi,
      VER_FLAGS.VER_MAJORVERSION |
          VER_FLAGS.VER_MINORVERSION |
          VER_FLAGS.VER_SERVICEPACKMAJOR,
      dwlConditionMask,
    );
  } finally {
    free(osvi);
  }
}