Skip to content

Repository files navigation

restart-manager

CI CodeQL

Safe, human-friendly Restart Manager workflows for Rust applications that need to find, stop, and restart the Windows processes locking their files.

Installation

cargo add restart-manager

The default API is blocking. Enable the optional Tokio API when needed:

cargo add restart-manager --features tokio

Example

Inspect the applications affected by replacing a file:

use restart_manager::RestartSession;

fn main() -> Result<(), restart_manager::Error> {
    let mut session = RestartSession::new()?;
    session.register_files([r"C:\product\component.dll"])?;

    let applications = session.affected_applications()?;
    eprintln!("reboot reasons: {:?}", applications.reboot_reasons());
    for application in &applications {
        eprintln!(
            "{} (restartable: {})",
            application.display_name().to_string_lossy(),
            application.is_restartable(),
        );
    }

    session.end()
}

Important behavior

  • Native operations are Windows-only. Public types remain available on other targets, where OS operations return ErrorKind::UnsupportedPlatform.
  • Shutdown produces an owned RestartPending recovery value. It must be restarted or explicitly completed with leave_stopped; dropping it makes one best-effort restart attempt before ending the session.
  • Forced shutdown is opt-in and can cause applications to lose data.
  • Restart Manager can relaunch only services and applications that registered themselves for restart.
  • Tokio shutdown/restart futures use tokio::AsyncOperationError<T>. Its state() is Some only when a callback-lease conflict proves that native work never began; worker failures return None rather than a misleading retryable typestate.

More information

License

Licensed under either MIT or Apache-2.0, at your option.

About

Safe Rust workflows for the Windows Restart Manager API

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages