如何使子进程相同的环境变量parrent,再加上它在windows自己的? [英] How make child process with same environment variables as parrent plus it's own in windows?

查看:269
本文介绍了如何使子进程相同的环境变量parrent,再加上它在windows自己的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建我使用的CreateProcess 函数新子proccess窗口:

In windows for creating new child proccess I'm using CreateProcess function:

BOOL WINAPI CreateProcess(
  __in_opt     LPCTSTR lpApplicationName,
  __inout_opt  LPTSTR lpCommandLine,
  __in_opt     LPSECURITY_ATTRIBUTES lpProcessAttributes,
  __in_opt     LPSECURITY_ATTRIBUTES lpThreadAttributes,
  __in         BOOL bInheritHandles,
  __in         DWORD dwCreationFlags,
  __in_opt     LPVOID lpEnvironment,
  __in_opt     LPCTSTR lpCurrentDirectory,
  __in         LPSTARTUPINFO lpStartupInfo,
  __out        LPPROCESS_INFORMATION lpProcessInformation
);

在这里我们可以看到,的CreateProcess 即可获得 lpEnvironment 参数指定新进程的环境变量,如果它是NULL ,孩子就会有相同的环境中parrent。现在,我希望孩子有作为parrent加上环境 lpEnvironment 瓦尔指定相同的环境(父进程,即合并后的环境和特定的)。建议你将如何做到这一点?我应该采取母公司所有ENVS,用新的合并他们,他们都传递给的CreateProcess

Here we can see that CreateProcess can get lpEnvironment parameter to specify environment variables of new process and if it's NULL, the child will have same environment as parrent. Now I want the child to have same environment as parrent plus environment vars specified in lpEnvironment (i.e. merged environment of parent process and specified ones). How would you suggest to do this? Should I take all envs of parent, merge them with new ones and pass them all to CreateProcess?

推荐答案

使用的 GETENV 获得CRT ENV添加自己并设置

use getenv to get crt env add your own and set

这篇关于如何使子进程相同的环境变量parrent,再加上它在windows自己的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆