Lydon Ch
Lydon Ch

Reputation: 8815

Environment.SetEnvironmentVariable does not set any value

i'm encountering this issue with only

c# Environment.SetEnvironmentVariable(key,val, EnvironmentVariableTarget.Process) does not seem to set values that can be retrieved on the native-C app using getenv()

native-C app getenv() can read the values OK using Win2016 + VS-redist-2010

This works fine in Windows Server 2012 and 2008 using VS-redist-2015

Any thought / suggestion will be appreciated.

Upvotes: 3

Views: 1604

Answers (1)

Paul
Paul

Reputation: 3316

By default Environment.SetEnvironmentVariable(string <variable>, string <value>) stores variables for the current process. To be more sure you need to use the overload that contains the target Environment.SetEnvironmentVariable(string <variable>, string <value>, EnvironmentVariableTarget <target>). That way you can set the target to Machine or User.

Upvotes: 2

Related Questions