您的位置:首页 > 编程语言 > Delphi

Delphi关闭进程

2012-12-16 21:05 316 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: