Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Prozesshandles (https://www.delphipraxis.net/173404-prozesshandles.html)

tk_tommy 22. Feb 2013 13:44

Prozesshandles
 
HI!

Ich habe folgendes Problem.

- Ich starte aus meinem Programm heraus ein anderes Programm mit CreateProcess.
- Die Prozess-ID wird gesichert.
- Nach einiger Zeit wird der Prozess von mir beendet. (Terminate)
- Im Win7-Taskmanager werden aber ständig die Handles hochgezählt.
Nach einigen Stunden habe ich bereits über 2000 Handles.

Code-Ausschnitt
- Prozess erstellen

if(CreateProcess(Nil,pchar(pProgramName + ' ' + uebergabe),nil,nil,false,NORMAL_PRIORITY_CLASS,nil ,nil,StartupInfo,ProcessInfo) = true) then begin;
GetExitCodeProcess(ProcessInfo.hProcess,exestatus) ;
if(exestatus = STATUS_PENDING) then begin;
vResult := ProcessInfo.hProcess;
ThreadId := ProcessInfo.hThread;
pdwProcessId := ProcessInfo.dwProcessId;
end;
end;


- Prozess beenden

procid := OpenProcess(PROCESS_TERMINATE, false, strtoint(pid));
if(procid <> 0) then begin;
// ExitCode laden
GetExitCodeProcess(procid,processstatus);
// Prozess beenden
if(terminateprocess(procid,processstatus) = true) then begin;
try closehandle(procid); except end;
status := true;
end
end;


- Prozess prüfen

procid := OpenProcess(PROCESS_TERMINATE, false, strtoint(pid));
if(procid <> 0) then begin;
status := true;
end;



Wenn ich nach Beendigung des Prozesses prüfe, ob der Prozess noch läuft, wird der beendete Prozess gefunden????


Wie kann ich das verhindern? / Wo liegt der Fehler


Grüße Tommy

TiGü 22. Feb 2013 14:06

AW: Prozesshandles
 
Delphi-Quellcode:
 // - Prozess prüfen

        procid := OpenProcess(PROCESS_TERMINATE, false, strtoint(pid));
        if(procid <> 0) then begin;
          status := true;
        end;
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Zitat:

Zitat von MSDN
The handle returned by the OpenProcess function can be used in any function that requires a handle to a process, such as the wait functions, provided the appropriate access rights were requested.

When you are finished with the handle, be sure to close it using the CloseHandle function.


TiGü 22. Feb 2013 14:07

AW: Prozesshandles
 
Doppelpost

Dalai 22. Feb 2013 15:02

AW: Prozesshandles
 
Zitat:

Zitat von tk_tommy (Beitrag 1204774)
Wo liegt der Fehler

Auch wenn du dir Frage sicher anders gemeint hast, so fallen mir sofort einige Fehler auf:
  • Boolesche Prüfung auf True
  • Fehlende Code-Tags. Ich frag mich immer wieder, warum die nicht genutzt werden - woran liegt das?

Zum eigentlichen Problem des Themas kann ich mich TiGü nur anschließen: Zu jedem OpenProcess() gehört ein CloseHandle().

MfG Dalai


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz