Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: base/process/launch_win.cc

Issue 98603007: Launches a privileged utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds the elevation flag to the utility process. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/launch.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <shellapi.h>
9 #include <windows.h> 10 #include <windows.h>
10 #include <userenv.h> 11 #include <userenv.h>
11 #include <psapi.h> 12 #include <psapi.h>
12 13
13 #include <ios> 14 #include <ios>
14 #include <limits> 15 #include <limits>
15 16
16 #include "base/bind.h" 17 #include "base/bind.h"
17 #include "base/bind_helpers.h" 18 #include "base/bind_helpers.h"
18 #include "base/command_line.h" 19 #include "base/command_line.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 ProcessHandle* process_handle) { 233 ProcessHandle* process_handle) {
233 if (!process_handle) 234 if (!process_handle)
234 return LaunchProcess(cmdline.GetCommandLineString(), options, NULL); 235 return LaunchProcess(cmdline.GetCommandLineString(), options, NULL);
235 236
236 win::ScopedHandle process; 237 win::ScopedHandle process;
237 bool rv = LaunchProcess(cmdline.GetCommandLineString(), options, &process); 238 bool rv = LaunchProcess(cmdline.GetCommandLineString(), options, &process);
238 *process_handle = process.Take(); 239 *process_handle = process.Take();
239 return rv; 240 return rv;
240 } 241 }
241 242
243 bool LaunchElevatedProcess(const CommandLine& cmdline,
244 const LaunchOptions& options,
245 ProcessHandle* process_handle) {
246 const string16 file = cmdline.GetProgram().value();
247 const string16 arguments = cmdline.GetArgumentsString();
248
249 SHELLEXECUTEINFO shex_info = {0};
250 shex_info.cbSize = sizeof(shex_info);
251 shex_info.fMask = SEE_MASK_NOCLOSEPROCESS;
252 shex_info.hwnd = GetActiveWindow();
253 shex_info.lpVerb = L"runas";
254 shex_info.lpFile = file.c_str();
255 shex_info.lpParameters = arguments.c_str();
256 shex_info.lpDirectory = NULL;
257 shex_info.nShow = options.start_hidden ? SW_HIDE : SW_SHOW;
258 shex_info.hInstApp = NULL;
259
260 if (!ShellExecuteEx(&shex_info)) {
261 DPLOG(ERROR);
262 return false;
263 }
264
265 if (options.wait)
266 WaitForSingleObject(shex_info.hProcess, INFINITE);
267
268 // If the caller wants the process handle give it to them, otherwise just
269 // close it. Closing it does not terminate the process.
270 if (process_handle)
271 *process_handle = shex_info.hProcess;
272 else
273 CloseHandle(shex_info.hProcess);
274
275 return true;
276 }
277
242 bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) { 278 bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) {
243 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0}; 279 JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
244 limit_info.BasicLimitInformation.LimitFlags = limit_flags; 280 limit_info.BasicLimitInformation.LimitFlags = limit_flags;
245 return 0 != SetInformationJobObject( 281 return 0 != SetInformationJobObject(
246 job_object, 282 job_object,
247 JobObjectExtendedLimitInformation, 283 JobObjectExtendedLimitInformation,
248 &limit_info, 284 &limit_info,
249 sizeof(limit_info)); 285 sizeof(limit_info));
250 } 286 }
251 287
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 WaitForSingleObject(proc_info.process_handle(), INFINITE); 359 WaitForSingleObject(proc_info.process_handle(), INFINITE);
324 360
325 return true; 361 return true;
326 } 362 }
327 363
328 void RaiseProcessToHighPriority() { 364 void RaiseProcessToHighPriority() {
329 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); 365 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
330 } 366 }
331 367
332 } // namespace base 368 } // namespace base
OLDNEW
« no previous file with comments | « base/process/launch.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698