Crates.io | sysctrlcmd |
lib.rs | sysctrlcmd |
version | 1.0.2 |
source | src |
created_at | 2023-12-09 21:59:03.554566 |
updated_at | 2023-12-09 22:02:32.990842 |
description | System Commands for Linux, Windows, and MacOS (logoff, shutdown, reboot, etc.) |
homepage | |
repository | https://github.com/SourM1lk/sysctrlcmd |
max_upload_size | |
id | 1063910 |
size | 12,613 |
sysctrlcmd is a Rust crate providing a unified and cross-platform interface for executing system-level commands like locking the workstation, logging off the current user, hibernating, suspending, restarting, and shutting down the system. It's designed to simplify the integration of system command functionalities in Rust applications, offering a consistent API across different operating systems.
The table below outlines the support for various system commands across Windows, Linux, and MacOS:
Command | Windows | Linux | MacOS |
---|---|---|---|
Lock | ✔ | ❌ | ❌ |
Logoff | ✔ | ❌ | ❌ |
Hibernate | ✔ | ✔ | ❌ |
Suspend | ✔ | ✔ | ❌ |
Restart | ✔ | ✔ | ❌ |
Shutdown | ✔ | ✔ | ❌ |
use sysctrlcmd::SystemCommandsImpl;
fn main() {
SystemCommandsImpl::lock().expect("Failed to lock the system screen");
SystemCommandsImpl::logoff().expect("Failed to log off");
SystemCommandsImpl::hibernate().expect("Failed to hibernate");
SystemCommandsImpl::suspend().expect("Failed to suspend");
SystemCommandsImpl::restart().expect("Failed to restart");
SystemCommandsImpl::shutdown().expect("Failed to shut down");
}
Add the following to your Cargo.toml
file:
[dependencies]
sysctrlcmd = "*"