diff --git a/src/core_main.rs b/src/core_main.rs index 771ee4ca8..9ce45a23b 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -269,6 +269,28 @@ pub fn core_main() -> Option> { crate::virtual_display_manager::amyuni_idd::uninstall_driver() ); return None; + } else if args[0] == "--install-remote-printer" { + #[cfg(windows)] + if crate::platform::is_win_10_or_greater() { + match remote_printer::install_update_printer(&crate::get_app_name()) { + Ok(_) => { + log::info!("Remote printer installed/updated successfully"); + } + Err(e) => { + log::error!("Failed to install/update the remote printer: {}", e); + } + } + } else { + log::error!("Win10 or greater required!"); + } + return None; + } else if args[0] == "--uninstall-remote-printer" { + #[cfg(windows)] + if crate::platform::is_win_10_or_greater() { + remote_printer::uninstall_printer(&crate::get_app_name()); + log::info!("Remote printer uninstalled"); + } + return None; } } #[cfg(target_os = "macos")] diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 7ec5b5a15..c55953cac 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1390,6 +1390,16 @@ copy /Y \"{tmp_path}\\{app_name} Tray.lnk\" \"%PROGRAMDATA%\\Microsoft\\Windows\ ") }; + let install_remote_printer = if install_printer { + // No need to use `|| true` here. + // The script will not exit even if `--install-remote-printer` panics. + format!("\"{}\" --install-remote-printer", &src_exe) + } else if crate::platform::is_win_10_or_greater() { + format!("\"{}\" --uninstall-remote-printer", &src_exe) + } else { + "".to_owned() + }; + // Remember to check if `update_me` need to be changed if changing the `cmds`. // No need to merge the existing dup code, because the code in these two functions are too critical. // New code should be written in a common function. @@ -1418,6 +1428,7 @@ cscript \"{uninstall_shortcut}\" {tray_shortcuts} {shortcuts} copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\" +{install_remote_printer} {dels} {import_config} {after_install} @@ -1437,11 +1448,6 @@ copy /Y \"{tmp_path}\\Uninstall {app_name}.lnk\" \"{path}\\\" import_config = get_import_config(&exe), ); run_cmds(cmds, debug, "install")?; - if install_printer { - allow_err!(remote_printer::install_update_printer( - &crate::get_app_name() - )); - } run_after_run_cmds(silent); Ok(()) }