Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Uninstall gives the Windows shell back to Explorer (1086)

gelenmedya449af7786182
diff --git a/crates/rf-app/src/installer.rs b/crates/rf-app/src/installer.rs
index 9c0d461b..c0837a5f 100644
--- a/crates/rf-app/src/installer.rs
+++ b/crates/rf-app/src/installer.rs
@@ -82,6 +82,11 @@ fn before_uninstall() {
let _ = rf_win::default_fm::disable(classes);
}
let _ = rf_win::dialog_reg::disable(rf_win::dialog_reg::CLASSES);
+ // "rustyfiles as the Windows shell": the next sign-in starts Explorer again, and so does this session when we were its shell
+ // (issue 1086: the value stayed and named a file the uninstall had deleted)
+ if rf_win::shell_switch::undo_for_uninstall() {
+ log::info!("uninstall: the Windows shell was given back to Explorer");
+ }
let none = Path::new("");
let _ = rf_win::dialogs::set_start_with_windows_as("DirectLook", none, &[], false);
let _ = rf_win::dialogs::set_start_with_windows(none, false);
diff --git a/crates/rf-win/src/shell_switch.rs b/crates/rf-win/src/shell_switch.rs
index 8dcfaa15..0cce31f6 100644
--- a/crates/rf-win/src/shell_switch.rs
+++ b/crates/rf-win/src/shell_switch.rs
@@ -54,10 +54,77 @@ pub fn set(guard: &Path, on: bool) -> windows::core::Result<()> {
}
}
+/// Whether a `Shell` value (as read) is one of ours: it names the guard, wherever that copy was installed. Pure.
+pub fn is_ours(value: &str) -> bool {
+ value.to_ascii_lowercase().contains(&GUARD_FILE.to_ascii_lowercase())
+}
+
+/// Whether Explorer is this session's shell right now: the shell's window is a visible window of an explorer.exe process.
+pub fn explorer_is_shell() -> bool {
+ use windows::Win32::Foundation::CloseHandle;
+ use windows::Win32::System::Threading::{OpenProcess, PROCESS_NAME_WIN32, PROCESS_QUERY_LIMITED_INFORMATION, QueryFullProcessImageNameW};
+ use windows::Win32::UI::WindowsAndMessaging::{GetShellWindow, GetWindowThreadProcessId, IsWindowVisible};
+ // SAFETY: plain queries; the process handle is closed here.
+ unsafe {
+ let hwnd = GetShellWindow();
+ if hwnd.0.is_null() || !IsWindowVisible(hwnd).as_bool() {
+ return false;
+ }
+ let mut pid = 0u32;
+ GetWindowThreadProcessId(hwnd, Some(&mut pid));
+ let Ok(process) = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, pid) else { return false };
+ let mut buf = [0u16; 1024];
+ let mut len = buf.len() as u32;
+ let named = QueryFullProcessImageNameW(process, PROCESS_NAME_WIN32, windows::core::PWSTR(buf.as_mut_ptr()), &mut len).is_ok();
+ let _ = CloseHandle(process);
+ named && Path::new(&String::from_utf16_lossy(&buf[..len as usize])).file_name().is_some_and(|n| n.eq_ignore_ascii_case("explorer.exe"))
+ }
+}
+
+/// At uninstall: Windows gets Explorer back. Returns whether the switch was on.
+///
+/// WHY (issue 1086: "Uninstall leaves HKCU\...\Winlogon\Shell pointing to deleted rustyfiles-shellguard.exe"). The uninstall took
+/// every other change in Windows back but not this one, so the next sign-in tried to start a file that was gone and the user had
+/// no desktop and no taskbar until the value was deleted by hand. The value goes first, which is what the next sign-in reads. And
+/// when rustyfiles is the shell of THIS session, Explorer is started so that the session is not left with no shell either: with
+/// the value gone and no shell running, a started explorer.exe becomes the shell. When Explorer is the shell already (the switch
+/// was only set for the next sign-in) nothing is started: a second explorer.exe would just open a folder window.
+/// NOT tried on a session whose shell is rustyfiles (the real shell is never switched on this PC).
+pub fn undo_for_uninstall() -> bool {
+ if !current().is_some_and(|v| is_ours(&v)) {
+ return false;
+ }
+ if let Err(e) = set(Path::new(""), false) {
+ log::warn!("uninstall: the Winlogon Shell value could not be removed: {e}");
+ }
+ if !explorer_is_shell() {
+ let root = std::env::var_os("SystemRoot").filter(|v| !v.is_empty()).map(PathBuf::from).unwrap_or_else(|| PathBuf::from(r"C:\Windows"));
+ if let Err(e) = std::process::Command::new(root.join("explorer.exe")).spawn() {
+ log::warn!("uninstall: Explorer could not be started: {e}");
+ }
+ }
+ true
+}
+
#[cfg(test)]
mod tests {
use super::*;
+ #[test]
+ fn a_shell_value_is_ours_when_it_names_the_guard_wherever_it_was_installed() {
+ assert!(is_ours(r#""C:\Users\Me\AppData\Local\rustyfiles\current\rustyfiles-shellguard.exe""#));
+ assert!(is_ours(r"D:\Apps\RUSTYFILES-SHELLGUARD.EXE"));
+ assert!(!is_ours("explorer.exe"));
+ assert!(!is_ours(r"C:\Program Files\OtherShell\shell.exe"));
+ }
+
+ /// (on a developer's or CI's ordinary session Explorer is the shell; where the tests run with no desktop there is no shell
+ /// window at all and the answer is no)
+ #[test]
+ fn the_shell_question_answers_without_failing() {
+ let _ = explorer_is_shell();
+ }
+
#[test]
fn the_value_is_the_guard_in_quotes_and_is_recognised_either_way() {
let g = Path::new(r"C:\Users\Me\AppData\Local\rustyfiles\current\rustyfiles-shellguard.exe");