mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
open as admin (windows only)
This commit is contained in:
23
src-tauri/src/admin.rs
Normal file
23
src-tauri/src/admin.rs
Normal 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() {}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user