Probably off-topic but need a pointer

F

FritzH

Hi folks,

This is probably off-topic for this group, but please feel free to
point me in the right direction.

I have a slight problem here - I'm trying to use CreateProcessAsUser
to run a process as a different user. However, it only runs it in that
user's security context (starts up fine, shows on the right desktop,
etc). I really need it to run as the target user, as the process being
launched depends on ActiveDirectory.

Can anyone give me a pointer? (pun not indended)

The code looks like this (error handling stripped out - all calls
succeed):

HANDLE hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE,
exProcId);
if (!hproc) ...

// Now get the process token
HANDLE orig_usertoken = 0;
if (!OpenProcessToken(hproc, TOKEN_ALL_ACCESS,
&orig_usertoken)) ...

CloseHandle(hproc);

// Create a duplicate of the user token for the
CreateProcessAsUser
call
HANDLE usertoken = NULL;
DuplicateTokenEx(orig_usertoken, MAXIMUM_ALLOWED, NULL,
SecurityDelegation, TokenPrimary, &usertoken);
if (!usertoken) ...

// if (!ImpersonateLoggedOnUser(usertoken)) ...

// Create a new environment block for the process
void* envblock;
if (!CreateEnvironmentBlock(&envblock, usertoken, FALSE)) ...

if (!CreateProcessAsUser(usertoken, NULL,
wcscmdline, // Has to be a writeable string
NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT,
envblock,
path.c_str(),
&startupInfo, &procinf)) ...

// if (!RevertToSelf()) ...

// Clean up after ourselves
//
**********************************************************************
//
//
CloseHandle(orig_usertoken);
CloseHandle(usertoken);
DestroyEnvironmentBlock(envblock);

cheers!
 
I

Ian Collins

FritzH said:
Hi folks,

This is probably off-topic for this group, but please feel free to
point me in the right direction.

I have a slight problem here - I'm trying to use CreateProcessAsUser
to run a process as a different user.

One of the many windows programming groups would be the place to ask.
This is windows specific.
 
F

FritzH

There is no such function in the C++ standard library. You must be referring
to a library function on your operating system.



You'll have a better chance of getting an answer by asking this question on
an appropriate microsoft.* newsgroup. The discussions on comp.lang.c++
are concerned with C++, the programming language. There are other
newsgroups for operating system-specific topics.

 application_pgp-signature_part
< 1KViewDownload

Hi Sam,

Cool, thanks for the pointer (I'm new to these groups)

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top