OLD | NEW |
| (Empty) |
1 // Copyright 2004-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 // TODO(omaha): this code should be updated according to code published by | |
17 // Microsoft at http://msdn.microsoft.com/en-us/library/ms724429(VS.85).aspx. | |
18 // We need a more rigorous clasification of versions. | |
19 | |
20 #ifndef OMAHA_BASE_SYSTEM_INFO_H_ | |
21 #define OMAHA_BASE_SYSTEM_INFO_H_ | |
22 | |
23 #include <windows.h> | |
24 #include <tchar.h> | |
25 | |
26 namespace omaha { | |
27 | |
28 // TODO(omaha): refactor to use a namespace. | |
29 class SystemInfo { | |
30 public: | |
31 // Find out if the OS is at least Windows 2000 | |
32 // Service pack 4. If OS version is less than that | |
33 // will return false, all other cases true. | |
34 static bool OSWin2KSP4OrLater() { | |
35 // Use GetVersionEx to get OS and Service Pack information. | |
36 OSVERSIONINFOEX osviex; | |
37 ::ZeroMemory(&osviex, sizeof(osviex)); | |
38 osviex.dwOSVersionInfoSize = sizeof(osviex); | |
39 BOOL success = ::GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&osviex)); | |
40 // If this failed we're on Win9X or a pre NT4SP6 OS. | |
41 if (!success) { | |
42 return false; | |
43 } | |
44 | |
45 if (osviex.dwMajorVersion < 5) { | |
46 return false; | |
47 } | |
48 if (osviex.dwMajorVersion > 5) { | |
49 return true; // way beyond Windows XP. | |
50 } | |
51 if (osviex.dwMinorVersion >= 1) { | |
52 return true; // Windows XP or better. | |
53 } | |
54 if (osviex.wServicePackMajor >= 4) { | |
55 return true; // Windows 2000 SP4. | |
56 } | |
57 | |
58 return false; // Windows 2000, < SP4. | |
59 } | |
60 | |
61 // Returns true if the OS is at least XP SP2. | |
62 static bool OSWinXPSP2OrLater(); | |
63 | |
64 // CategorizeOS returns a categorization of what operating system is running, | |
65 // and the service pack level. | |
66 // NOTE: Please keep this in the order of increasing OS versions | |
67 enum OSVersionType { | |
68 OS_WINDOWS_UNKNOWN = 1, | |
69 OS_WINDOWS_9X_OR_NT, | |
70 OS_WINDOWS_2000, | |
71 OS_WINDOWS_XP, | |
72 OS_WINDOWS_SERVER_2003, | |
73 OS_WINDOWS_VISTA, | |
74 OS_WINDOWS_7 | |
75 }; | |
76 static HRESULT CategorizeOS(OSVersionType* os_version, DWORD* service_pack); | |
77 static const wchar_t* OSVersionTypeAsString(OSVersionType t); | |
78 | |
79 // Returns true if the current operating system is Windows 2000. | |
80 static bool IsRunningOnW2K(); | |
81 | |
82 // Are we running on Windows XP or later. | |
83 static bool IsRunningOnXPOrLater(); | |
84 | |
85 // Are we running on Windows XP SP1 or later. | |
86 static bool IsRunningOnXPSP1OrLater(); | |
87 | |
88 // Are we running on Windows Vista or later. | |
89 static bool IsRunningOnVistaOrLater(); | |
90 | |
91 static bool IsRunningOnVistaRTM(); | |
92 | |
93 // Returns the version and the name of the operating system. | |
94 static bool GetSystemVersion(int* major_version, | |
95 int* minor_version, | |
96 int* service_pack_major, | |
97 int* service_pack_minor, | |
98 TCHAR* name_buf, | |
99 size_t name_buf_len); | |
100 | |
101 // Returns the processor architecture. We use wProcessorArchitecture in | |
102 // SYSTEM_INFO returned by ::GetNativeSystemInfo() to detect the processor | |
103 // architecture of the installed operating system. Note the "Native" in the | |
104 // function name - this is important. See | |
105 // http://msdn.microsoft.com/en-us/library/ms724340.aspx. | |
106 static DWORD GetProcessorArchitecture(); | |
107 | |
108 // Returns whether this is a 64-bit Windows system. | |
109 static bool Is64BitWindows(); | |
110 }; | |
111 | |
112 } // namespace omaha | |
113 | |
114 #endif // OMAHA_BASE_SYSTEM_INFO_H_ | |
115 | |
OLD | NEW |