win_uwp.rs 707 B

1234567891011121314151617181920212223242526
  1. #![cfg(target_os = "windows")]
  2. use crate::utils::dirs;
  3. use anyhow::{bail, Result};
  4. use deelevate::{PrivilegeLevel, Token};
  5. use runas::Command as RunasCommand;
  6. use std::process::Command as StdCommand;
  7. pub async fn invoke_uwptools() -> Result<()> {
  8. let resource_dir = dirs::app_resources_dir()?;
  9. let tool_path = resource_dir.join("enableLoopback.exe");
  10. if !tool_path.exists() {
  11. bail!("enableLoopback exe not found");
  12. }
  13. let token = Token::with_current_process()?;
  14. let level = token.privilege_level()?;
  15. match level {
  16. PrivilegeLevel::NotPrivileged => RunasCommand::new(tool_path).status()?,
  17. _ => StdCommand::new(tool_path).status()?,
  18. };
  19. Ok(())
  20. }