I need to change thw environment variable Environment.GetEnvironmentVariable("TMP") for a Windows service in .NET 2.0 that is running with its own user account. The server is a Windows Server 2003, SP2. Can anybody tell me how to change the Windows environment variable for that user?
+2
A:
Just set the environment variable in your Main or OnStart method:
Environment.SetEnvironmentVariable("TMP", @"c:\temp");
Using SetEnvironmentVariable() changes the environment only for the running instance of the process, it doesn't change the user's system environment.
Hans Passant
2010-03-30 11:15:56