Registriert seit: 16. Aug 2004
165 Beiträge
Delphi 7 Enterprise
|
AW: Feststellen, ob Prozess (Handle bekannt) noch gestartet ist
15. Aug 2011, 13:34
Vielleicht hilft dies hier aus meiner Codesnippet-Sammlung:
Code:
uses PsAPI;
function ProcessExists(const ABaseName: string): Boolean;
// ref: http://delphikingdom.com/asp/answer.asp?IDAnswer=24727
const
MAX_PID = 1024;
var
lpidProcess: array[0..MAX_PID - 1] of DWORD;
cbNeeded: DWORD;
i: Integer;
hProcess: THandle;
lpBaseName: array[0..MAX_PATH] of AnsiChar;
begin
Result := False;
if not EnumProcesses(@lpidProcess, MAX_PID, cbNeeded) then Exit;
for i := 0 to (cbNeeded div SizeOf(DWORD)) do
begin
hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, lpidProcess[i]);
if hProcess <> 0 then
try
if GetModuleBaseName(hProcess, 0, lpBaseName, MAX_PATH) <> 0 then
begin
if SameText(lpBaseName, ABaseName) then
begin
Result := True;
Break;
end;
end;
finally
CloseHandle(hProcess);
end;
end;
end;
// Beispiel:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if not ProcessExists('Firefox.exe') then doSomething;
end;
|
|
Zitat
|