[wip] use windows crate to run as admin
This commit is contained in:
@ -34,3 +34,6 @@ tauri-plugin-shell = { workspace = true }
|
||||
tauri-plugin-dialog = { workspace = true }
|
||||
tauri-plugin-store = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows = { workspace = true }
|
||||
|
@ -1,3 +1,5 @@
|
||||
#[cfg(target_os = "windows")]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fs::File,
|
||||
@ -54,12 +56,31 @@ fn install_game(id: String, state: tauri::State<LanSpreadState>) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn run_as_admin(file: &str, params: &str, dir: &str) -> bool {
|
||||
todo!();
|
||||
let file_wide: Vec<u16> = OsStr::new(file).encode_wide().chain(Some(0)).collect();
|
||||
let params_wide: Vec<u16> = OsStr::new(params).encode_wide().chain(Some(0)).collect();
|
||||
let dir_wide: Vec<u16> = OsStr::new(dir).encode_wide().chain(Some(0)).collect();
|
||||
|
||||
let result = unsafe {
|
||||
ShellExecuteW(
|
||||
HWND(0),
|
||||
Some("runas"),
|
||||
&file_wide,
|
||||
Some(¶ms_wide),
|
||||
Some(&dir_wide),
|
||||
windows::Win32::UI::WindowsAndMessaging::SW_SHOWNORMAL,
|
||||
)
|
||||
};
|
||||
|
||||
result.0 > 32 // Success if greater than 32
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn run_game(id: String, state: tauri::State<LanSpreadState>) {
|
||||
const FIRST_START_DONE_FILE: &str = ".softlan_first_start_done";
|
||||
|
||||
log::error!("run_game {id}");
|
||||
|
||||
let games_folder =
|
||||
tauri::async_runtime::block_on(async { state.inner().games_folder.lock().await.clone() });
|
||||
|
||||
|
Reference in New Issue
Block a user