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

Unified Diff: base/process_util_win.cc

Issue 555192: Add a utility function to run a process as an arbitrary user... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 11 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
« no previous file with comments | « base/process_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_win.cc
===================================================================
--- base/process_util_win.cc (revision 37643)
+++ base/process_util_win.cc (working copy)
@@ -7,6 +7,7 @@
#include <fcntl.h>
#include <io.h>
#include <windows.h>
+#include <userenv.h>
#include <psapi.h>
#include <ios>
@@ -17,6 +18,9 @@
#include "base/scoped_handle_win.h"
#include "base/scoped_ptr.h"
+// userenv.dll is required for CreateEnvironmentBlock().
+#pragma comment(lib, "userenv.lib")
+
namespace base {
namespace {
@@ -162,6 +166,42 @@
return true;
}
+
+bool LaunchAppAsUser(UserTokenHandle token, const std::wstring& cmdline,
+ bool start_hidden, ProcessHandle* process_handle) {
ananta 2010/02/01 00:52:29 Would it make sense to take in the desired STARTUP
+ STARTUPINFO startup_info = {0};
+ startup_info.cb = sizeof(startup_info);
+ PROCESS_INFORMATION process_info;
+ if (start_hidden) {
+ startup_info.dwFlags = STARTF_USESHOWWINDOW;
+ startup_info.wShowWindow = SW_HIDE;
+ }
+ DWORD flags = CREATE_UNICODE_ENVIRONMENT;
+ void* enviroment_block = NULL;
+
+ if(!CreateEnvironmentBlock(&enviroment_block, token, FALSE))
+ return false;
+
+ BOOL launched =
+ CreateProcessAsUser(token, NULL, const_cast<wchar_t*>(cmdline.c_str()),
+ NULL, NULL, FALSE, flags, enviroment_block,
+ NULL, &startup_info, &process_info);
+
+ DestroyEnvironmentBlock(enviroment_block);
+
+ if (!launched)
+ return false;
+
+ CloseHandle(process_info.hThread);
+
+ if (process_handle) {
+ *process_handle = process_info.hProcess;
+ } else {
+ CloseHandle(process_info.hProcess);
+ }
+ return true;
+}
+
bool LaunchApp(const CommandLine& cl,
bool wait, bool start_hidden, ProcessHandle* process_handle) {
return LaunchApp(cl.command_line_string(), wait,
« no previous file with comments | « base/process_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698