spawn_cmd/spawn_cmd.rs
1//! Example demonstrating spawning a custom process (e.g. cmd.exe)
2//! directly with elevated `TrustedInstaller` privileges in the user's interactive desktop.
3
4use elevate_ti::elevated_command;
5// Advanced usage:
6// use elevate_ti::{elevated_command_on, InteractiveDesktop};
7
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}