升级问询

This commit is contained in:
zqm
2026-04-10 16:57:27 +08:00
parent 9f76e2c23d
commit af94e95809

View File

@@ -1390,9 +1390,13 @@ fn notify_app_upgrade(app_name: &str, current_ver: &str, latest_ver: &str, debug
{ {
use std::process::Command; use std::process::Command;
// 查找运行中的进程,获取 PID // 查找运行中的进程,获取 PID(使用 PowerShell Get-Process 更可靠)
let output = Command::new("tasklist") let ps_script = format!(
.args(["/FI", &format!("IMAGENAME eq {}.exe", app_name), "/FO", "CSV"]) "(Get-Process -Name '{}' -ErrorAction SilentlyContinue).Id",
app_name
);
let output = Command::new("powershell")
.args(["-NoProfile", "-NonInteractive", "-Command", &ps_script])
.output(); .output();
let output_bytes = match output { let output_bytes = match output {
@@ -1400,18 +1404,17 @@ fn notify_app_upgrade(app_name: &str, current_ver: &str, latest_ver: &str, debug
Err(_) => return, Err(_) => return,
}; };
let output_str = String::from_utf8_lossy(&output_bytes); let output_str = String::from_utf8_lossy(&output_bytes);
let lines: Vec<&str> = output_str.lines().collect();
// 解析 PID 列表(每行一个 PID
let mut pids: Vec<u32> = Vec::new(); let mut pids: Vec<u32> = Vec::new();
for line in lines { for line in output_str.lines() {
if line.contains(&format!("\"{}\"", app_name)) { let line = line.trim();
if let Some(pid_part) = line.split(",").nth(1) { if !line.is_empty() && line != "0" {
if let Ok(pid) = pid_part.trim_matches('"').parse::<u32>() { if let Ok(pid) = line.parse::<u32>() {
// 排除 Updater 自己 // 排除 Updater 自己
let current_pid = std::process::id(); let current_pid = std::process::id();
if pid != current_pid { if pid != current_pid {
pids.push(pid); pids.push(pid);
}
} }
} }
} }
@@ -1437,7 +1440,7 @@ fn notify_app_upgrade(app_name: &str, current_ver: &str, latest_ver: &str, debug
let pipe_server = pipe_name.replace("\\\\.\\pipe\\", ""); let pipe_server = pipe_name.replace("\\\\.\\pipe\\", "");
let ps_script = format!( let ps_script = format!(
r#" r#"
$pipe = [System.IO.Pipes.NamedPipeClientStream]::new(".", "{}", [System.IO.Pipes.PipeDirection]::Out) $pipe = [System.IO.Pipes.NamedPipeClientStream]::new(".", "{}", [System.IO.Pipes.PipeDirection]::InOut)
try {{ try {{
$pipe.Connect(3000) $pipe.Connect(3000)
$writer = [System.IO.StreamWriter]::new($pipe) $writer = [System.IO.StreamWriter]::new($pipe)