Expand description
Windows and Linux wrapper around elevated-command
that elevates commands using a graphical elevation dialog, executes them in the background using
tokio
and provides improved error feedback.
This crate is useful when writing apps using frameworks like Tauri
together with
libraries like interprocess
or interprocess_helpers
.
§Example
use std::process::Command;
use elevated_process::Process;
// Create a regular command. This can also include arguments.
let mut cmd = Command::new("myapp.exe");
cmd.arg("--help");
// Spawn the elevated process.
//
// If the current application does not have elevated
// priveleges, this will first spawn a dialog that prompts
// the user for the required permissions before spawning
// the actual command wih elevated permissions.
let process = Process::spawn(cmd);
// Waits for the underlying elevated_command::Command to exit.
//
// On Windows, if the current process is not already elevated,
// this finishes immediately after the user answeres the
// elevation prompt.
// On Linux, this will wait until the elevation prompt and
// the actual command have exited.
let result = process.wait().await;
// See crate::Error for more details.
//
// On both Windows and Linux this will display errors
// regarding process elevation.
// On Linux, this will also report an error if the
// elevated process returned an unsuccessful status code.
// On Windows, if the current process is not already elevated,
// this will not return any information about the actual
// process that was elevated.
println!("Result: {:#?}", result);
Structs§
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
- Process
- The elevated process.
Enums§
- Error
- Represents the various errors that can occur during the elevation and execution of a command.