Skip to main content

TokenCommand

Struct TokenCommand 

Source
pub struct TokenCommand { /* private fields */ }
Expand description

Builder for launching processes under a specified primary security token.

Implementations§

Source§

impl TokenCommand

Source

pub fn new(token: Token, desktop: Option<InteractiveDesktop>) -> Self

Create a new command builder bound to an elevated token and its target desktop context.

Source

pub fn current_exe(self) -> Result<Self, ElevateError>

Set the target executable to the path of the current binary.

Source

pub fn exe(self, path: impl AsRef<Path>) -> Self

Set a custom target executable path. Supports environment variables like %SystemRoot%.

Examples found in repository?
examples/headless_cmd.rs (line 14)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Spawning headless background maintenance command...");
10
11    // `headless_command()` automatically binds to a Session 0 TrustedInstaller token
12    // with no desktop station attached, preventing any Session 0 DACL or access violations.
13    headless_command()?
14        .exe("%SystemRoot%\\System32\\cmd.exe")
15        .args("cmd.exe /k whoami /groups")
16        .spawn()?;
17
18    println!("Headless process spawned successfully in Session 0.");
19    Ok(())
20}
More examples
Hide additional examples
examples/spawn_cmd.rs (line 13)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Spawning an elevated Command Prompt...");
10
11    // Standard interactive desktop:
12    elevated_command()?
13        .exe("%SystemRoot%\\System32\\cmd.exe")
14        .args("cmd.exe /k whoami /groups")
15        .spawn()?;
16
17    // Tip: To target specific desktops (like the lock screen or a custom sandbox),
18    // you can use `elevated_command_on`:
19    //
20    // elevated_command_on(InteractiveDesktop::Winlogon)?.exe(...).spawn()?;
21    // elevated_command_on(InteractiveDesktop::custom("MyStation\\MyDesktop"))?.exe(...).spawn()?;
22
23    println!("Elevated Command Prompt spawned successfully.");
24    Ok(())
25}
Source

pub fn args(self, args: impl Into<String>) -> Self

Pass a raw command-line string to the process.

Examples found in repository?
examples/headless_cmd.rs (line 15)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Spawning headless background maintenance command...");
10
11    // `headless_command()` automatically binds to a Session 0 TrustedInstaller token
12    // with no desktop station attached, preventing any Session 0 DACL or access violations.
13    headless_command()?
14        .exe("%SystemRoot%\\System32\\cmd.exe")
15        .args("cmd.exe /k whoami /groups")
16        .spawn()?;
17
18    println!("Headless process spawned successfully in Session 0.");
19    Ok(())
20}
More examples
Hide additional examples
examples/spawn_cmd.rs (line 14)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Spawning an elevated Command Prompt...");
10
11    // Standard interactive desktop:
12    elevated_command()?
13        .exe("%SystemRoot%\\System32\\cmd.exe")
14        .args("cmd.exe /k whoami /groups")
15        .spawn()?;
16
17    // Tip: To target specific desktops (like the lock screen or a custom sandbox),
18    // you can use `elevated_command_on`:
19    //
20    // elevated_command_on(InteractiveDesktop::Winlogon)?.exe(...).spawn()?;
21    // elevated_command_on(InteractiveDesktop::custom("MyStation\\MyDesktop"))?.exe(...).spawn()?;
22
23    println!("Elevated Command Prompt spawned successfully.");
24    Ok(())
25}
Source

pub fn spawn(self) -> Result<(), ElevateError>

Spawn the process under the configured token context.

Examples found in repository?
examples/headless_cmd.rs (line 16)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Spawning headless background maintenance command...");
10
11    // `headless_command()` automatically binds to a Session 0 TrustedInstaller token
12    // with no desktop station attached, preventing any Session 0 DACL or access violations.
13    headless_command()?
14        .exe("%SystemRoot%\\System32\\cmd.exe")
15        .args("cmd.exe /k whoami /groups")
16        .spawn()?;
17
18    println!("Headless process spawned successfully in Session 0.");
19    Ok(())
20}
More examples
Hide additional examples
examples/spawn_cmd.rs (line 15)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    println!("Spawning an elevated Command Prompt...");
10
11    // Standard interactive desktop:
12    elevated_command()?
13        .exe("%SystemRoot%\\System32\\cmd.exe")
14        .args("cmd.exe /k whoami /groups")
15        .spawn()?;
16
17    // Tip: To target specific desktops (like the lock screen or a custom sandbox),
18    // you can use `elevated_command_on`:
19    //
20    // elevated_command_on(InteractiveDesktop::Winlogon)?.exe(...).spawn()?;
21    // elevated_command_on(InteractiveDesktop::custom("MyStation\\MyDesktop"))?.exe(...).spawn()?;
22
23    println!("Elevated Command Prompt spawned successfully.");
24    Ok(())
25}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.