blob: d53148d935e194e95466e4b4a29566fa964282e4 (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/win/windows_version.h"
#include <windows.h>
#include "base/logging.h"
namespace base {
namespace win {
Version GetVersion() {
static bool checked_version = false;
static Version win_version = VERSION_PRE_2000;
if (!checked_version) {
OSVERSIONINFOEX version_info;
version_info.dwOSVersionInfoSize = sizeof version_info;
GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
if (version_info.dwMajorVersion == 5) {
switch (version_info.dwMinorVersion) {
case 0:
win_version = VERSION_2000;
break;
case 1:
win_version = VERSION_XP;
break;
case 2:
default:
win_version = VERSION_SERVER_2003;
break;
}
} else if (version_info.dwMajorVersion == 6) {
if (version_info.wProductType != VER_NT_WORKSTATION) {
// 2008 is 6.0, and 2008 R2 is 6.1.
win_version = VERSION_2008;
} else {
if (version_info.dwMinorVersion == 0) {
win_version = VERSION_VISTA;
} else {
win_version = VERSION_WIN7;
}
}
} else if (version_info.dwMajorVersion > 6) {
win_version = VERSION_WIN7;
}
checked_version = true;
}
return win_version;
}
void GetServicePackLevel(int* major, int* minor) {
DCHECK(major && minor);
static bool checked_version = false;
static int service_pack_major = -1;
static int service_pack_minor = -1;
if (!checked_version) {
OSVERSIONINFOEX version_info = {0};
version_info.dwOSVersionInfoSize = sizeof(version_info);
GetVersionEx(reinterpret_cast<OSVERSIONINFOW*>(&version_info));
service_pack_major = version_info.wServicePackMajor;
service_pack_minor = version_info.wServicePackMinor;
checked_version = true;
}
*major = service_pack_major;
*minor = service_pack_minor;
}
WindowsArchitecture GetWindowsArchitecture() {
SYSTEM_INFO system_info;
GetNativeSystemInfo(&system_info);
switch (system_info.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_INTEL: return X86_ARCHITECTURE;
case PROCESSOR_ARCHITECTURE_AMD64: return X64_ARCHITECTURE;
case PROCESSOR_ARCHITECTURE_IA64: return IA64_ARCHITECTURE;
default: return OTHER_ARCHITECTURE;
}
}
WOW64Status GetWOW64Status() {
static WOW64Status wow64_status =
GetWOW64StatusForProcess(GetCurrentProcess());
return wow64_status;
}
WOW64Status GetWOW64StatusForProcess(HANDLE process_handle) {
typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL);
IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>(
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process"));
if (!is_wow64_process)
return WOW64_DISABLED;
BOOL is_wow64 = FALSE;
if (!(*is_wow64_process)(process_handle, &is_wow64))
return WOW64_UNKNOWN;
return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
}
} // namespace win
} // namespace base
|