Skip to content

Environment Variables Return Null

Bryan

Asked Mar 13, 2010, 1:06 PM EST3 answers
Share
LinkedInX
I'm having a problem where my program is returning null for environment variables that my installer is setting. I checked the Advanced settings of the computer, and the variable values are all correct, but inside my program the values are returning null.

I'm using the following code to store the value: string envirVar = System.Environment.GetEnvironmentVariable("InstallUser");

Can anyone help?

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    make sure the environment variables are being permanently saved and not just Set by your installer.  There is a big difference.  One is in memory, the other is in a file in the registry.  SetX sets the variables using dos commands so the result is permanent.  You can check if the env variables are being permanently saved by going to the Advanced Setting on the Control Panel --> System
    0
  • 0
    They're not just being set, they are being permanently saved. I've restarted the computer, and the variables remain. It only happens on some machines. On my computer it is able to get the variable just fine, on others it returns null.
    0
  • 0
    Does anyone have any other ideas?
    0