Skip to main content

Crate token_privilege

Crate token_privilege 

Source
Expand description

Safe Rust wrapper for Windows process token privilege and elevation detection.

All unsafe Win32 FFI calls are contained within the crate. Consumers use a fully safe public API and can maintain #![forbid(unsafe_code)] in their own crates.

On non-Windows platforms, all functions return Err(TokenPrivilegeError::UnsupportedPlatform).

§Examples

use token_privilege::{is_elevated, is_privilege_enabled, privileges};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    if is_elevated()? {
        println!("Running as Administrator");
    }

    if is_privilege_enabled(privileges::SE_DEBUG)? {
        println!("SeDebugPrivilege is enabled");
    }

    Ok(())
}

Modules§

privileges
Well-known Windows privilege name constants.

Structs§

PrivilegeInfo
Represents the status of a single Windows privilege.

Enums§

TokenPrivilegeError
Errors that can occur when querying token privileges.

Functions§

enumerate_privileges
Enumerate all privileges on the current process token.
has_privilege
Check if a specific named privilege is present on the current process token, regardless of whether it is currently enabled.
is_elevated
Check if the current process is running with elevated (Administrator) privileges.
is_privilege_enabled
Check if a specific named privilege is present and enabled on the current process token.