Skip to content

Instantly share code, notes, and snippets.

@kyle-go
Created March 4, 2019 08:28
Show Gist options
  • Save kyle-go/92f3102af45ade5a0f81f99333ef77ce to your computer and use it in GitHub Desktop.
Save kyle-go/92f3102af45ade5a0f81f99333ef77ce to your computer and use it in GitHub Desktop.
Check Windows OS version
// test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
#include <string>
#include <iostream>
bool IsVistaOrLater() {
OSVERSIONINFO osvi = { sizeof(OSVERSIONINFO) };
GetVersionEx(&osvi);
return osvi.dwMajorVersion >= 6;
}
bool IsWin8_1OrLater()
{
typedef void(__stdcall*NTPROC)(DWORD*, DWORD*, DWORD*);
HINSTANCE hinst = LoadLibraryA("ntdll.dll");
DWORD dwMajor, dwMinor, dwBuildNumber;
NTPROC func = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
if (!func) {
FreeLibrary(hinst);
return false;
}
func(&dwMajor, &dwMinor, &dwBuildNumber);
FreeLibrary(hinst);
if (dwMajor == 6 && dwMinor == 3) //win 8.1
return true;
if (dwMajor >= 10)
return true;
return false;
}
int main()
{
printf("IsVistaOrLater() = %s.\n", IsVistaOrLater() ? "true" : "false");
printf("IsWin8_1OrLater() = %s.\n", IsWin8_1OrLater() ? "true" : "false");
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment