pub struct TokenCommand { /* private fields */ }Expand description
Builder for launching processes under a specified primary security token.
Implementations§
Source§impl TokenCommand
impl TokenCommand
Sourcepub fn new(token: Token, desktop: Option<InteractiveDesktop>) -> Self
pub fn new(token: Token, desktop: Option<InteractiveDesktop>) -> Self
Create a new command builder bound to an elevated token and its target desktop context.
Sourcepub fn current_exe(self) -> Result<Self, ElevateError>
pub fn current_exe(self) -> Result<Self, ElevateError>
Set the target executable to the path of the current binary.
Sourcepub fn exe(self, path: impl AsRef<Path>) -> Self
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
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}Sourcepub fn args(self, args: impl Into<String>) -> Self
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
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}Sourcepub fn spawn(self) -> Result<(), ElevateError>
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
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§
impl !Send for TokenCommand
impl !Sync for TokenCommand
impl Freeze for TokenCommand
impl RefUnwindSafe for TokenCommand
impl Unpin for TokenCommand
impl UnsafeUnpin for TokenCommand
impl UnwindSafe for TokenCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more