Hi
I am having some problem in c#. Can someone help me with programmatically setting environment variables using C# ?
Thanks
Hi
I am having some problem in c#. Can someone help me with programmatically setting environment variables using C# ?
Thanks
If the value parameter is not emptyand the environment variable named by the variable parameter does not exist, the environment variable is created and assigned the contents of value. Solely for the purposes of this operation, value is considered empty if it is a null reference (Nothing in Visual Basic), contains a zero-length string, or contains an initial hexadecimal zero character (0x00). If variable contains a non-initial hexadecimal zero character, the characters before the zero character are considered the environment variable name and all subsequent characters are ignored.
SetEnvironmentVariable works for the current process and for processes launched from it. GetEnvironmentVariable(String) Retrieves the value of an environment variable from the current process.
Code:// Change the directory to %WINDIR% Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir"); DirectoryInfo info = new DirectoryInfo("."); lock(info) { Console.WriteLine("Directory Info: "+info.FullName); }
GetEnvironmentVariable(String, EnvironmentVariableTarget) : Retrieves the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.
Code:public static string GetEnvironmentVariable( string variable, EnvironmentVariableTarget target )
Bookmarks