C# Environment SetEnvironmentVariable(String, String, EnvironmentVariableTarget)

Description

Environment SetEnvironmentVariable(String, String, EnvironmentVariableTarget) creates, modifies, or deletes an environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.

Syntax

Environment.SetEnvironmentVariable(String, String, EnvironmentVariableTarget) has the following syntax.


public static void SetEnvironmentVariable(
  string variable,/*from w w w .  jav  a 2  s.com*/
  string value,
  EnvironmentVariableTarget target
)

Parameters

Environment.SetEnvironmentVariable(String, String, EnvironmentVariableTarget) has the following parameters.

  • variable - The name of an environment variable.
  • value - A value to assign to variable.
  • target - One of the EnvironmentVariableTarget values.

Returns

Environment.SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method returns

Example

The following example creates environment variables.


/*w ww.j  av a 2  s  . c o m*/

using System;
using System.Collections;
using Microsoft.Win32;

class Sample 
{
    public static void Main(){
       Environment.SetEnvironmentVariable("A_GETSET_ENVAR_SAMPLE", null, EnvironmentVariableTarget.Process);
    }
   
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version