From dfc60d8645d6e92b742dd6632f25f0e7d2cd2fad Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sat, 27 Dec 2025 15:11:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E6=AD=A3=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E6=A8=A1=E5=BC=8F=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=94=B9=E4=B8=BA=E6=A3=80=E6=B5=8B=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/commands.rs | 43 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index c61c7314..819a439b 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,5 +1,5 @@ -//! 命令模块,负责处理命令 -//! @since Beta v0.8.8 +// 命令模块,负责处理命令 +// @since Beta v0.9.1 use tauri::{AppHandle, Emitter, Manager, WebviewWindowBuilder}; use tauri_utils::config::{WebviewUrl, WindowConfig}; @@ -81,11 +81,7 @@ pub fn is_in_admin() -> bool { { use windows_sys::Win32::Foundation::{CloseHandle, HANDLE}; use windows_sys::Win32::Security::{ - AllocateAndInitializeSid, CheckTokenMembership, FreeSid, SID_IDENTIFIER_AUTHORITY, - TOKEN_QUERY, - }; - use windows_sys::Win32::System::SystemServices::{ - DOMAIN_ALIAS_RID_ADMINS, SECURITY_BUILTIN_DOMAIN_RID, + GetTokenInformation, TokenElevation, TOKEN_ELEVATION, TOKEN_QUERY, }; use windows_sys::Win32::System::Threading::{GetCurrentProcess, OpenProcessToken}; @@ -95,35 +91,20 @@ pub fn is_in_admin() -> bool { return false; } - let nt_authority = SID_IDENTIFIER_AUTHORITY { Value: [0, 0, 0, 0, 0, 5] }; - let mut admin_group = std::ptr::null_mut(); + let mut elevation = TOKEN_ELEVATION { TokenIsElevated: 0 }; + let mut return_length = 0; - let success = AllocateAndInitializeSid( - &nt_authority, - 2, - SECURITY_BUILTIN_DOMAIN_RID.try_into().unwrap(), - DOMAIN_ALIAS_RID_ADMINS.try_into().unwrap(), - 0, - 0, - 0, - 0, - 0, - 0, - &mut admin_group, + let result = GetTokenInformation( + token_handle, + TokenElevation, + &mut elevation as *mut _ as *mut _, + std::mem::size_of::() as u32, + &mut return_length, ); - if success == 0 { - CloseHandle(token_handle); - return false; - } - - let mut is_admin = 0i32; - let result = CheckTokenMembership(std::ptr::null_mut(), admin_group, &mut is_admin); - - FreeSid(admin_group); CloseHandle(token_handle); - result != 0 && is_admin != 0 + result != 0 && elevation.TokenIsElevated != 0 } } }