Welcome, Guest
Username: Password: Remember me
Discussions for CodeTyphon Object Pascal Programming Language
  • Page:
  • 1

TOPIC:

SeDebugPrivilege 2 years 6 months ago #16102

  • Luca
  • Luca's Avatar Topic Author
  • Visitor
  • Visitor
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.

SeDebugPrivilege 2 years 6 months ago #16103

  • Matis A.
  • Matis A.'s Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 1047
  • Thank you received: 145
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.

SeDebugPrivilege 2 years 6 months ago #16104

  • Luca
  • Luca's Avatar Topic Author
  • Visitor
  • Visitor
Thank you for fast reply, but thats not it. I can't even compile the project


 

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

SeDebugPrivilege 2 years 6 months ago #16105

  • Matis A.
  • Matis A.'s Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 1047
  • Thank you received: 145
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.

SeDebugPrivilege 2 years 6 months ago #16106

  • Luca
  • Luca's Avatar Topic Author
  • Visitor
  • Visitor

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

SeDebugPrivilege 2 years 6 months ago #16107

  • Matis A.
  • Matis A.'s Avatar
  • Away
  • Moderator
  • Moderator
  • Posts: 1047
  • Thank you received: 145
uses
 windows
PilotLogic Core Programmer

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

SeDebugPrivilege 2 years 6 months ago #16108

  • Luca
  • Luca's Avatar Topic Author
  • Visitor
  • Visitor
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;

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

Last edit: by Luca.
  • Page:
  • 1