mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-09 08:29:00 +00:00
Launch Windows PowerShell from its system path
This commit is contained in:
@@ -392,9 +392,12 @@ pub fn printers_parsed(queues: &str, available: Option<&str>) -> Vec<Printer> {
|
||||
|
||||
/// 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");
|
||||
|
||||
@@ -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:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user