Created
January 11, 2017 07:42
-
-
Save tmplinshi/524e5aefb28bb22bf6c1dae9154609db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; =============================================================================================================================== | |
; Check if a process is elevated | |
; =============================================================================================================================== | |
IsProcessElevated(ProcessID) | |
{ | |
if !(hProcess := DllCall("OpenProcess", "uint", 0x0400, "int", 0, "uint", ProcessID, "ptr")) | |
throw Exception("OpenProcess failed", -1) | |
if !(DllCall("advapi32\OpenProcessToken", "ptr", hProcess, "uint", 0x0008, "ptr*", hToken)) | |
throw Exception("OpenProcessToken failed", -1), DllCall("CloseHandle", "ptr", hProcess) | |
if !(DllCall("advapi32\GetTokenInformation", "ptr", hToken, "int", 20, "uint*", IsElevated, "uint", 4, "uint*", size)) | |
throw Exception("GetTokenInformation failed", -1), DllCall("CloseHandle", "ptr", hToken) && DllCall("CloseHandle", "ptr", hProcess) | |
return IsElevated, DllCall("CloseHandle", "ptr", hToken) && DllCall("CloseHandle", "ptr", hProcess) | |
} | |
; =============================================================================================================================== | |
MsgBox % IsProcessElevated(DllCall("GetCurrentProcessId")) | |
; 0 => Process is not elevated | |
; 1 => Process is elevated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment