User Environment

mnashadka
mnashadka used Ask the Experts™
on
I'm using CreateProcessAsUser to spawn a new process as a different user.  I'm logging on successfully using LogonUser, and I have the 3 necessary privileges (SeAssignPrimaryTokenPrivilege, SeIncreaseQuotaPrivilege, and SeTcbPrivilege).  I'm trying to use CreateEnvironmentBlock and sending that to CreateProcessAsUser.  The process is started, but there is no environment.  For instance, the PATH variable is empty.  What am I missing to get the process to spawn with the user's environment variables?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
>>What am I missing to get the process to spawn with the user's environment variables?

There are several possibilities why that could fail, the most likely to be is that th euser profile is not loaded - see http://support.microsoft.com/default.aspx?scid=KB;en-us;305136& ("BUG: CreateEnvironmentBlock Fails With Error 203 If the User's Profile Is Not Loaded")

BTW, I actually would use

LogonUser ( ...);

ImpersonateLoggedOnUser ( ...);

LPVOID lpEnvironment = GetEnvironmentStrings (); // pass this to 'CreateProcess()'

//...

RevertToSelf ();

Author

Commented:
CreateEnvironmentBlock was actually successful (at least according to the return code), but I changed it to use Impersonate and it worked.  Thanks a lot!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial