I've implemented a system service running as system user which is spawning a child process running as another user with the environment variables of this user. Launching a COM object as local server by CoCreateInstance inherits the environment variables from the system user, but not from the user of the child process.
What I have tried:
HANDLE hToken = NULL;
LogonUser(
L"username", L"domain", L"password",
LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,
&hToken); {
void* lpEnvironment = NULL;
CreateEnvironmentBlock(&lpEnvironment, hToken, TRUE);
CreateProcessAsUser(
hToken, procname, cmdline,
NULL, NULL, FALSE,
CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS |CREATE_UNICODE_ENVIRONMENT,
lpEnvironment, NULL, &startupInfo, &procInfo);
In this child process I'm launching a COM objects as local server with
CoCreateInstance. The process runs as the user defined in the first step, but with the environment variables from the system user.
IUnknown* pUnk = nullptr;
CoCreateInstance(
clsid, NULL, CLSCTX_LOCAL_SERVER,
IID_IUnknown, (void**)&pUnk);
Is there any way I can launch the COM object with the environment variables from the child process which was created in the first step.
I'm aware of the dcomcnfg tool. In its
identity tab, the standard option
The launching user is set. I would assume in this case the environment variables from the child process would be used, but they are not. Changing the option to
Interactive user or
This user has the intended effect, but there seems not to be a way to get the environment variables from the child process.