Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-07-2009
Member
 
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
Reply With Quote
  #2  
Old 13-07-2009
Member
 
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.
Reply With Quote
  #3  
Old 13-07-2009
Member
 
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);
            }
Reply With Quote
  #4  
Old 13-07-2009
Member
 
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
)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "c# environment variables"
Thread Thread Starter Forum Replies Last Post
What are an Environment Variables in PHP? N I C K Software Development 5 21-02-2010 01:29 AM
How to load/refresh environment variables WITHOUT leaving command prompt? troy Windows XP Support 3 15-05-2009 11:33 PM
How to change/add environment variables from command line PERMANENTLY? Moiz Windows XP Support 2 01-04-2009 05:46 PM
Setting environment variables? Chaz Vista Help 3 18-01-2009 09:22 AM
set environment variables in script .bat Creezeer Windows Server Help 1 14-03-2007 12:06 PM


All times are GMT +5.5. The time now is 08:23 PM.