function DSiTerminateProcessById(processID: DWORD; closeWindowsFirst: boolean; maxWait_sec: integer): boolean; var hProcess: THandle; begin Result := false; hProcess := OpenProcess(SYNCHRONIZE OR PROCESS_TERMINATE, false, processID); if hProcess = 0 then Exit; try if closeWindowsFirst then begin EnumWindows(@DSiSendWMCloseToWindow, integer(processID)); Result := (WaitForSingleObject(hProcess, maxWait_sec * 1000) = WAIT_OBJECT_0); end; if not Result then Result := TerminateProcess(hProcess, 0); finally CloseHandle(hProcess); end; end; { DSiTerminateProcessById } DSiWin32中的代码
原帖子如下:
http://topic.csdn.net/t/20041115/21/3555509.html那位高手整理一下,谢谢了
maxWait_sec: integer): boolean;
var
hProcess: THandle;
begin
Result := false;
hProcess := OpenProcess(SYNCHRONIZE OR PROCESS_TERMINATE, false, processID);
if hProcess = 0 then
Exit;
try
if closeWindowsFirst then begin
EnumWindows(@DSiSendWMCloseToWindow, integer(processID));
Result := (WaitForSingleObject(hProcess, maxWait_sec * 1000) = WAIT_OBJECT_0);
end;
if not Result then
Result := TerminateProcess(hProcess, 0);
finally CloseHandle(hProcess); end;
end; { DSiTerminateProcessById }
DSiWin32中的代码