From 45bfb0e22e4440080bfdd7927ff3358adf0a288e Mon Sep 17 00:00:00 2001 From: 21pages Date: Sun, 13 Nov 2022 18:38:24 +0800 Subject: [PATCH] portable-service: run background Signed-off-by: 21pages --- src/platform/windows.rs | 21 +++++++++++++++++++++ src/server/portable_service.rs | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index b418d0904..34f132894 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1480,6 +1480,27 @@ pub fn get_user_token(session_id: u32, as_user: bool) -> HANDLE { } } +pub fn run_background(exe: &str, arg: &str) -> ResultType { + let wexe = wide_string(exe); + let warg; + unsafe { + let ret = ShellExecuteW( + NULL as _, + NULL as _, + wexe.as_ptr() as _, + if arg.is_empty() { + NULL as _ + } else { + warg = wide_string(arg); + warg.as_ptr() as _ + }, + NULL as _, + SW_HIDE, + ); + return Ok(ret as i32 > 32); + } +} + pub fn run_uac(exe: &str, arg: &str) -> ResultType { let wop = wide_string("runas"); let wexe = wide_string(exe); diff --git a/src/server/portable_service.rs b/src/server/portable_service.rs index 9e3f11bc7..54f7a92dd 100644 --- a/src/server/portable_service.rs +++ b/src/server/portable_service.rs @@ -476,7 +476,12 @@ pub mod client { unsafe { libc::memset(shmem.as_ptr() as _, 0, shmem.len() as _); } - if crate::common::run_me(vec!["--portable-service"]).is_err() { + if crate::platform::run_background( + &std::env::current_exe()?.to_string_lossy().to_string(), + "--portable-service", + ) + .is_err() + { *SHMEM.lock().unwrap() = None; bail!("Failed to run portable service process"); }