Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi KillTask Hilfe bitte (https://www.delphipraxis.net/56050-killtask-hilfe-bitte.html)

f4r 31. Okt 2005 11:40


KillTask Hilfe bitte
 
Hallo Leute,

vorab ich bin nur ein Laie der sich gerne mit delphi beschäftigt

die folgende funktion hab ich ausm netz gezogen funkz auch !

hier eine Funktion zum Beenden eines Programmes !
( Direkt aus dem Task Manager )


Delphi-Quellcode:
function KillTask(ExeFileName: string): Integer;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  Result := 0;
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);

  while Integer(ContinueLoop) <> 0 do
  begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
      UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
      UpperCase(ExeFileName))) then
      Result := Integer(TerminateProcess(
                        OpenProcess(PROCESS_TERMINATE,
                                    BOOL(0),
                                    FProcessEntry32.th32ProcessID),
                                    0));
     ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;


Fragt mich net ich versteh sie auch net

Was ich jetzt aber brauch ist ne Funktion oder Procedure die klärt ob ein Proggie noch aktiv ist !

WEis jemand da n idee ?

mfg

f4r

[edit=alcaeus]Delphi-Tags eingefuegt. Mfg, alcaeus[/edit]

ichbins 31. Okt 2005 11:52

Re: KillTask Hilfe bitte
 
1. Willkommen in der DP :party:

2. Bitte verwende doch die Delphi-Tags: [DeIphi] CODE [/DeIphi]

3. Zu deiner Frage: Du musst deine Funktion nur etwas umschreiben:

Delphi-Quellcode:
function TaskRunning(ExeFileName: string): Boolean;
const
  PROCESS_TERMINATE = $0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  Result := false;
  FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
  while ContinueLoop do
  begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName))
    or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName)))
    then Result := true;
    ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;
(ungetestet) welche Unit hast du denn eingebunden? Ich hab tprocessentry32 nich...
die Codeformatierung ist übrigens grauenhaft :kotz:

f4r 31. Okt 2005 12:49

Re: KillTask Hilfe bitte
 
danke scho ma

wie müsste dann eine abfrage ???

Delphi-Quellcode:
if taskrunning ('IEXPLORE.EXE')=TRUE then
  KILLTASK ('IEXPLORE')
else
  SHOWMESSAGE('DANKE LIEBES DELPHI - PRAXIS FORUM');
(habsnochnet getestet) mach ich nachher

P.S. Codeformat ich habs nur rauskopiert
P.P.S Ist einem normalen Delphi Projekt in ner pas mit Forum drinne, meinstde das ???


mfg

f4r

[edit=alcaeus]Delphi-Tags gesetzt. Mfg, alcaeus[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:10 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