procedure TForm2.Button2Click(Sender: TObject);
var
h: HWND;
dwPid: DWORD;
hThreadProcess: THANDLE;
s: string;
begin
h := FindWindow(PChar(Edit2.Text), PChar(Edit1.Text));
if h > 0 then begin
OutputDebugString('找到句柄');
GetWindowThreadProcessId(h, @dwPid);
if dwPid > 0 then begin
{$IFNDEF _API}
OutputDebugString('通过命令行关闭进程');
s := Format('ntsd -c q -p %d',[dwPid]);
//taskkill同ntsd也可以关闭进程
Self.Caption := s;
WinExec(PAnsiChar(s) ,SW_HIDE);
{$ELSE}
OutputDebugString('通过API关闭进程');
hThreadProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
TerminateProcess(hThreadProcess, 0);
CloseHandle(hThreadProcess);
{$ENDIF}
end;
end;
end;Delphi关闭进程
最新推荐文章于 2026-05-10 05:38:05 发布

664

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



