Created
March 4, 2019 08:28
-
-
Save kyle-go/92f3102af45ade5a0f81f99333ef77ce to your computer and use it in GitHub Desktop.
Check Windows OS version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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