升级问询
This commit is contained in:
@@ -1390,9 +1390,13 @@ fn notify_app_upgrade(app_name: &str, current_ver: &str, latest_ver: &str, debug
|
||||
{
|
||||
use std::process::Command;
|
||||
|
||||
// 查找运行中的进程,获取 PID
|
||||
let output = Command::new("tasklist")
|
||||
.args(["/FI", &format!("IMAGENAME eq {}.exe", app_name), "/FO", "CSV"])
|
||||
// 查找运行中的进程,获取 PID(使用 PowerShell Get-Process 更可靠)
|
||||
let ps_script = format!(
|
||||
"(Get-Process -Name '{}' -ErrorAction SilentlyContinue).Id",
|
||||
app_name
|
||||
);
|
||||
let output = Command::new("powershell")
|
||||
.args(["-NoProfile", "-NonInteractive", "-Command", &ps_script])
|
||||
.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,
|
||||
};
|
||||
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();
|
||||
for line in lines {
|
||||
if line.contains(&format!("\"{}\"", app_name)) {
|
||||
if let Some(pid_part) = line.split(",").nth(1) {
|
||||
if let Ok(pid) = pid_part.trim_matches('"').parse::<u32>() {
|
||||
// 排除 Updater 自己
|
||||
let current_pid = std::process::id();
|
||||
if pid != current_pid {
|
||||
pids.push(pid);
|
||||
}
|
||||
for line in output_str.lines() {
|
||||
let line = line.trim();
|
||||
if !line.is_empty() && line != "0" {
|
||||
if let Ok(pid) = line.parse::<u32>() {
|
||||
// 排除 Updater 自己
|
||||
let current_pid = std::process::id();
|
||||
if pid != current_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 ps_script = format!(
|
||||
r#"
|
||||
$pipe = [System.IO.Pipes.NamedPipeClientStream]::new(".", "{}", [System.IO.Pipes.PipeDirection]::Out)
|
||||
$pipe = [System.IO.Pipes.NamedPipeClientStream]::new(".", "{}", [System.IO.Pipes.PipeDirection]::InOut)
|
||||
try {{
|
||||
$pipe.Connect(3000)
|
||||
$writer = [System.IO.StreamWriter]::new($pipe)
|
||||
|
||||
Reference in New Issue
Block a user