подскажите почему функция при втором вызове не убивает процесс?
т.е. есть 1.exe и 2.exe. оба запущены. при вызове DebugKillProcess(GetProcessId('1.exe')); процесс закрывается. еще раз вызываем DebugKillProcess(GetProcessId('2.exe')); процесс не закрывается
Код:
function TForm1.DebugKillProcess(ProcessId: dword): boolean;
var
pHandle: dword;
myPID: dword;
HandlesInfo: PSYSTEM_HANDLE_INFORMATION_EX;
r: dword;
begin
Result := false;
myPID := GetCurrentProcessId();
if not EnableDebugPrivilege() then Exit;
if DbgUiConnectToDbg() <> STATUS_SUCCESS then Exit;
pHandle := OpenProcessEx(ProcessId);
if DbgUiDebugActiveProcess(pHandle) <> STATUS_SUCCESS then Exit;
HandlesInfo := GetInfoTable(SystemHandleInformation);
if HandlesInfo = nil then Exit;
for r := 0 to HandlesInfo^.NumberOfHandles do
if (HandlesInfo^.Information[r].ProcessId = myPID) and
(HandlesInfo^.Information[r].ObjectTypeNumber = $8)
then begin
CloseHandle(HandlesInfo^.Information[r].Handle);
Result := true;
break;
end;
VirtualFree(HandlesInfo, 0, MEM_RELEASE);
end;