设置特定进程的特定运行的环境变量 [英] Setting environment variables for a specific run of a specific process
问题描述
是否可以使用C ++将过程A的环境变量设置为仅对其当前运行(过程A将由我的进程启动)有效的方式?
Is it possible to set the environment variables of a process "A" in a way that they will be valid only for its current run (process "A" will be started by my process) using C++?
推荐答案
假设您准备依靠Windows API,当您调用 CreateProcess
函数启动一个进程具有 lpEnvironment
参数。
Assuming you are prepared to rely on the Windows API, when you call the CreateProcess
function to launch a process, you have the lpEnvironment
parameter.
通常,您传递 NULL
,这意味着使用创建过程的环境。但是,您可以提供一个将由新进程使用的环境块。
Normally you pass NULL
which means, use the environment of the creating process. However, you can supply an environment block which will be used by the new process.
您传递的环境块是一个以null结尾的空字符串块。例如:
The environment block that you pass is a null-terminated block of null-terminated strings. For example:
"MyVar=MyValue\0MyOtheVar=MyOtherValue\0\0"
定义两个单独的变量。
这篇关于设置特定进程的特定运行的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!