2024-09-20 09:52:13 +08:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
pub fn kill(name: &str) -> String {
|
|
|
|
|
Command::new("taskkill")
|
|
|
|
|
.args(&["/IM", name, "/F"])
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
format!("Killing {}", name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn run_steam() -> std::io::Result<std::process::Output> {
|
|
|
|
|
Command::new("cmd")
|
|
|
|
|
.args(&["/C", "start", "steam://run"])
|
|
|
|
|
.output()
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 16:02:47 +08:00
|
|
|
// FIXME wmic is deprecated
|
2024-09-20 09:52:13 +08:00
|
|
|
pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
|
|
|
|
|
let command = format!("/C wmic process where name='{}' get ExecutablePath", name);
|
|
|
|
|
let args = command.split_whitespace().collect::<Vec<&str>>();
|
|
|
|
|
let output = Command::new("cmd.exe").args(&args).output()?;
|
|
|
|
|
|
|
|
|
|
let out = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
|
|
|
|
|
|
|
|
if out.contains("ExecutablePath") {
|
|
|
|
|
let spt: Vec<&str> = out.split("\r\n").collect();
|
|
|
|
|
if spt.len() >= 2 {
|
|
|
|
|
return Ok(spt[1].to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(std::io::Error::new(
|
|
|
|
|
std::io::ErrorKind::Other,
|
|
|
|
|
"Failed to get executable path",
|
|
|
|
|
))
|
|
|
|
|
}
|
2025-03-21 16:02:47 +08:00
|
|
|
|
|
|
|
|
pub fn open_path(path: &str) -> Result<(), std::io::Error> {
|
|
|
|
|
let p = format!("file:///{}", path);
|
|
|
|
|
Command::new("explorer")
|
|
|
|
|
.args([p])
|
|
|
|
|
.spawn()
|
|
|
|
|
.expect("Failed to open path");
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|