Skip to content

Commit

Permalink
trying
Browse files Browse the repository at this point in the history
  • Loading branch information
niStee committed Jul 21, 2024
1 parent 6d7bbe4 commit e344f36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/steps/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {

Err(SkipStep("USOClient not supported.".to_string()).into())
}

}

pub fn reboot() -> Result<()> {
Expand Down
13 changes: 6 additions & 7 deletions src/steps/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,30 @@ 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 accept_all = if ctx.config().accept_all_windows_updates() {
"-AcceptAll"
} else {
""
};
let mut command = if let Some(sudo) = ctx.sudo() {
let mut command = ctx.run_type().execute(sudo);
command.arg(powershell);
command
} else {
ctx.run_type().execute(powershell)
};

// Correctly format the argument list for Start-Process
let argument_list = format!(
"-NoProfile -Command \"Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate {} -Verbose\"",
accept_all
);

// Correctly pass the entire PowerShell command as a single string to -ArgumentList
command
.args([
"-NoProfile",
"-Command",
&format!("Start-Process -FilePath powershell -Verb runAs -ArgumentList '{}'", argument_list),
&format!("Start-Process powershell -Verb runAs -ArgumentList '{}'", argument_list),
])
.status_checked()
}
Expand Down

0 comments on commit e344f36

Please sign in to comment.