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.
delphi 对抗任务管理器关闭
禁用任务管理器示例
最新推荐文章于 2021-07-30 13:34:09 发布
本文提供了一个使用 Delphi 和 Windows API 的示例代码,该代码演示了如何通过调整进程特权来阻止用户通过任务管理器终止当前运行的程序。
2932

被折叠的 条评论
为什么被折叠?



