| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/process/launch.h" | 5 #include "base/process/launch.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <userenv.h> | 10 #include <userenv.h> |
| 11 #include <psapi.h> | 11 #include <psapi.h> |
| 12 #include <Shellapi.h> |
| 12 | 13 |
| 13 #include <ios> | 14 #include <ios> |
| 14 | 15 |
| 15 #include "base/bind.h" | 16 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 18 #include "base/debug/stack_trace.h" | 19 #include "base/debug/stack_trace.h" |
| 19 #include "base/logging.h" | 20 #include "base/logging.h" |
| 20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 189 |
| 189 return true; | 190 return true; |
| 190 } | 191 } |
| 191 | 192 |
| 192 bool LaunchProcess(const CommandLine& cmdline, | 193 bool LaunchProcess(const CommandLine& cmdline, |
| 193 const LaunchOptions& options, | 194 const LaunchOptions& options, |
| 194 ProcessHandle* process_handle) { | 195 ProcessHandle* process_handle) { |
| 195 return LaunchProcess(cmdline.GetCommandLineString(), options, process_handle); | 196 return LaunchProcess(cmdline.GetCommandLineString(), options, process_handle); |
| 196 } | 197 } |
| 197 | 198 |
| 199 bool LaunchElevatedProcess(const CommandLine& cmdline, |
| 200 const LaunchOptions& options, |
| 201 ProcessHandle* process_handle) { |
| 202 const std::wstring file = cmdline.GetProgram().value(); |
| 203 const std::wstring arguments = cmdline.GetArgumentsString(); |
| 204 |
| 205 SHELLEXECUTEINFO shex_info = {0}; |
| 206 shex_info.cbSize = sizeof(shex_info); |
| 207 shex_info.fMask = SEE_MASK_NOCLOSEPROCESS; |
| 208 shex_info.hwnd = GetActiveWindow(); |
| 209 shex_info.lpVerb = L"runas"; |
| 210 shex_info.lpFile = file.c_str(); |
| 211 shex_info.lpParameters = arguments.c_str(); |
| 212 shex_info.lpDirectory = NULL; |
| 213 shex_info.nShow = options.start_hidden ? SW_HIDE : SW_SHOW; |
| 214 shex_info.hInstApp = NULL; |
| 215 |
| 216 if (!ShellExecuteEx(&shex_info)) { |
| 217 DPLOG(ERROR); |
| 218 return false; |
| 219 } |
| 220 |
| 221 if (options.wait) |
| 222 WaitForSingleObject(shex_info.hProcess, INFINITE); |
| 223 |
| 224 // If the caller wants the process handle give it to them, otherwise just |
| 225 // close it. Closing it does not terminate the process. |
| 226 if (process_handle) |
| 227 *process_handle = shex_info.hProcess; |
| 228 else |
| 229 CloseHandle(shex_info.hProcess); |
| 230 |
| 231 return true; |
| 232 } |
| 233 |
| 198 bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) { | 234 bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) { |
| 199 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; | 235 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; |
| 200 limit_info.BasicLimitInformation.LimitFlags = limit_flags; | 236 limit_info.BasicLimitInformation.LimitFlags = limit_flags; |
| 201 return 0 != SetInformationJobObject( | 237 return 0 != SetInformationJobObject( |
| 202 job_object, | 238 job_object, |
| 203 JobObjectExtendedLimitInformation, | 239 JobObjectExtendedLimitInformation, |
| 204 &limit_info, | 240 &limit_info, |
| 205 sizeof(limit_info)); | 241 sizeof(limit_info)); |
| 206 } | 242 } |
| 207 | 243 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 WaitForSingleObject(proc_info.process_handle(), INFINITE); | 309 WaitForSingleObject(proc_info.process_handle(), INFINITE); |
| 274 | 310 |
| 275 return true; | 311 return true; |
| 276 } | 312 } |
| 277 | 313 |
| 278 void RaiseProcessToHighPriority() { | 314 void RaiseProcessToHighPriority() { |
| 279 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 315 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
| 280 } | 316 } |
| 281 | 317 |
| 282 } // namespace base | 318 } // namespace base |
| OLD | NEW |