From a3c3caf774d740ea3b68781d23e8d0e589befab7 Mon Sep 17 00:00:00 2001 From: Cherry <13651622+MolotovCherry@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:38:58 -0700 Subject: [PATCH] Use GetCurrentProcess instead of OpenProcess --- pueue/src/daemon/service.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pueue/src/daemon/service.rs b/pueue/src/daemon/service.rs index 86cbcccd..0ae38d04 100644 --- a/pueue/src/daemon/service.rs +++ b/pueue/src/daemon/service.rs @@ -35,7 +35,7 @@ use std::{ ffi::{c_void, OsString}, iter, path::PathBuf, - process, ptr, + ptr, sync::{ atomic::{AtomicBool, Ordering}, mpsc::{channel, Receiver, Sender}, @@ -61,10 +61,9 @@ use windows::{ RemoteDesktop::{WTSGetActiveConsoleSessionId, WTSQueryUserToken}, SystemServices::MAXIMUM_ALLOWED, Threading::{ - CreateProcessAsUserW, GetExitCodeProcess, OpenProcess, OpenProcessToken, + CreateProcessAsUserW, GetCurrentProcess, GetExitCodeProcess, OpenProcessToken, TerminateProcess, WaitForSingleObject, CREATE_NO_WINDOW, - CREATE_UNICODE_ENVIRONMENT, INFINITE, PROCESS_INFORMATION, - PROCESS_QUERY_INFORMATION, STARTUPINFOW, + CREATE_UNICODE_ENVIRONMENT, INFINITE, PROCESS_INFORMATION, STARTUPINFOW, }, }, }, @@ -373,12 +372,11 @@ fn event_loop() -> Result<()> { /// Set the specified process privilege to state. /// https://learn.microsoft.com/en-us/windows/win32/secauthz/privilege-constants fn set_privilege(name: PCWSTR, state: bool) -> Result<()> { - let handle: OwnedHandle = - unsafe { OpenProcess(PROCESS_QUERY_INFORMATION, false, process::id())?.into() }; + let process: OwnedHandle = unsafe { GetCurrentProcess().into() }; let mut token: OwnedHandle = OwnedHandle::default(); unsafe { - OpenProcessToken(handle.0, TOKEN_ADJUST_PRIVILEGES, &mut token.0)?; + OpenProcessToken(process.0, TOKEN_ADJUST_PRIVILEGES, &mut token.0)?; } let mut luid = LUID::default();