Skip to content

Commit

Permalink
fix: πŸ› Fix "is_administrator" function
Browse files Browse the repository at this point in the history
  • Loading branch information
AntwortEinesLebens committed Oct 20, 2024
1 parent 6dee87d commit 04d9bf1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/windows/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use windows::{
core::{Owned, Result as WindowsResult},
Win32::{
Foundation::BOOL,
Security::{AllocateAndInitializeSid, CheckTokenMembership, PSID, SECURITY_NT_AUTHORITY},
System::SystemServices::{DOMAIN_ALIAS_RID_ADMINS, SECURITY_BUILTIN_DOMAIN_RID},
},
};

pub fn is_administrator() -> WindowsResult<bool> {
let mut is_admin: bool = false;
let mut is_admin: BOOL = false.into();

unsafe {
let mut administrators_group: Owned<PSID> = Owned::new(PSID::default());
Expand All @@ -30,12 +31,8 @@ pub fn is_administrator() -> WindowsResult<bool> {
&mut *administrators_group,
)?;

CheckTokenMembership(
None,
*administrators_group,
&mut is_admin as *mut _ as *mut _,
)?;
CheckTokenMembership(None, *administrators_group, &mut is_admin as *mut _)?;
}

Ok(is_admin)
Ok(is_admin.as_bool())
}

0 comments on commit 04d9bf1

Please sign in to comment.