From: Dorel Sturm on
Hi,

I'm using this code to create a process as user.

LogonUser()....

LoadUserProfile()....

CreateEnvironmentBlock()....

ImpersonateLogonUser()....

CreateProcessAsUser()....

RevertToSelf()....

DestroyEnvironmentBlock()...


So far so good this code works OK. However CreateEnvironmentBlock does not
return to me these environment variables:
HOMEDRIVE
HOMEPATH
HOMESHARE
(all other variables for that user are there).

When the user that I use in LogonUser() call is already logged on on that
computer then these three environment variables are there otherwise not. I
suspect that these three environment variables are created when shell
explorer is started after logon and executing logon scripts.

My question is when are this environment variables created? Who creates
them? How can I "create them on the fly"?

I tried to call UserInit.exe just before calling CreateEnvironmentBlock()
but this did not helped me. Also I don't want to start the complete Explorer
(or what else is setup for the user as shell environment) when I execute
this code.

Any ideas?

Thanks for the help.

Dorel Sturm






From: Stefan Kuhr on
Hi Dorel,

Dorel Sturm wrote:
>
> <snip>
> My question is when are this environment variables created? Who creates
> them? How can I "create them on the fly"?
>


Do a NetUserGetInfo with level 3 for the user and the computer's DC. The
USER_INFO_3 struct will contain home drive and home dir. You can create
the missing environment variables from these struct members.

Cheers,

--
Stefan

From: Dorel Sturm on
Hi Stefan,

Thanks for the idea however NetUserGetInfo does not work for me. All the
time when I do the call I get for usri3_home_dir_drive and usri3_home_dir
empty strings (not NULL strings but pointers to empty strings).
NetUserGetInfo call returns success and usri3_full_name gives me the full
name.

I found in HKEY_CURRENT_USER\Volatile Environment all the entries I need to
create the missing environment variables (HOMEPATH, APPDATA etc.). The
problem is that this registry entries are created I think by Explorer after
logon and after the shell is started.

After I call LoadUserProfile the hProfile member from PROFILEINFO points to
the HKEY_CURRENT_USER registry hive for that user. I can use this handle to
read registry keys for that user but not "Volatile Environment" because at
that point they are not yet created.

Any idea how to "create on the fly" the environment variables I see in
"Volatile Environment"?

Dorel Sturm

"Stefan Kuhr" <kustt110(a)gmx.li> wrote in message
news:%231S7LnmsHHA.4916(a)TK2MSFTNGP05.phx.gbl...
> Hi Dorel,
>
> Dorel Sturm wrote:
>>
>> <snip>
>> My question is when are this environment variables created? Who creates
>> them? How can I "create them on the fly"?
>>
>
>
> Do a NetUserGetInfo with level 3 for the user and the computer's DC. The
> USER_INFO_3 struct will contain home drive and home dir. You can create
> the missing environment variables from these struct members.
>
> Cheers,
>
> --
> Stefan
>