procedure EnableDebugPriv;
var
hToken: THandle;
sedebugnameValue: Int64;
tkp: TTokenPrivileges;
ReturnLength: Cardinal;
begin
// enable the SeDebugPrivilege
if (not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)) then
raise
Exception.CreateFmt('OpenProcessToken() failed, Error = %d SeDebugPrivilege is not available.', [GetLastError]);
try
if (not LookupPrivilegeValue(nil, SE_DEBUG_NAME, sedebugnameValue)) then
raise
Exception.CreateFmt('LookupPrivilegeValue() failed, Error = %d SeDebugPrivilege is not available.', [GetLastError]);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Luid := sedebugnameValue;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
ReturnLength := 0;
if (not AdjustTokenPrivileges(hToken, False, tkp, SizeOf(tkp), nil, ReturnLength)) then
raise
Exception.CreateFmt('AdjustTokenPrivileges() failed, Error = %d SeDebugPrivilege is not available.', [GetLastError]);
finally
CloseHandle(hToken);
end;
end;