From 8ece0346d894236430d5b2d189864066f763a2dc Mon Sep 17 00:00:00 2001 From: Nils <52573120+niStee@users.noreply.github.com> Date: Thu, 1 Aug 2024 03:50:48 +0200 Subject: [PATCH] chore: improve Windows Update step and add PSWindowsUpdate Module (#842) * chore: improve Windows Update step and add PSWindowsUpdate Module Refactor the `windows_update` function in `windows.rs` to improve the Windows Update step. Added a prompt for administrator privileges and updated the warning message. Also, added support for installing the PSWindowsUpdate Module as an alternative to using USOClient for Windows Update. still see warning: The installer will request to run as administrator, expect a prompt. Start-Process : A parameter cannot be found that matches parameter name 'Command'. At line:1 char:74 + ... ath powershell -Verb runAs -ArgumentList -NoProfile -Command Import- ... + ~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand VERBOSE: MSI-THIN-GF36 (6/30/2024 4:48:48 PM): Connecting to Microsoft Update server. Please wait... VERBOSE: Found [0] Updates in pre search criteria but as the verbose shows it works * trying * fix --- src/steps/os/windows.rs | 4 +++- src/steps/powershell.rs | 22 +++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index a5f32e8d..a9d17864 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -204,10 +204,12 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> { print_separator("Windows Update"); if powershell.supports_windows_update() { + println!("The installer will request to run as administrator, expect a prompt."); + powershell.windows_update(ctx) } else { print_warning( - "Consider installing PSWindowsUpdate as the use of Windows Update via USOClient is not supported.", + "Consider installing PSWindowsUpdate Module as the use of Windows Update via USOClient is not supported.", ); Err(SkipStep("USOClient not supported.".to_string()).into()) diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index b5e5b67d..fbf482f0 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -95,9 +95,16 @@ impl Powershell { #[cfg(windows)] pub fn windows_update(&self, ctx: &ExecutionContext) -> Result<()> { let powershell = require_option(self.path.as_ref(), String::from("Powershell is not installed"))?; - debug_assert!(self.supports_windows_update()); + let accept_all = if ctx.config().accept_all_windows_updates() { + "-AcceptAll" + } else { + "" + }; + + let install_windowsupdate_verbose = "Install-WindowsUpdate -Verbose".to_string(); + let mut command = if let Some(sudo) = ctx.sudo() { let mut command = ctx.run_type().execute(sudo); command.arg(powershell); @@ -107,18 +114,7 @@ impl Powershell { }; command - .args([ - "-NoProfile", - "-Command", - &format!( - "Start-Process powershell -Verb runAs -ArgumentList 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate {} -Verbose'", - if ctx.config().accept_all_windows_updates() { - "-AcceptAll" - } else { - "" - } - ), - ]) + .args(["-NoProfile", &install_windowsupdate_verbose, accept_all]) .status_checked() } }