[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Probably off-topic but need a pointer

FritzH

12/14/2008 9:35:00 PM

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!
3 Answers

Ian Collins

12/14/2008 9:51:00 PM

0

FritzH wrote:
> 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.

--
Ian Collins

Sam

12/14/2008 10:01:00 PM

0

FritzH writes:

> 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

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

> 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)

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.

FritzH

12/14/2008 10:20:00 PM

0

On Dec 15, 11:01 am, Sam <s...@email-scan.com> wrote:
> FritzH writes:
> > 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
>
> There is no such function in the C++ standard library. You must be referring
> to a library function on your operating system.
>
> > 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)
>
> 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!