From 27ffc2b9ea4d3068dc606918b2b8fc7f019de2a5 Mon Sep 17 00:00:00 2001 From: nistee Date: Sun, 16 Feb 2025 18:50:43 +0100 Subject: [PATCH] refactor(powershell): update Microsoft Store update command execution and streamline output handling --- src/steps/powershell.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index 1a8120b6..cf895d96 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -183,27 +183,14 @@ mod windows { pub fn microsoft_store(powershell: &Powershell, ctx: &ExecutionContext) -> Result<()> { println!("{}", t!("Scanning for updates...")); - let update_command = "(Get-CimInstance -Namespace \"Root\\cimv2\\mdm\\dmmap\" \ - -ClassName \"MDM_EnterpriseModernAppManagement_AppManagement01\" | \ - Invoke-CimMethod -MethodName UpdateScanMethod).ReturnValue"; + let update_command = "Start-Process powershell -Verb RunAs -ArgumentList '-Command', \ + '(Get-CimInstance -Namespace \"Root\\cimv2\\mdm\\dmmap\" \ + -ClassName \"MDM_EnterpriseModernAppManagement_AppManagement01\" | \ + Invoke-CimMethod -MethodName UpdateScanMethod).ReturnValue'"; + powershell .build_command_internal(ctx, &["-Command", update_command])? - .output_checked_with_utf8(|output| { - if output.stdout.trim() == "0" { - println!( - "{}", - t!("Success, Microsoft Store apps are being updated in the background") - ); - Ok(()) - } else { - println!( - "{}", - t!("Unable to update Microsoft Store apps, manual intervention is required") - ); - Err(()) - } - }) - .map(|_| ()) + .status_checked() } fn has_module(powershell: &PathBuf, command: &str) -> bool {