- Posts: 4
- Thank you received: 0
Question SeDebugPrivilege
- Luca
- Topic Author
- Offline
- New Member
-
I can't seem to make this working, any help would be well appreciated. Here is one of many exmaples, I just want to enable SeDebugPrivilege to be able to terminate elevated apps.
I tried most of code I found on Google but noone worked, Any idea what to change?procedure ChangePrivilege;
var
privileges, oldprivileges: TOKEN_PRIVILEGES;
token: hwnd;
d: dword;
begin
if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES+TOKEN_QUERY, token) then begin
if not LookupPrivilegeValue(nil, 'SeDebugPrivilege', privileges.Privileges[0].Luid) then begin
m('err1');
exit;
end;
privileges.PrivilegeCount := 1;
privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
d := 0;
if not AdjustTokenPrivileges(token, false, privileges, 0, nil, @d) then begin
m('err3');
end;
end else m('err0');
end;
Please Log in or Create an account to join the conversation.
- Matis A.
-
- Away
- Moderator
-
PilotLogic Core Programmer
Attachments:
Please Log in or Create an account to join the conversation.
- Luca
- Topic Author
- Offline
- New Member
-
- Posts: 4
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- Matis A.
-
- Away
- Moderator
-
if not AdjustTokenPrivileges(token, false, privileges, 0, oldprivileges, d) then begin
m('err3');
end;
end else m('err0');
PilotLogic Core Programmer
Please Log in or Create an account to join the conversation.
- Luca
- Topic Author
- Offline
- New Member
-
- Posts: 4
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- Matis A.
-
- Away
- Moderator
-
Please Log in or Create an account to join the conversation.
- Luca
- Topic Author
- Offline
- New Member
-
- Posts: 4
- Thank you received: 0
uses Windows;
function sedebug_enable: boolean;
var
NewState: TTokenPrivileges;
luid: TLargeInteger;
hToken: THandle;
ReturnLength: DWord;
begin
if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, hToken) then begin
if LookupPrivilegeValue(nil, PChar('SeDebugPrivilege'), luid) then begin
NewState.PrivilegeCount:= 1;
NewState.Privileges[0].Luid := luid;
NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if AdjustTokenPrivileges(hToken, False, NewState, SizeOf(TTokenPrivileges), TTOKENPRIVILEGES(nil^), ReturnLength) then begin
result := true;
end;
end;
end;
end;
Please Log in or Create an account to join the conversation.