Files
clash-verge-rev/src-tauri/src/core/win_uwp.rs
T

26 lines
707 B
Rust
Raw Normal View History

2023-11-22 00:15:41 -08:00
#![cfg(target_os = "windows")]
use crate::utils::dirs;
use anyhow::{bail, Result};
use deelevate::{PrivilegeLevel, Token};
use runas::Command as RunasCommand;
use std::process::Command as StdCommand;
pub async fn invoke_uwptools() -> Result<()> {
2023-12-14 12:50:45 +08:00
let resource_dir = dirs::app_resources_dir()?;
let tool_path = resource_dir.join("enableLoopback.exe");
2023-11-22 00:15:41 -08:00
if !tool_path.exists() {
bail!("enableLoopback exe not found");
}
let token = Token::with_current_process()?;
let level = token.privilege_level()?;
2023-12-14 12:50:45 +08:00
match level {
2023-11-22 00:15:41 -08:00
PrivilegeLevel::NotPrivileged => RunasCommand::new(tool_path).status()?,
2023-12-14 12:50:45 +08:00
_ => StdCommand::new(tool_path).status()?,
2023-11-22 00:15:41 -08:00
};
Ok(())
}