diff --git a/Cargo.lock b/Cargo.lock index 159eee6e..0bc360fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2559,7 +2559,7 @@ dependencies = [ [[package]] name = "impersonate_system" version = "0.1.0" -source = "git+https://github.com/21pages/impersonate-system#af4a82050580217a434c2024e181a98de24823ec" +source = "git+https://github.com/21pages/impersonate-system#c48f37a8fd17413b2a4ba655c3873bdc5c8d25aa" dependencies = [ "cc", ] diff --git a/flutter/lib/desktop/pages/desktop_home_page.dart b/flutter/lib/desktop/pages/desktop_home_page.dart index b6552515..152463c6 100644 --- a/flutter/lib/desktop/pages/desktop_home_page.dart +++ b/flutter/lib/desktop/pages/desktop_home_page.dart @@ -412,15 +412,6 @@ class _DesktopHomePageState extends State @override void initState() { super.initState(); - Timer(const Duration(seconds: 1), () async { - final installed = bind.mainIsInstalled(); - final root = await bind.mainIsRoot(); - final release = await bind.mainIsRelease(); - if (Platform.isWindows && release && !installed && !root) { - msgBox('custom-elevation-nocancel', 'Prompt', 'elevation_prompt', '', - gFFI.dialogManager); - } - }); Timer(const Duration(seconds: 5), () async { updateUrl = await bind.mainGetSoftwareUpdateUrl(); if (updateUrl.isNotEmpty) setState(() {}); diff --git a/src/core_main.rs b/src/core_main.rs index 8c6430ef..46088da5 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -85,11 +85,6 @@ pub fn core_main() -> Option> { .ok(); } } - #[cfg(windows)] - #[cfg(not(debug_assertions))] - if !crate::platform::is_installed() && args.is_empty() { - crate::platform::elevate_or_run_as_system(is_setup, _is_elevate, _is_run_as_system); - } if args.is_empty() { std::thread::spawn(move || crate::start_server(false)); } else { diff --git a/src/lang/en.rs b/src/lang/en.rs index 7c95f8ab..72aa4585 100644 --- a/src/lang/en.rs +++ b/src/lang/en.rs @@ -34,5 +34,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("uac_warning", "Temporarily denied access due to elevation request, please wait for the remote user to accept the UAC dialog. To avoid this problem, it is recommended to install the software on the remote device or run it with administrator privileges."), ("elevated_foreground_window_warning", "Temporarily unable to use the mouse and keyboard, because the current window of the remote desktop requires higher privilege to operate, you can request the remote user to minimize the current window. To avoid this problem, it is recommended to install the software on the remote device or run it with administrator privileges."), ("JumpLink", "View"), + ("Stop service", "Stop Service"), ].iter().cloned().collect(); } diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 53fb60bd..ed9ac7e9 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -21,7 +21,10 @@ use winapi::{ errhandlingapi::GetLastError, handleapi::CloseHandle, minwinbase::STILL_ACTIVE, - processthreadsapi::{GetCurrentProcess, GetExitCodeProcess, OpenProcess, OpenProcessToken}, + processthreadsapi::{ + GetCurrentProcess, GetCurrentProcessId, GetExitCodeProcess, OpenProcess, + OpenProcessToken, + }, securitybaseapi::GetTokenInformation, shellapi::ShellExecuteA, winbase::*, @@ -878,23 +881,35 @@ fn get_install_info_with_subkey(subkey: String) -> (String, String, String, Stri (subkey, path, start_menu, exe) } -pub fn copy_exe_cmd(src_exe: &str, _exe: &str, _path: &str) -> String { +pub fn copy_exe_cmd(src_exe: &str, _exe: &str, path: &str) -> String { #[cfg(feature = "flutter")] - return format!( + let main_exe = format!( "XCOPY \"{}\" \"{}\" /Y /E /H /C /I /K /R /Z", PathBuf::from(src_exe) .parent() .unwrap() .to_string_lossy() .to_string(), - _path + path ); #[cfg(not(feature = "flutter"))] - return format!( + let main_exe = format!( "copy /Y \"{src_exe}\" \"{exe}\"", src_exe = src_exe, exe = _exe ); + + return format!( + " + {main_exe} + copy /Y \"{ORIGIN_PROCESS_EXE}\" \"{path}\\{broker_exe}\" + \"{src_exe}\" --extract \"{path}\" + ", + main_exe = main_exe, + path = path, + ORIGIN_PROCESS_EXE = crate::ui::win_privacy::ORIGIN_PROCESS_EXE, + broker_exe = crate::ui::win_privacy::INJECTED_PROCESS_EXE, + ); } pub fn update_me() -> ResultType<()> { @@ -905,18 +920,16 @@ pub fn update_me() -> ResultType<()> { chcp 65001 sc stop {app_name} taskkill /F /IM {broker_exe} - taskkill /F /IM {app_name}.exe + taskkill /F /IM {app_name}.exe /FI \"PID ne {cur_pid}\" {copy_exe} - \"{src_exe}\" --extract \"{path}\" sc start {app_name} {lic} ", - src_exe = src_exe, copy_exe = copy_exe_cmd(&src_exe, &exe, &path), broker_exe = crate::ui::win_privacy::INJECTED_PROCESS_EXE, - path = path, app_name = crate::get_app_name(), lic = register_licence(), + cur_pid = get_current_pid(), ); std::thread::sleep(std::time::Duration::from_millis(1000)); run_cmds(cmds, false, "update")?; @@ -1087,8 +1100,6 @@ if exist \"{tmp_path}\\{app_name} Tray.lnk\" del /f /q \"{tmp_path}\\{app_name} chcp 65001 md \"{path}\" {copy_exe} -copy /Y \"{ORIGIN_PROCESS_EXE}\" \"{path}\\{broker_exe}\" -\"{src_exe}\" --extract \"{path}\" reg add {subkey} /f reg add {subkey} /f /v DisplayIcon /t REG_SZ /d \"{exe}\" reg add {subkey} /f /v DisplayName /t REG_SZ /d \"{app_name}\" @@ -1119,10 +1130,7 @@ sc delete {app_name} ", uninstall_str=uninstall_str, path=path, - src_exe=src_exe, exe=exe, - ORIGIN_PROCESS_EXE = crate::ui::win_privacy::ORIGIN_PROCESS_EXE, - broker_exe=crate::ui::win_privacy::INJECTED_PROCESS_EXE, subkey=subkey, app_name=crate::get_app_name(), version=crate::VERSION, @@ -1178,13 +1186,14 @@ fn get_before_uninstall() -> String { sc stop {app_name} sc delete {app_name} taskkill /F /IM {broker_exe} - taskkill /F /IM {app_name}.exe + taskkill /F /IM {app_name}.exe /FI \"PID ne {cur_pid}\" reg delete HKEY_CLASSES_ROOT\\.{ext} /f netsh advfirewall firewall delete rule name=\"{app_name} Service\" ", app_name = app_name, broker_exe = crate::ui::win_privacy::INJECTED_PROCESS_EXE, - ext = ext + ext = ext, + cur_pid = get_current_pid(), ) } @@ -1613,3 +1622,7 @@ pub fn is_foreground_window_elevated() -> ResultType { is_elevated(Some(process_id)) } } + +fn get_current_pid() -> u32 { + unsafe { GetCurrentProcessId() } +} diff --git a/src/ui/index.tis b/src/ui/index.tis index 45e88109..31781c35 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -1242,9 +1242,3 @@ function refreshCurrentUser() { function getHttpHeaders() { return "Authorization: Bearer " + handler.get_local_option("access_token"); } - -$(body).timer(1000, function check_elevation(){ - if (is_win && handler.is_release() && !handler.is_installed() && !handler.is_root()) { - msgbox("custom-elevation-nocancel", "Prompt", "elevation_prompt"); - } -}); \ No newline at end of file