diff --git a/apps/desktop/src-tauri/src/rustdesk.rs b/apps/desktop/src-tauri/src/rustdesk.rs index 3de5069..21f7dba 100644 --- a/apps/desktop/src-tauri/src/rustdesk.rs +++ b/apps/desktop/src-tauri/src/rustdesk.rs @@ -8,6 +8,7 @@ use reqwest::blocking::Client; use serde::Deserialize; use sha2::{Digest, Sha256}; use std::env; +use std::ffi::OsStr; use std::fs::{self, File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; @@ -15,6 +16,7 @@ use std::process::{Command, Stdio}; use std::thread; use std::time::Duration; use thiserror::Error; +use std::os::windows::process::CommandExt; const RELEASES_API: &str = "https://api.github.com/repos/rustdesk/rustdesk/releases/latest"; const USER_AGENT: &str = "RavenDesktop/1.0"; @@ -24,6 +26,7 @@ const DEFAULT_PASSWORD: &str = "FMQ9MA>e73r.FI> = Lazy::new(|| Mutex::new(())); @@ -209,7 +212,7 @@ fn download_latest_installer(cache_root: &Path) -> Result<(PathBuf, String), Rus } fn run_installer(installer_path: &Path) -> Result<(), RustdeskError> { - let status = Command::new(installer_path) + let status = hidden_command(installer_path) .arg("--silent-install") .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -292,7 +295,7 @@ api-server = "https://{host}" } fn apply_config(exe_path: &Path, config_path: &Path) -> Result<(), RustdeskError> { - let status = Command::new(exe_path) + let status = hidden_command(exe_path) .arg("--import-config") .arg(config_path) .stdout(Stdio::null()) @@ -336,7 +339,7 @@ fn ensure_service_running() -> Result<(), RustdeskError> { } fn run_sc(args: &[&str]) -> Result<(), RustdeskError> { - let status = Command::new("sc") + let status = hidden_command("sc") .args(args) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -370,7 +373,7 @@ fn query_id_with_retries(exe_path: &Path, attempts: usize) -> Result Result { - let output = Command::new(exe_path) + let output = hidden_command(exe_path) .arg("--get-id") .output()?; if !output.status.success() { @@ -387,7 +390,7 @@ fn query_id(exe_path: &Path) -> Result { } fn query_version(exe_path: &Path) -> Result { - let output = Command::new(exe_path) + let output = hidden_command(exe_path) .arg("--version") .output()?; if !output.status.success() { @@ -500,7 +503,7 @@ fn parse_assignment(line: &str, key: &str) -> Option { } fn run_with_args(exe_path: &Path, args: &[&str]) -> Result<(), RustdeskError> { - let status = Command::new(exe_path) + let status = hidden_command(exe_path) .args(args) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -514,6 +517,12 @@ fn run_with_args(exe_path: &Path, args: &[&str]) -> Result<(), RustdeskError> { Ok(()) } +fn hidden_command(program: impl AsRef) -> Command { + let mut cmd = Command::new(program); + cmd.creation_flags(CREATE_NO_WINDOW); + cmd +} + fn log_event(message: impl AsRef) { if let Some(dir) = logs_directory() { if let Err(error) = append_log(dir, message.as_ref()) {