| Crates.io | elevated-command |
| lib.rs | elevated-command |
| version | 1.1.2 |
| created_at | 2024-01-02 08:57:19.609781+00 |
| updated_at | 2024-01-04 14:35:25.819094+00 |
| description | Run a command using sudo, prompting the user with an OS dialog if necessary |
| homepage | https://github.com/vangork/elevated-command |
| repository | https://github.com/vangork/elevated-command |
| max_upload_size | |
| id | 1086044 |
| size | 35,484 |
Run command using sudo, prompting the user with a graphical OS dialog if necessary. Useful for background rust applications or native Tauri apps that need sudo.
elevated-command provides a native OS dialog prompt on Windows, Linux and MacOS.



Add the following to your Cargo.toml:
[dependencies]
elevated-command = "1.1"
In your main.rs:
use elevated_command::Command;
use std::process::Command as StdCommand;
fn main() {
let is_elevated = Command::is_elevated();
let mut cmd = StdCommand::new("path to the application");
cmd.arg("some arg");
let output = if is_elevated {
cmd.output().unwrap()
} else {
let elevated_cmd = Command::new(cmd);
elevated_cmd.output().unwrap()
};
}
Note: The application should not be sudo.
To get started using elevated-command, please see the API reference (docs.rs).
On Windows, elevated-command will elevate your command using User Account Control (UAC).
On Linux, elevated-command will use pkexec to show the password prompt and run your command.
On MacOS, elevated-command should behave just like the sudo command in the shell.
Licensed under the MIT license.