winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Runtime.h (2194B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <AppInstallerVersions.h>
      5 #include <winget/LocIndependent.h>
      6 
      7 #include <filesystem>
      8 #include <memory>
      9 #include <string>
     10 #include <string_view>
     11 
     12 namespace AppInstaller::Runtime
     13 {
     14     // Determines whether the process is running in a packaged context or not.
     15     bool IsRunningInPackagedContext();
     16 
     17     // Determines the current version of the client and returns it.
     18     Utility::LocIndString GetClientVersion();
     19 
     20     // Gets the package family name of the current package (or empty string if not packaged).
     21     std::wstring GetPackageFamilyName();
     22 
     23     // Determines the current version of the package if running in a packaged context.
     24     Utility::LocIndString GetPackageVersion();
     25 
     26     // Gets a string representation of the OS version for debugging purposes.
     27     Utility::LocIndString GetOSVersion();
     28 
     29     // Gets the OS region.
     30     // This can be used as the current market.
     31     std::string GetOSRegion();
     32 
     33     // Determines whether the current OS version is >= the given one.
     34     // We treat the given Version struct as a standard 4 part Windows OS version.
     35     bool IsCurrentOSVersionGreaterThanOrEqual(const Utility::Version& version);
     36 
     37     // Determines whether the process is running with administrator privileges.
     38     bool IsRunningAsAdmin();
     39 
     40     // Determines whether the process is running with local system context.
     41     bool IsRunningAsSystem();
     42 
     43     // Determines whether the process is running with administrator or system privileges.
     44     bool IsRunningAsAdminOrSystem();
     45 
     46     // Determines whether the current token can be elevated.
     47     // This only returns true for tokens that are TokenElevationTypeLimited.
     48     // Thus, it will only be true if:
     49     //  1. UAC is enabled
     50     //  2. the user is in the Administrators group
     51     //  3. the token is not already elevated
     52     bool IsRunningWithLimitedToken();
     53 
     54     // Returns true if this is a release build; false if not.
     55     inline constexpr bool IsReleaseBuild()
     56     {
     57 #ifdef WINGET_ENABLE_RELEASE_BUILD
     58         return true;
     59 #else
     60         return false;
     61 #endif
     62     }
     63 }