Skip to content

Commit

Permalink
(GH-615) capture more user information
Browse files Browse the repository at this point in the history
Capture the following additional information about a user:

* Username
* User domain
* User is System?
* User is Remote?
  • Loading branch information
ferventcoder committed May 1, 2017
1 parent 4017e98 commit c46574a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -116,13 +120,15 @@ 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:
* 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
Expand Down
23 changes: 23 additions & 0 deletions src/chocolatey/infrastructure/information/ProcessInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c46574a

Please sign in to comment.