fix windows install hang, avoid kill self

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-10-30 18:45:44 +08:00
parent 6756b67492
commit ba4bc3a645
2 changed files with 14 additions and 4 deletions

View File

@ -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();
}

View File

@ -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::*,
@ -905,7 +908,7 @@ 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}
@ -917,6 +920,7 @@ pub fn update_me() -> ResultType<()> {
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")?;
@ -1178,13 +1182,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 +1618,7 @@ pub fn is_foreground_window_elevated() -> ResultType<bool> {
is_elevated(Some(process_id))
}
}
fn get_current_pid() -> u32 {
unsafe { GetCurrentProcessId() }
}