/// <summary> /// Returns default environment for the process. /// If credentials are specified then the default environment is the default for that user. /// Otherwise the default is to inherit from this process. /// </summary> private Dictionary <string, string> CreateDefaultProcessEnvironment(NetworkCredential credential) { EnvironmentBlock envBlock = new EnvironmentBlock(); if (credential == null) { envBlock = EnvironmentBlock.Create(Environment.GetEnvironmentVariables()); } else { using (var safeUserToken = Utils.LogonAndGetUserPrimaryToken(credential)) { envBlock = EnvironmentBlock.CreateForUser(safeUserToken.DangerousGetHandle()); } } return(envBlock.ToDictionary()); }
/// <summary> /// Returns default environment for the process. /// If credentials are specified then the default environment is the default for that user. /// Otherwise the default is to inherit from this process. /// </summary> private Dictionary<string, string> CreateDefaultProcessEnvironment(NetworkCredential credential) { EnvironmentBlock envBlock = new EnvironmentBlock(); if (credential == null) { envBlock = EnvironmentBlock.Create(Environment.GetEnvironmentVariables()); } else { using (var safeUserToken = Utils.LogonAndGetUserPrimaryToken(credential)) { envBlock = EnvironmentBlock.CreateForUser(safeUserToken.DangerousGetHandle()); } } return envBlock.ToDictionary(); }