diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 264c8b6dc2..32eb5b7535 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -480,9 +480,14 @@ private static void set_environment_options(ChocolateyConfiguration config) config.Information.Is64BitOperatingSystem = Environment.Is64BitOperatingSystem; config.Information.Is64BitProcess = (IntPtr.Size == 8); config.Information.IsInteractive = Environment.UserInteractive; + config.Information.UserName = System.Environment.UserName; + config.Information.UserDomainName = System.Environment.UserDomainName; config.Information.IsUserAdministrator = ProcessInformation.user_is_administrator(); + config.Information.IsUserSystemAccount = ProcessInformation.user_is_system(); + config.Information.IsUserRemoteDesktop = ProcessInformation.user_is_terminal_services(); + config.Information.IsUserRemote = ProcessInformation.user_is_remote(); config.Information.IsProcessElevated = ProcessInformation.process_is_elevated(); - + if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("https_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location)) { config.Proxy.Location = Environment.GetEnvironmentVariable("https_proxy"); diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 3f5575bdd9..e0c817d7c2 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -337,7 +337,12 @@ public sealed class InformationCommandConfiguration public bool Is64BitOperatingSystem { get; set; } public bool Is64BitProcess { get; set; } public bool IsInteractive { get; set; } + public string UserName { get; set; } + public string UserDomainName { get; set; } public bool IsUserAdministrator { get; set; } + public bool IsUserSystemAccount { get; set; } + public bool IsUserRemoteDesktop { get; set; } + public bool IsUserRemote { get; set; } public bool IsProcessElevated { get; set; } public bool IsLicensedVersion { get; set; } public string LicenseType { get; set; } diff --git a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs index 2f20225c42..78949a855d 100644 --- a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs +++ b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs @@ -75,7 +75,12 @@ public static void set_environment_variables(ChocolateyConfiguration config) // experimental until we know if this value returns correctly based on the OS and not the current process. Environment.SetEnvironmentVariable("OS_IS64BIT", config.Information.Is64BitOperatingSystem ? "true" : "false"); Environment.SetEnvironmentVariable("PROCESS_IS64BIT", config.Information.Is64BitProcess ? "true" : "false"); + Environment.SetEnvironmentVariable("USER_NAME", config.Information.UserName); + Environment.SetEnvironmentVariable("USER_DOMAIN", config.Information.UserDomainName); Environment.SetEnvironmentVariable("IS_ADMIN", config.Information.IsUserAdministrator ? "true" : "false"); + Environment.SetEnvironmentVariable("IS_SYSTEM", config.Information.IsUserSystemAccount ? "true" : "false"); + Environment.SetEnvironmentVariable("IS_REMOTEDESKTOP", config.Information.IsUserRemoteDesktop ? "true" : "false"); + Environment.SetEnvironmentVariable("IS_REMOTE", config.Information.IsUserRemote ? "true" : "false"); Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", config.Information.IsProcessElevated ? "true" : "false"); Environment.SetEnvironmentVariable("TEMP", config.CacheLocation); Environment.SetEnvironmentVariable("TMP", config.CacheLocation); diff --git a/src/chocolatey/infrastructure.app/templates/ChocolateyReadMeTemplate.cs b/src/chocolatey/infrastructure.app/templates/ChocolateyReadMeTemplate.cs index ce71d05207..9cce389d55 100644 --- a/src/chocolatey/infrastructure.app/templates/ChocolateyReadMeTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/ChocolateyReadMeTemplate.cs @@ -96,7 +96,11 @@ Chocolatey makes a number of environment variables available (You can access any * OS_PLATFORM - Like Windows, OSX, Linux. (0.9.9+) * OS_VERSION - The version of OS, like 6.1 something something for Windows. (0.9.9+) * OS_NAME - The reported name of the OS. (0.9.9+) + * USER_NAME = The user name (0.10.6+) + * USER_DOMAIN = The user domain name (could also be local computer name) (0.10.6+) * IS_PROCESSELEVATED = Is the process elevated? (0.9.9+) + * IS_SYSTEM = Is the user the system account? (0.10.6+) + * IS_REMOTEDESKTOP = Is the user in a terminal services session? (0.10.6+) * ChocolateyToolsLocation - formerly 'ChocolateyBinRoot' ('ChocolateyBinRoot' will be removed with Chocolatey v2.0.0), this is where tools being installed outside of Chocolatey packaging will go. (0.9.10+) #### Set By Options and Configuration @@ -116,6 +120,7 @@ Chocolatey makes a number of environment variables available (You can access any * ChocolateyPackageParametersSensitive - Package parameters passed from command line `--package-parameters-senstivite` that are not logged anywhere. (0.10.1+ and licensed editions 1.6.0+) * ChocolateyLicensedVersion - What version is the licensed edition on? * ChocolateyLicenseType - What edition / type of the licensed edition is installed? + * USER_CONTEXT - The original user context - different when self-service is used (Licensed v1.10.0+) #### Experimental Environment Variables The following are experimental or use not recommended: @@ -123,6 +128,7 @@ Chocolatey makes a number of environment variables available (You can access any * OS_IS64BIT = This may not return correctly - it may depend on the process the app is running under (0.9.9+) * CHOCOLATEY_VERSION_PRODUCT = the version of Choco that may match CHOCOLATEY_VERSION but may be different (0.9.9+) - based on git describe * IS_ADMIN = Is the user an administrator? But doesn't tell you if the process is elevated. (0.9.9+) + * IS_REMOTE = Is the user in a remote session? (0.10.6+) #### Not Useful Or Anti-Pattern If Used diff --git a/src/chocolatey/infrastructure/information/ProcessInformation.cs b/src/chocolatey/infrastructure/information/ProcessInformation.cs index c80b5e3fd2..28a5e89bff 100644 --- a/src/chocolatey/infrastructure/information/ProcessInformation.cs +++ b/src/chocolatey/infrastructure/information/ProcessInformation.cs @@ -116,6 +116,29 @@ public static bool process_is_elevated() return false; } + public static bool user_is_terminal_services() + { + return Environment.GetEnvironmentVariable("SESSIONNAME").to_string().contains("rdp-"); + } + + public static bool user_is_remote() + { + return user_is_terminal_services() || Environment.GetEnvironmentVariable("SESSIONNAME").to_string() == string.Empty; + } + + public static bool user_is_system() + { + if (Platform.get_platform() != PlatformType.Windows) return false; + + var isSystem = false; + + using (var identity = WindowsIdentity.GetCurrent()) + { + isSystem = identity.IsSystem; + } + + return isSystem; + } // ReSharper disable InconsistentNaming