Results 1 to 4 of 4

Thread: c# environment variables

  1. #1
    Join Date
    May 2009
    Posts
    18

    c# environment variables

    Hi

    I am having some problem in c#. Can someone help me with programmatically setting environment variables using C# ?

    Thanks

  2. #2
    Join Date
    Dec 2008
    Posts
    106

    Re: c# environment variables

    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.

  3. #3
    Join Date
    Oct 2008
    Posts
    77

    Re: c# environment variables

    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);
                }

  4. #4
    Join Date
    May 2008
    Posts
    181

    Re: c# environment variables

    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
    )

Similar Threads

  1. What are an Environment Variables in PHP?
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 21-02-2010, 01:29 AM
  2. Replies: 3
    Last Post: 15-05-2009, 11:33 PM
  3. Replies: 2
    Last Post: 01-04-2009, 05:46 PM
  4. Setting environment variables?
    By Chaz in forum Vista Help
    Replies: 3
    Last Post: 18-01-2009, 09:22 AM
  5. set environment variables in script .bat
    By Creezeer in forum Windows Server Help
    Replies: 1
    Last Post: 14-03-2007, 12:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,963,841.66167 seconds with 17 queries