-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathGetOSVersion.cpp
64 lines (58 loc) · 1.24 KB
/
GetOSVersion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <Windows.h>
#include <string>
#include <stdio.h>
#pragma comment(lib, "user32.lib")
void GetOSVersion()
{
typedef void(__stdcall*NTPROC)(DWORD*, DWORD*, DWORD*);
HINSTANCE hinst = LoadLibrary("ntdll.dll");
DWORD dwMajor, dwMinor, dwBuildNumber;
NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
proc(&dwMajor, &dwMinor, &dwBuildNumber);
if (dwMajor == 10 && dwMinor == 0) //win 10
{
printf("Windows 10\n");
return;
}
SYSTEM_INFO info;
GetSystemInfo(&info);
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if (GetVersionEx((OSVERSIONINFO *)&os))
{
switch (os.dwMajorVersion)
{
case 6:
switch (os.dwMinorVersion)
{
case 0:
if (os.wProductType == VER_NT_WORKSTATION)
printf("Windows Vista\n");
else
printf("Windows Server 2008\n");
break;
case 1:
if (os.wProductType == VER_NT_WORKSTATION)
printf("Windows 7\n");
else
printf("Windows Windows Server 2008 R2\n");
break;
case 2:
if (os.wProductType == VER_NT_WORKSTATION)
printf("Windows 8\n");
else
printf("Windows Server 2012\n");
break;
}
break;
default:
printf("Too old\n");
}
}
else
printf("Error\n");
}
void main()
{
GetOSVersion();
}