| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/win_util.h" | 5 #include "base/win_util.h" |
| 6 | 6 |
| 7 #include <aclapi.h> | 7 #include <aclapi.h> |
| 8 #include <shobjidl.h> // Must be before propkey. | 8 #include <shobjidl.h> // Must be before propkey. |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 #include <propvarutil.h> | 10 #include <propvarutil.h> |
| 11 #include <sddl.h> | 11 #include <sddl.h> |
| 12 #include <shlobj.h> | 12 #include <shlobj.h> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/registry.h" | 15 #include "base/win/registry.h" |
| 16 #include "base/scoped_handle.h" | 16 #include "base/scoped_handle.h" |
| 17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 20 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
| 21 | 21 |
| 22 namespace win_util { | 22 namespace win_util { |
| 23 | 23 |
| 24 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ | 24 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \ |
| 25 offsetof(struct_name, member) + \ | 25 offsetof(struct_name, member) + \ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (size_ret < (buffer_size - 1)) { | 120 if (size_ret < (buffer_size - 1)) { |
| 121 output.resize(size_ret); | 121 output.resize(size_ret); |
| 122 return output; | 122 return output; |
| 123 } | 123 } |
| 124 buffer_size *= 2; | 124 buffer_size *= 2; |
| 125 } | 125 } |
| 126 return std::wstring(); // error | 126 return std::wstring(); // error |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool UserAccountControlIsEnabled() { | 129 bool UserAccountControlIsEnabled() { |
| 130 RegKey key(HKEY_LOCAL_MACHINE, | 130 base::win::RegKey key(HKEY_LOCAL_MACHINE, |
| 131 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", | 131 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", |
| 132 KEY_READ); | 132 KEY_READ); |
| 133 DWORD uac_enabled; | 133 DWORD uac_enabled; |
| 134 if (!key.ReadValueDW(L"EnableLUA", &uac_enabled)) | 134 if (!key.ReadValueDW(L"EnableLUA", &uac_enabled)) |
| 135 return true; | 135 return true; |
| 136 // Users can set the EnableLUA value to something arbitrary, like 2, which | 136 // Users can set the EnableLUA value to something arbitrary, like 2, which |
| 137 // Vista will treat as UAC enabled, so we make sure it is not set to 0. | 137 // Vista will treat as UAC enabled, so we make sure it is not set to 0. |
| 138 return (uac_enabled != 0); | 138 return (uac_enabled != 0); |
| 139 } | 139 } |
| 140 | 140 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 PropVariantClear(&property_value); | 181 PropVariantClear(&property_value); |
| 182 return SUCCEEDED(result); | 182 return SUCCEEDED(result); |
| 183 } | 183 } |
| 184 | 184 |
| 185 static const char16 kAutoRunKeyPath[] = | 185 static const char16 kAutoRunKeyPath[] = |
| 186 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; | 186 L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; |
| 187 | 187 |
| 188 bool AddCommandToAutoRun(HKEY root_key, const string16& name, | 188 bool AddCommandToAutoRun(HKEY root_key, const string16& name, |
| 189 const string16& command) { | 189 const string16& command) { |
| 190 RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); | 190 base::win::RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); |
| 191 return autorun_key.WriteValue(name.c_str(), command.c_str()); | 191 return autorun_key.WriteValue(name.c_str(), command.c_str()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name) { | 194 bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name) { |
| 195 RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); | 195 base::win::RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); |
| 196 return autorun_key.DeleteValue(name.c_str()); | 196 return autorun_key.DeleteValue(name.c_str()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace win_util | 199 } // namespace win_util |
| 200 | 200 |
| 201 #ifdef _MSC_VER | 201 #ifdef _MSC_VER |
| 202 // | 202 // |
| 203 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1. | 203 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1. |
| 204 // | 204 // |
| 205 extern char VisualStudio2005ServicePack1Detection[10]; | 205 extern char VisualStudio2005ServicePack1Detection[10]; |
| 206 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*), | 206 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*), |
| 207 VS2005SP1Detect); | 207 VS2005SP1Detect); |
| 208 // | 208 // |
| 209 // Chrome requires at least Service Pack 1 for Visual Studio 2005. | 209 // Chrome requires at least Service Pack 1 for Visual Studio 2005. |
| 210 // | 210 // |
| 211 #endif // _MSC_VER | 211 #endif // _MSC_VER |
| 212 | 212 |
| 213 #ifndef COPY_FILE_COPY_SYMLINK | 213 #ifndef COPY_FILE_COPY_SYMLINK |
| 214 #error You must install the Windows 2008 or Vista Software Development Kit and \ | 214 #error You must install the Windows 2008 or Vista Software Development Kit and \ |
| 215 set it as your default include path to build this library. You can grab it by \ | 215 set it as your default include path to build this library. You can grab it by \ |
| 216 searching for "download windows sdk 2008" in your favorite web search engine. \ | 216 searching for "download windows sdk 2008" in your favorite web search engine. \ |
| 217 Also make sure you register the SDK with Visual Studio, by selecting \ | 217 Also make sure you register the SDK with Visual Studio, by selecting \ |
| 218 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ | 218 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ |
| 219 menu (see Start - All Programs - Microsoft Windows SDK - \ | 219 menu (see Start - All Programs - Microsoft Windows SDK - \ |
| 220 Visual Studio Registration). | 220 Visual Studio Registration). |
| 221 #endif | 221 #endif |
| OLD | NEW |