Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment.SetEnvironmentVariable does not set any value

i'm encountering this issue with only

  • Windows Server 2016 (Win2016) and
  • VisualStudio-redistributable 2015 (VS-redist-2015 = msvcp14)

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.

like image 925
Lydon Ch Avatar asked May 17 '26 00:05

Lydon Ch


1 Answers

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.

like image 153
pmcilreavy Avatar answered May 19 '26 13:05

pmcilreavy