3

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.

Lydon Ch
  • 8,637
  • 20
  • 79
  • 132
  • in general, an environment variable is only visible in the creating process and in 'children' of the creating process – user3629249 Mar 23 '18 at 16:17

1 Answers1

2

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.

pmcilreavy
  • 3,076
  • 2
  • 28
  • 37
  • we target EnvironmentVariableTarget.Process, which worked with everything but Win2016+VS-redist-2015) trying now with EnvironmentVariableTarget.Machine. thanks for the tip – Lydon Ch Mar 21 '18 at 05:15
  • 1
    EnvironmentVariableTarget.Machine did not work either. – Lydon Ch Mar 21 '18 at 05:34