Skip to content

Instantly share code, notes, and snippets.

@alex-codes
Created May 5, 2017 00:02
Show Gist options
  • Save alex-codes/ddee8d02142b8d47334d63ce7af55f58 to your computer and use it in GitHub Desktop.
Save alex-codes/ddee8d02142b8d47334d63ce7af55f58 to your computer and use it in GitHub Desktop.
Common Windows environment variables
public static class EnvironmentVariables
{
public static string ApplicationData
{
get { return GetVariable("APPDATA"); }
set { SetVariable("APPDATA", value); }
}
public static string ComputerName
{
get { return GetVariable("COMPUTERNAME"); }
set { SetVariable("COMPUTERNAME", value); }
}
public static string Date
{
get { return GetVariable("DATE"); }
set { SetVariable("DATE", value); }
}
public static string HomePath
{
get { return GetVariable("HOMEPATH"); }
set { SetVariable("HOMEPATH", value); }
}
public static string Path
{
get { return GetVariable("PATH"); }
set { SetVariable("PATH", value); }
}
public static string ProgramFiles
{
get { return GetVariable("PROGRAMFILES"); }
set { SetVariable("PROGRAMFILES", value); }
}
public static string Random
{
get { return GetVariable("RANDOM"); }
set { SetVariable("RANDOM", value); }
}
public static string SystemDrive
{
get { return GetVariable("SYSTEMDRIVE"); }
set { SetVariable("SYSTEMDRIVE", value); }
}
public static string Temp
{
get { return GetVariable("TEMP"); }
set { SetVariable("TEMP", value); }
}
public static string Tmp
{
get { return GetVariable("TMP"); }
set { SetVariable("TMP", value); }
}
public static string UserName
{
get { return GetVariable("USERNAME"); }
set { SetVariable("USERNAME", value); }
}
public static string UserProfile
{
get { return GetVariable("USERPROFILE"); }
set { SetVariable("USERPROFILE", value); }
}
public static string WindowsDirectory
{
get { return GetVariable("WINDIR"); }
set { SetVariable("WINDIR", value); }
}
public static string GetVariable(string variableName)
{
return Environment.GetEnvironmentVariable(variableName);
}
public static void SetVariable(string variableName, string value)
{
Environment.SetEnvironmentVariable(variableName, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment