public IValue GetEnvironmentVariable(string varName, EnvironmentVariableTargetEnum target = EnvironmentVariableTargetEnum.Process) { EnvironmentVariableTarget targetParam = GetSystemEnvVariableTarget(target); string value = System.Environment.GetEnvironmentVariable(varName, targetParam); if (value == null) { return(ValueFactory.Create()); } else { return(ValueFactory.Create(value)); } }
public MapImpl EnvironmentVariables(EnvironmentVariableTargetEnum target = EnvironmentVariableTargetEnum.Process) { EnvironmentVariableTarget targetParam = GetSystemEnvVariableTarget(target); var varsMap = new MapImpl(); var allVars = System.Environment.GetEnvironmentVariables(targetParam); foreach (DictionaryEntry item in allVars) { varsMap.Insert( ValueFactory.Create((string)item.Key), ValueFactory.Create((string)item.Value)); } return(varsMap); }
private static EnvironmentVariableTarget GetSystemEnvVariableTarget(EnvironmentVariableTargetEnum target) { EnvironmentVariableTarget targetParam = EnvironmentVariableTarget.Process; switch (target) { case EnvironmentVariableTargetEnum.Process: targetParam = EnvironmentVariableTarget.Process; break; case EnvironmentVariableTargetEnum.User: targetParam = EnvironmentVariableTarget.User; break; case EnvironmentVariableTargetEnum.Machine: targetParam = EnvironmentVariableTarget.Machine; break; } return(targetParam); }
public void SetEnvironmentVariable(string varName, string value, EnvironmentVariableTargetEnum target = EnvironmentVariableTargetEnum.Process) { EnvironmentVariableTarget targetParam = GetSystemEnvVariableTarget(target); System.Environment.SetEnvironmentVariable(varName, value, targetParam); }