open as admin (windows only)

This commit is contained in:
SpikeHD
2022-09-04 18:05:19 -07:00
parent fb231acaa6
commit 7cf1b198ff
2 changed files with 28 additions and 0 deletions

23
src-tauri/src/admin.rs Normal file
View File

@@ -0,0 +1,23 @@
use std::process::exit;
use std::process::Command;
#[cfg(windows)]
pub fn reopen_as_admin() {
let install = std::env::current_exe().unwrap();
println!("Opening as admin: {}", install.to_str().unwrap());
Command::new("powershell.exe")
.arg("powershell")
.arg(format!(
"-command \"&{{Start-Process -filepath 'cmd' -argumentlist '/c \"{}\"' -verb runas}}\"",
install.to_str().unwrap()
))
.spawn()
.expect("Error starting exec as admin");
exit(0);
}
#[cfg(linux)]
pub fn reopen_as_admin() {}

View File

@@ -16,6 +16,9 @@ use std::thread;
use structs::APIQuery;
use sysinfo::{System, SystemExt};
use crate::admin::reopen_as_admin;
mod admin;
mod downloader;
mod file_helpers;
mod gamebanana;
@@ -52,6 +55,8 @@ fn main() {
println!("===============================================================================");
println!("You running as a non-elevated user. Some stuff will almost definitely not work.");
println!("===============================================================================");
reopen_as_admin();
}
// Setup datadir/cultivation just in case something went funky and it wasn't made