Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C++
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.


C++
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900