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

Unified 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: Moves whitelist to a new file, adds new OWNERS reviewers for that file. Also fixes ordering of met… 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 side-by-side diff with in-line comments
Download patch
Index: base/process/launch_win.cc
diff --git a/base/process/launch_win.cc b/base/process/launch_win.cc
index da913efba749089592644c627c2dc226dbfa6182..2e333c34fd7ccb207d71b1e5d49f41e45999304c 100644
--- a/base/process/launch_win.cc
+++ b/base/process/launch_win.cc
@@ -9,6 +9,7 @@
#include <windows.h>
#include <userenv.h>
#include <psapi.h>
+#include <Shellapi.h>
#include <ios>
@@ -195,6 +196,41 @@ bool LaunchProcess(const CommandLine& cmdline,
return LaunchProcess(cmdline.GetCommandLineString(), options, process_handle);
}
+bool LaunchElevatedProcess(const CommandLine& cmdline,
+ const LaunchOptions& options,
+ ProcessHandle* process_handle) {
+ const std::wstring file = cmdline.GetProgram().value();
Nico 2014/02/05 05:38:11 No wstrings in new code, use string16.
Drew Haven 2014/02/05 20:13:22 Done.
+ const std::wstring arguments = cmdline.GetArgumentsString();
+
+ SHELLEXECUTEINFO shex_info = {0};
+ shex_info.cbSize = sizeof(shex_info);
+ shex_info.fMask = SEE_MASK_NOCLOSEPROCESS;
+ shex_info.hwnd = GetActiveWindow();
+ shex_info.lpVerb = L"runas";
+ shex_info.lpFile = file.c_str();
+ shex_info.lpParameters = arguments.c_str();
+ shex_info.lpDirectory = NULL;
+ shex_info.nShow = options.start_hidden ? SW_HIDE : SW_SHOW;
+ shex_info.hInstApp = NULL;
+
+ if (!ShellExecuteEx(&shex_info)) {
+ DPLOG(ERROR);
+ return false;
+ }
+
+ if (options.wait)
+ WaitForSingleObject(shex_info.hProcess, INFINITE);
+
+ // If the caller wants the process handle give it to them, otherwise just
+ // close it. Closing it does not terminate the process.
+ if (process_handle)
+ *process_handle = shex_info.hProcess;
+ else
+ CloseHandle(shex_info.hProcess);
+
+ return true;
+}
+
bool SetJobObjectLimitFlags(HANDLE job_object, DWORD limit_flags) {
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
limit_info.BasicLimitInformation.LimitFlags = limit_flags;

Powered by Google App Engine
This is Rietveld 408576698