#include-once #include Func _DebugPrivilege($fEnable = Default) $fEnable = ($fEnable = Default) ? True : $fEnable Local $fRet = ($fEnable) ? _EnableDebugPrivilege() : _DisableDebugPrivilege() Return SetError(@error, @extended, $fRet) EndFunc ;==>_DebugPrivilege Func _DisableDebugPrivilege($hCurrentProc = Default) $hCurrentProc = ((IsKeyword($hCurrentProc) Or $hCurrentProc < 1) _ ? _WinAPI_GetCurrentProcess() : $hCurrentProc) Local $hToken = _Security__OpenProcessToken($hCurrentProc, _ BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY)) If Not $hToken Then Return SetError(2, 0, 0) EndIf Local $nSDN = _Security__LookupPrivilegeValue("", $SE_DEBUG_NAME) Local $tTokenPriv = DllStructCreate("dword;dword;long;dword") Local $pTokenPriv = DllStructGetPtr($tTokenPriv) DllStructSetData($tTokenPriv, 1, 1) DllStructSetData($tTokenPriv, 2, $nSDN) DllStructSetData($tTokenPriv, 3, 0) DllStructSetData($tTokenPriv, 4, $SE_PRIVILEGE_ENABLED) Local $nTokenSize = DllStructGetSize($tTokenPriv) Local $bRet = _Security__AdjustTokenPrivileges($hToken, True, _ $pTokenPriv, $nTokenSize) _WinAPI_CloseHandle($hToken) Return SetError(Not $bRet, 0, $bRet) EndFunc ;==>_DisableDebugPrivilege Func _EnableDebugPrivilege($hCurrentProc = Default) $hCurrentProc = ((IsKeyword($hCurrentProc) Or $hCurrentProc < 1) _ ? _WinAPI_GetCurrentProcess() : $hCurrentProc) Local $hToken = _Security__OpenProcessToken($hCurrentProc, _ BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY)) If Not $hToken Then Return SetError(2, 0, 0) EndIf Local $nSDN = _Security__LookupPrivilegeValue("", $SE_DEBUG_NAME) Local $tTokenPriv = DllStructCreate("dword;dword;long;dword") Local $pTokenPriv = DllStructGetPtr($tTokenPriv) DllStructSetData($tTokenPriv, 1, 1) DllStructSetData($tTokenPriv, 2, $nSDN) DllStructSetData($tTokenPriv, 3, 0) DllStructSetData($tTokenPriv, 4, $SE_PRIVILEGE_ENABLED) Local $nTokenSize = DllStructGetSize($tTokenPriv) Local $bRet = _Security__AdjustTokenPrivileges($hToken, False, _ $pTokenPriv, $nTokenSize) _WinAPI_CloseHandle($hToken) Return SetError(Not $bRet, 0, $bRet) EndFunc ;==>_EnableDebugPrivilege