Setting environment variables for a specific start of a specific process

Is it possible to set environment variables for process "A" so that they are only valid for its current start (process "A" will be started by my process) using C ++?

0
c ++ windows environment-variables
source share
2 answers

Assuming you're ready to rely on the Windows API when you call the CreateProcess function to start the process, you have lpEnvironment .

Usually you pass NULL , which means use the creation process environment. However, you can provide an environment block that will be used by the new process.

The protection block that you pass is a zero-terminated block with zero-termination. For example:

 "MyVar=MyValue\0MyOtheVar=MyOtherValue\0\0" 

defines two separate variables.

+3
source share

If changing environment variables is not a problem for your current process, see Setting environment variables in C ++ .

Tip. All programs created by your process will only have environment variables and the values ​​that you provide to them.

0
source share

All Articles