delphi 对抗任务管理器关闭

禁用任务管理器示例
本文提供了一个使用 Delphi 和 Windows API 的示例代码,该代码演示了如何通过调整进程特权来阻止用户通过任务管理器终止当前运行的程序。
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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值