delphi 대항 작업 관리자 닫기

1651 단어
program Project1;

uses
  Windows;

{$R *.res}
function MakeMeCritical(Yes: Boolean): Boolean;
const
  SE_DEBUG_PRIVILEGE = $14;
  SE_PROC_INFO = $1D;
var
  Enabled: PBOOL;
  DllHandle: THandle;
  BreakOnTermination: ULong;
  HR: HRESULT;
  RtlAdjustPrivilege: function(Privilege: ULONG; Enable: BOOL; CurrentThread: BOOL; var Enabled: PBOOL): DWORD; stdcall;
  NtSetInformationProcess: function(ProcHandle: THandle; ProcInfoClass: ULONG; ProcInfo: Pointer;  ProcInfoLength: ULONG): HResult; stdcall;
begin
  Result := False;
  DllHandle := LoadLibrary('ntdll.dll') ;
  if DllHandle <> 0 then
  begin
     @RtlAdjustPrivilege := GetProcAddress(dllHandle, 'RtlAdjustPrivilege');
     if (@RtlAdjustPrivilege <> nil) then
     begin
       if RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, True, True, Enabled) = 0 then
       begin
          @NtSetInformationProcess := GetProcAddress(dllHandle, 'NtSetInformationProcess');
          if (@NtSetInformationProcess <> nil) then
          begin
            BreakOnTermination := Ord(Yes);
            HR := NtSetInformationProcess(GetCurrentProcess(), SE_PROC_INFO, @BreakOnTermination, SizeOf(BreakOnTermination));
            Result := HR = S_OK;
          end;
       end;
     end;
     FreeLibrary(DllHandle);
  end
end;

begin
  if MakeMeCritical(True) then
  begin
    //the user cannot termintate the process now
    MessageBoxA(0, PAnsiChar(' TMD           !'), PAnsiChar('       '), 0);
    MakeMeCritical(False)
  end
  else
    MessageBoxA(0, PAnsiChar(' ,NO!'), PAnsiChar('Test'), 0);
end.

좋은 웹페이지 즐겨찾기