Documentation
1
2
3
4
5
6
7
use crate::share::exec;

pub fn is_admin() -> bool {
    let shell = "[bool]([System.Security.Principal.WindowsPrincipal][System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)";
    let output = exec(shell).expect("Failed to execute powershell command");
    String::from_utf8(output.stdout).unwrap_or_default().trim() == "True"
}