Skip to content

Commit

Permalink
PR review comments fix Part 3:
Browse files Browse the repository at this point in the history
- When running as admin, block attempt to repair user scope installed package.
  • Loading branch information
Madhusudhan-MSFT committed Feb 15, 2024
1 parent e2868e2 commit 808ad02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSpecified);
WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSupported);
WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers);
WINGET_DEFINE_RESOURCE_STRINGID(NoAdminRepairForUserScopePackage);
WINGET_DEFINE_RESOURCE_STRINGID(NoExperimentalFeaturesMessage);
WINGET_DEFINE_RESOURCE_STRINGID(NoInstalledPackageFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoPackageFound);
Expand Down
14 changes: 14 additions & 0 deletions src/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ namespace AppInstaller::CLI::Workflow

std::wstring commandUtf16 = Utility::ConvertToUTF16(context.Get<Execution::Data::RepairString>());

// When running as admin, block attempt to repair user scope installed package.
if (Runtime::IsRunningAsAdmin())
{
auto installedPackageVersion = context.Get<Execution::Data::InstalledPackageVersion>();
const std::string installedScopeString = installedPackageVersion->GetMetadata()[PackageVersionMetadata::InstalledScope];
auto scopeEnum = ConvertToScopeEnum(installedScopeString);

if (scopeEnum == ScopeEnum::User)
{
context.Reporter.Warn() << Resource::String::NoAdminRepairForUserScopePackage << std::endl;
AICLI_TERMINATE_CONTEXT(E_ABORT);
}
}

// Parse the command string as application and command line for CreateProcess
wil::unique_cotaskmem_string app = nullptr;
wil::unique_cotaskmem_string args = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2810,4 +2810,7 @@ Please specify one of them using the --source option to proceed.</value>
<data name="RepairOperationNotSupported" xml:space="preserve">
<value>The installer technology in use does not support repair.</value>
</data>
<data name="NoAdminRepairForUserScopePackage" xml:space="preserve">
<value>The package installed for user scope cannot be repaired when running with administrator privileges.</value>
</data>
</root>

0 comments on commit 808ad02

Please sign in to comment.