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

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

Issue 2338133005: Add real_path option to LaunchProcess (Closed)
Patch Set: Add real_path option to LaunchProcess Created 4 years, 3 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
« base/process/launch.h ('K') | « base/process/launch_posix.cc ('k') | no next file » | 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 <shellapi.h>
10 #include <windows.h> 10 #include <windows.h>
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (options.force_breakaway_from_job_) 265 if (options.force_breakaway_from_job_)
266 flags |= CREATE_BREAKAWAY_FROM_JOB; 266 flags |= CREATE_BREAKAWAY_FROM_JOB;
267 267
268 PROCESS_INFORMATION temp_process_info = {}; 268 PROCESS_INFORMATION temp_process_info = {};
269 269
270 LPCTSTR current_directory = options.current_directory.empty() 270 LPCTSTR current_directory = options.current_directory.empty()
271 ? nullptr 271 ? nullptr
272 : options.current_directory.value().c_str(); 272 : options.current_directory.value().c_str();
273 273
274 string16 writable_cmdline(cmdline); 274 string16 writable_cmdline(cmdline);
275 const char16* executable_path = !options.real_path.empty() ?
276 options.real_path.value().c_str() : nullptr;
275 if (options.as_user) { 277 if (options.as_user) {
276 flags |= CREATE_UNICODE_ENVIRONMENT; 278 flags |= CREATE_UNICODE_ENVIRONMENT;
277 void* enviroment_block = nullptr; 279 void* enviroment_block = nullptr;
278 280
279 if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE)) { 281 if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE)) {
280 DPLOG(ERROR); 282 DPLOG(ERROR);
281 return Process(); 283 return Process();
282 } 284 }
283 285
284 BOOL launched = CreateProcessAsUser( 286 BOOL launched = CreateProcessAsUser(
285 options.as_user, nullptr, &writable_cmdline[0], nullptr, nullptr, 287 options.as_user, executable_path, &writable_cmdline[0], nullptr,
286 inherit_handles, flags, enviroment_block, current_directory, 288 nullptr, inherit_handles, flags, enviroment_block, current_directory,
287 startup_info, &temp_process_info); 289 startup_info, &temp_process_info);
288 DestroyEnvironmentBlock(enviroment_block); 290 DestroyEnvironmentBlock(enviroment_block);
289 if (!launched) { 291 if (!launched) {
290 DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline) 292 DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline)
291 << std::endl; 293 << std::endl;
292 return Process(); 294 return Process();
293 } 295 }
294 } else { 296 } else {
295 if (!CreateProcess(nullptr, &writable_cmdline[0], nullptr, nullptr, 297 if (!CreateProcess(executable_path, &writable_cmdline[0], nullptr, nullptr,
296 inherit_handles, flags, nullptr, current_directory, 298 inherit_handles, flags, nullptr, current_directory,
297 startup_info, &temp_process_info)) { 299 startup_info, &temp_process_info)) {
298 DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline) 300 DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline)
299 << std::endl; 301 << std::endl;
300 return Process(); 302 return Process();
301 } 303 }
302 } 304 }
303 base::win::ScopedProcessInformation process_info(temp_process_info); 305 base::win::ScopedProcessInformation process_info(temp_process_info);
304 306
305 if (options.job_handle) { 307 if (options.job_handle) {
306 if (0 == AssignProcessToJobObject(options.job_handle, 308 if (0 == AssignProcessToJobObject(options.job_handle,
307 process_info.process_handle())) { 309 process_info.process_handle())) {
308 DLOG(ERROR) << "Could not AssignProcessToObject."; 310 DLOG(ERROR) << "Could not AssignProcessToObject.";
309 Process scoped_process(process_info.TakeProcessHandle()); 311 Process scoped_process(process_info.TakeProcessHandle());
310 scoped_process.Terminate(kProcessKilledExitCode, true); 312 scoped_process.Terminate(kProcessKilledExitCode, true);
311 return Process(); 313 return Process();
312 } 314 }
313 315
314 ResumeThread(process_info.thread_handle()); 316 ResumeThread(process_info.thread_handle());
315 } 317 }
316 318
317 if (options.wait) 319 if (options.wait)
318 WaitForSingleObject(process_info.process_handle(), INFINITE); 320 WaitForSingleObject(process_info.process_handle(), INFINITE);
319 321
320 return Process(process_info.TakeProcessHandle()); 322 return Process(process_info.TakeProcessHandle());
321 } 323 }
322 324
323 Process LaunchElevatedProcess(const CommandLine& cmdline, 325 Process LaunchElevatedProcess(const CommandLine& cmdline,
324 const LaunchOptions& options) { 326 const LaunchOptions& options) {
325 const string16 file = cmdline.GetProgram().value(); 327 const string16 file = !options.real_path.empty() ?
328 options.real_path.value() : cmdline.GetProgram().value();
326 const string16 arguments = cmdline.GetArgumentsString(); 329 const string16 arguments = cmdline.GetArgumentsString();
327 330
328 SHELLEXECUTEINFO shex_info = {}; 331 SHELLEXECUTEINFO shex_info = {};
329 shex_info.cbSize = sizeof(shex_info); 332 shex_info.cbSize = sizeof(shex_info);
330 shex_info.fMask = SEE_MASK_NOCLOSEPROCESS; 333 shex_info.fMask = SEE_MASK_NOCLOSEPROCESS;
331 shex_info.hwnd = GetActiveWindow(); 334 shex_info.hwnd = GetActiveWindow();
332 shex_info.lpVerb = L"runas"; 335 shex_info.lpVerb = L"runas";
333 shex_info.lpFile = file.c_str(); 336 shex_info.lpFile = file.c_str();
334 shex_info.lpParameters = arguments.c_str(); 337 shex_info.lpParameters = arguments.c_str();
335 shex_info.lpDirectory = nullptr; 338 shex_info.lpDirectory = nullptr;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 370
368 bool GetAppOutput(const StringPiece16& cl, std::string* output) { 371 bool GetAppOutput(const StringPiece16& cl, std::string* output) {
369 return GetAppOutputInternal(cl, false, output); 372 return GetAppOutputInternal(cl, false, output);
370 } 373 }
371 374
372 void RaiseProcessToHighPriority() { 375 void RaiseProcessToHighPriority() {
373 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); 376 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
374 } 377 }
375 378
376 } // namespace base 379 } // namespace base
OLDNEW
« base/process/launch.h ('K') | « base/process/launch_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698