From 32bcac12db98113d18d8f56bc47fb6ddabe4d54f Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Sun, 11 Oct 2026 22:09:14 +0200 Subject: [PATCH] Launch Windows PowerShell from its system path --- crates/print/src/lib.rs | 5 ++++- crates/print/src/tests.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/print/src/lib.rs b/crates/print/src/lib.rs index 875e60d1..f8ff9a77 100644 --- a/crates/print/src/lib.rs +++ b/crates/print/src/lib.rs @@ -392,9 +392,12 @@ pub fn printers_parsed(queues: &str, available: Option<&str>) -> Vec { /// The `powershell` command that runs a script. `-NoProfile` keeps a user's profile from /// writing banners into what is parsed, `-NonInteractive` from waiting for input. +/// The full system path avoids running a powershell.exe beside a portable app. #[cfg(windows)] fn powershell_command(script: &str) -> std::process::Command { - let mut c = std::process::Command::new("powershell"); + let root = std::env::var_os("SystemRoot").unwrap_or_else(|| "C:\\Windows".into()); + let exe = std::path::Path::new(&root).join("System32").join("WindowsPowerShell").join("v1.0").join("powershell.exe"); + let mut c = std::process::Command::new(exe); use std::os::windows::process::CommandExt as _; c.args(["-NoProfile", "-NonInteractive", "-Command", script]).creation_flags(0x0800_0000); c.env_remove("CRAFT_PRINT_DRYRUN").env_remove("CRAFT_PRINT_TEST_SETTINGS"); diff --git a/crates/print/src/tests.rs b/crates/print/src/tests.rs index 011f521c..019e5828 100644 --- a/crates/print/src/tests.rs +++ b/crates/print/src/tests.rs @@ -486,3 +486,14 @@ fn queue_duplex_defaults_and_explicit_scaling_reach_the_spooler() { assert!(shrink.iter().any(|a| a == "print-scaling=auto-fit")); assert!(!shrink.iter().any(|a| a.starts_with("fit-to-page="))); } + +/// A portable app must never resolve PowerShell from its own directory. +#[cfg(windows)] +#[test] +fn windows_starts_powershell_by_its_full_path() { + let command = powershell_command("$null"); + let program = std::path::Path::new(command.get_program()); + assert!(program.is_absolute(), "{program:?}"); + assert!(program.ends_with("System32/WindowsPowerShell/v1.0/powershell.exe"), "{program:?}"); + assert!(program.is_file(), "{program:?}"); +}