Environment Variables in .NET

  • Thread starter Thread starter NetPointer
  • Start date Start date
N

NetPointer

How to set the environment variable?

I guess System.Environment gives readonly access to it.

Regards,
NetPointer.
 
Hi,

You can't change the environment variables of the current process, but what
you can do is to pass a new set of environment variables to a new Process
object through its StartInfo property. Another object is to use the
System.Management namespace, and finally, you could change the registry
directly.

Regards

Dennis
 
Last minute addition:

[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
public static extern void SetEnvironmentVariable(string name, string value);

Will do the trick as well.
 
Back
Top