win-desktop-utils
Windows-first desktop utility helpers for Rust apps.
win-desktop-utils provides small, focused helpers for common Windows desktop-app tasks without forcing consumers to work directly with raw Win32 shell and mutex APIs.
Scope
This crate currently provides helpers to:
- open an existing file or directory with the default Windows handler
- open a URL with the default browser or registered handler
- reveal an existing path in Explorer
- move an existing file or directory to the Recycle Bin
- enforce single-instance behavior with a named mutex
- resolve per-user roaming and local app-data paths
- create per-user roaming and local app-data paths if needed
- check whether the current process is elevated
- relaunch the current executable as administrator
This crate supports Windows only.
Installation
[]
= "0.2"
Current API
open_with_default(path)open_url(url)reveal_in_explorer(path)move_to_recycle_bin(path)single_instance(app_id)roaming_app_data(app_name)local_app_data(app_name)ensure_roaming_app_data(app_name)ensure_local_app_data(app_name)is_elevated()restart_as_admin(args)
Example
Error behavior
The crate exposes a small public error type with explicit path-related cases.
Notable error distinctions include:
Error::InvalidInput(...)for empty or malformed inputError::PathNotAbsolutewhen an operation requires an absolute pathError::PathDoesNotExistwhen an operation requires an existing pathError::WindowsApi { .. }when a Win32 or shell operation reports failureError::Io(...)for underlying I/O failures
Behavior notes
open_with_defaultrequires a non-empty existing path.open_urlonly checks that the URL string is non-empty after trimming; deeper URL validation is delegated to the Windows shell.reveal_in_explorerrequires an existing path and launchesexplorer.exe.move_to_recycle_binrequires an absolute existing path and usesSHFileOperationWwith undo enabled.single_instanceuses aLocal\...named mutex, so the lock is scoped to the current Windows session.- Keep the returned
InstanceGuardalive for as long as the process should own the single-instance lock. restart_as_adminstarts a new elevated instance of the current executable and does not terminate the current process.
Quality
The crate includes:
- automated tests for validation and single-instance behavior
- doctest examples in the public modules
- Windows CI via GitHub Actions
- docs published on docs.rs
Status
Early-stage crate, but tested and usable.