Skip to content

Commit dcd3581

Browse files
authored
Move pre-check errors to post-check (#6236)
## 📖 Description We had some pre-check errors for various issues in the OS. Move those to attempt the operation and convert any failures in the scenario on the older OS to the well-known HRESULT.
1 parent 8c6f3da commit dcd3581

3 files changed

Lines changed: 36 additions & 29 deletions

File tree

src/AppInstallerCLICore/Workflows/InstallFlow.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,6 @@ namespace AppInstaller::CLI::Workflow
211211

212212
bool isMachineScope = Manifest::ConvertToScopeEnum(context.Args.GetArg(Execution::Args::Type::InstallScope)) == Manifest::ScopeEnum::Machine;
213213

214-
// TODO: There was a bug in deployment api if provision api was called in packaged context.
215-
// Remove this check when the OS bug is fixed and back ported.
216-
if (isMachineScope && Runtime::IsRunningInPackagedContext())
217-
{
218-
context.Reporter.Error() << Resource::String::InstallFlowReturnCodeSystemNotSupported << std::endl;
219-
context.Add<Execution::Data::OperationReturnCode>(static_cast<DWORD>(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED));
220-
AICLI_LOG(CLI, Error, << "Device wide install for msix type is not supported in packaged context.");
221-
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED);
222-
}
223-
224214
context.Reporter.Info() << Resource::String::InstallFlowStartingPackageInstall << std::endl;
225215

226216
bool registrationDeferred = false;
@@ -241,6 +231,18 @@ namespace AppInstaller::CLI::Workflow
241231
}
242232
catch (const wil::ResultException& re)
243233
{
234+
// There was a bug in the deployment provision API when called in a packaged context,
235+
// fixed in 10.0.26100.0. On older OS versions, convert any failure under these conditions
236+
// to the error that was previously always returned.
237+
if (isMachineScope && Runtime::IsRunningInPackagedContext() &&
238+
!Runtime::IsCurrentOSVersionGreaterThanOrEqual(Utility::Version{ "10.0.26100.0" }))
239+
{
240+
context.Reporter.Error() << Resource::String::InstallFlowReturnCodeSystemNotSupported << std::endl;
241+
context.Add<Execution::Data::OperationReturnCode>(static_cast<DWORD>(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED));
242+
AICLI_LOG(CLI, Error, << "Device wide install for msix type is not supported in packaged context on this OS version. Error: " << re.GetErrorCode());
243+
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED);
244+
}
245+
244246
context.Add<Execution::Data::OperationReturnCode>(re.GetErrorCode());
245247
context << ReportInstallerResult("MSIX"sv, re.GetErrorCode(), /* isHResult */ true);
246248
return;

src/AppInstallerCLICore/Workflows/UninstallFlow.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,6 @@ namespace AppInstaller::CLI::Workflow
366366
{
367367
bool isMachineScope = Manifest::ConvertToScopeEnum(context.Args.GetArg(Execution::Args::Type::InstallScope)) == Manifest::ScopeEnum::Machine;
368368

369-
// TODO: There was a bug in deployment api if deprovision api was called in packaged context.
370-
// Remove this check when the OS bug is fixed and back ported.
371-
if (isMachineScope && Runtime::IsRunningInPackagedContext())
372-
{
373-
context.Reporter.Error() << Resource::String::InstallFlowReturnCodeSystemNotSupported << std::endl;
374-
context.Add<Execution::Data::OperationReturnCode>(static_cast<DWORD>(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED));
375-
AICLI_LOG(CLI, Error, << "Device wide uninstall for msix type is not supported in packaged context.");
376-
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED);
377-
}
378-
379369
const auto& packageFamilyNames = context.Get<Execution::Data::PackageFamilyNames>();
380370
context.Reporter.Info() << Resource::String::UninstallFlowStartingPackageUninstall << std::endl;
381371

@@ -402,6 +392,18 @@ namespace AppInstaller::CLI::Workflow
402392
}
403393
catch (const wil::ResultException& re)
404394
{
395+
// There was a bug in the deployment deprovision API when called in a packaged context,
396+
// fixed in 10.0.26100.0. On older OS versions, convert any failure under these conditions
397+
// to the error that was previously always returned.
398+
if (isMachineScope && Runtime::IsRunningInPackagedContext() &&
399+
!Runtime::IsCurrentOSVersionGreaterThanOrEqual(Utility::Version{ "10.0.26100.0" }))
400+
{
401+
context.Reporter.Error() << Resource::String::InstallFlowReturnCodeSystemNotSupported << std::endl;
402+
context.Add<Execution::Data::OperationReturnCode>(static_cast<DWORD>(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED));
403+
AICLI_LOG(CLI, Error, << "Device wide uninstall for msix type is not supported in packaged context on this OS version. Error: " << re.GetErrorCode());
404+
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED);
405+
}
406+
405407
context.Add<Execution::Data::OperationReturnCode>(re.GetErrorCode());
406408
context << ReportUninstallerResult("MSIXUninstall"sv, re.GetErrorCode(), /* isHResult */ true);
407409
return;

src/AppInstallerCommonCore/MSStore.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,6 @@ namespace AppInstaller::MSStore
401401

402402
if (m_scope == Manifest::ScopeEnum::Machine)
403403
{
404-
// TODO: There was a bug in InstallService where admin user is incorrectly identified as not admin,
405-
// causing false access denied on many OS versions.
406-
// Remove this check when the OS bug is fixed and back ported.
407-
if (!Runtime::IsRunningAsSystem())
408-
{
409-
AICLI_LOG(Core, Error, << "Device wide install for msstore type is not supported under admin context.");
410-
return APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED;
411-
}
412-
413404
installOptions.InstallForAllUsers(true);
414405
}
415406

@@ -438,6 +429,18 @@ namespace AppInstaller::MSStore
438429

439430
HRESULT hr = WaitForOperation(m_productId, m_isSilentMode, installItems, progress, monitor);
440431

432+
// There was a bug in InstallService where admin users were incorrectly identified as non-admin,
433+
// causing false access denied errors; fixed in 10.0.26100.0. On older OS versions, convert any
434+
// failure under these conditions to the error that was previously always returned.
435+
if (FAILED(hr) &&
436+
m_scope == Manifest::ScopeEnum::Machine &&
437+
!Runtime::IsRunningAsSystem() &&
438+
!Runtime::IsCurrentOSVersionGreaterThanOrEqual(Utility::Version{ "10.0.26100.0" }))
439+
{
440+
AICLI_LOG(Core, Error, << "Device wide install for msstore type is not supported under admin context on this OS version. Error: " << hr);
441+
return APPINSTALLER_CLI_ERROR_INSTALL_SYSTEM_NOT_SUPPORTED;
442+
}
443+
441444
bool shouldProvision = m_scope == Manifest::ScopeEnum::Machine;
442445
#ifndef AICLI_DISABLE_TEST_HOOKS
443446
if (TestHooks::s_ProvisionAfterInstall)

0 commit comments

Comments
 (0)