× Discussions for CodeTyphon Object Pascal Programming Language

Question SeDebugPrivilege

More
2 weeks 6 days ago #16102 by Luca
SeDebugPrivilege was created by Luca
Hello,

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.

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;

I tried most of code I found on Google but noone worked, Any idea what to change?

Please Log in or Create an account to join the conversation.

More
2 weeks 6 days ago #16103 by Matis A.
Replied by Matis A. on topic SeDebugPrivilege
Your target OS ?

Did you try with a Project with "Administrator Execution Level" like CTCenter ?

 

PilotLogic Core Programmer
Attachments:

Please Log in or Create an account to join the conversation.

More
2 weeks 6 days ago #16104 by Luca
Replied by Luca on topic SeDebugPrivilege
Thank you for fast reply, but thats not it. I can't even compile the project

File Attachment:

 

Please Log in or Create an account to join the conversation.

More
2 weeks 6 days ago #16105 by Matis A.
Replied by Matis A. on topic SeDebugPrivilege
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.

More
2 weeks 6 days ago #16106 by Luca
Replied by Luca on topic SeDebugPrivilege

Please Log in or Create an account to join the conversation.

More
2 weeks 6 days ago #16107 by Matis A.
Replied by Matis A. on topic SeDebugPrivilege
uses
 windows

PilotLogic Core Programmer

Please Log in or Create an account to join the conversation.

More
2 weeks 6 days ago - 2 weeks 6 days ago #16108 by Luca
Replied by Luca on topic SeDebugPrivilege
Done

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;

Last edit: 2 weeks 6 days ago by Luca.

Please Log in or Create an account to join the conversation.