0

I am trying to create and access an environment variable in Windows 10.

I can create environment variables in System Properties >> Environment Variables, but whenever I try to access them using Environment.GetEnvironmentVariable(), the function fails to find the variable I created.

Instead, I have started using Environment.SetEnvironmentVariable() to create the desired variable, then I am able to access it using GetEnvironmentVariable(). Unfortunately this variable is not added to the System Environment variables, so I always have to create it at runtime.

Is there a better method for getting system environment variables? I don't want to hardcode the environment variable for security reasons, and I don't want to prompt the user to enter the information at runtime. I would prefer a solution that allows each user to manually create their own.

Flopdong
  • 259
  • 1
  • 3
  • 15
  • Editing the variables only modifies the registry. A process does not see the changes until it restarts *and* doesn't inherit its environment from its parent process. At a minimum you need to restart VS. If that still doesn't show the added variables then log out and log back in again. – Hans Passant Jul 13 '18 at 17:44
  • After creating your environment variable did you restart VS? – WBuck Jul 13 '18 at 18:03

0 Answers0