Autor Beitrag
TimKellner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Sa 19.05.07 17:54 
Hallo liebe Community ich habe ein Problem und zwar möchte ich die Prozesse nach einem bestimmten Task durchsuchen.

Mein Versuch eine Prozessliste zu erstellen ist schon gescheitert. Könnt ihr mir vielleicht helfen?

Mein Versuch:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm_Main.SearchProcess(Prozessname: String);
var
  hProcSnap: THandle;
  pe32: TProcessEntry32;
  sl: TStrings;
begin
  sl.Create;
  { Snapshot machen *PENG* }
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  if hProcSnap = INVALID_HANDLE_VALUE then exit;


  pe32.dwSize := SizeOf(ProcessEntry32);


  { wenn es geklappt hat }
  if Process32First(hProcSnap, pe32) = true then
    { und los geht's }
    { Process32First liefert auch schon einen Prozess, den System-Prozess }
    sl.Add(pe32.szExeFile);
    while Process32Next(hProcSnap, pe32) = true do
    begin
      sl.Add(pe32.szExeFile);
    end;
  CloseHandle(hProcSnap);
end;
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Sa 19.05.07 18:00 
Hi!

Was ist denn das Ergebniss deines Versuchs?

Compiliert nicht? Kommt nix raus? Bricht mit Fehlermeldung ab?

EDIT:
Oh jetzt hab ich gerade noch was gesehen:
Bitte kein sl.Create(); machen.
Stattdessen ein
ausblenden Delphi-Quelltext
1:
sl := TStrings.Create();					
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Sa 19.05.07 18:05 
Hi,

ich bekomme die Fehlermeldung EAbstractError. Meldung: 'Abstrakter Fehler'.

EDIT:
Der Fehler tritt zwischen diesen beiden Zeilen auf:
ausblenden Delphi-Quelltext
1:
2:
sl.Add(pe32.szExeFile);
while Process32Next(hProcSnap, pe32) = true do
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 19.05.07 18:28 
Rischtisch. Es müsste heißen sl:= TStringList.Create;

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Sa 19.05.07 18:29 
Jo, dann ist es eben dass was ist oben beschrieben habe.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Sa 19.05.07 18:38 
Ich habe den Code jetzt so umgeändert, doch der Feher tritt immernoch auf.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure TForm_Main.SearchProcess(Prozessname: String);
var
  hProcSnap: THandle;
  pe32: TProcessEntry32;
  sl: TStrings;
begin
  sl := TStrings.Create();
  { Snapshot machen *PENG* }
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  if hProcSnap = INVALID_HANDLE_VALUE then exit;


  pe32.dwSize := SizeOf(ProcessEntry32);


  { wenn es geklappt hat }
  if Process32First(hProcSnap, pe32) = true then
    { und los geht's }
    { Process32First liefert auch schon einen Prozess, den System-Prozess }
    sl.Add(pe32.szExeFile);
    while Process32Next(hProcSnap, pe32) = true do
    begin
      sl.Add(pe32.szExeFile);
    end;
  CloseHandle(hProcSnap);
end;
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Sa 19.05.07 18:46 
Also zum einen solltest du irgendwo das TStrings noch freigeben. (sl.Free();)

Ich hatte manchmal meine Probleme mit TStrings. Hab dann TStringList oder so ähnlich verwendet.
Vielleicht funktioniert ja das. Hab gerade leider kein Delphi zur Hand ums zu testen.
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: Sa 19.05.07 19:03 
Also am schluss freigeben klappt schonmal nicht.

In Delphi bekomme ich jedoch generell folgende Warnungen vor dem Compilieren

[Warnung] Unit_Main.pas(66): Instanz von 'TStrings' mit der abstrakten Methode 'TStrings.Clear' wird angelegt
[Warnung] Unit_Main.pas(66): Instanz von 'TStrings' mit der abstrakten Methode 'TStrings.Delete' wird angelegt
[Warnung] Unit_Main.pas(66): Instanz von 'TStrings' mit der abstrakten Methode 'TStrings.Insert' wird angelegt
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 19.05.07 19:08 
user profile iconMartok hat folgendes geschrieben:
Rischtisch. Es müsste heißen sl:= TStringList.Create;

Hört mir denn keiner zu ;)

TStrings ist eine Abstrakte Klasse. Sowas instantiiert man nicht. Würde auch in der Hilfe stehen, wenn die mal einer lesen würde:
DOH hat folgendes geschrieben:
TStrings enthalten abstrakte bzw. rein virtuelle (C++ Terminologie) Methoden und sollten nicht direkt instantiiert werden.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
TimKellner Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73

Win XP Pro
Delphi 7 Enterprise, RAD Studio
BeitragVerfasst: So 20.05.07 13:29 
Es kommt schonmal keine Fehlermeldung mehr.

EDIT:

Soweit klappt jetzt alles jedoch funktioniert die Funktion nicht Ordnungsgemäß. Wenn ich die funktion auf einen bereits aktiven Prozess einstelle wird mir angezeigt das der Prozess nicht läuft. Ich muss den Prozess zb. den Internet Explorer einmal schließen und wieder neustarten, erst dann wird mir der Prozess angezeigt.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
function TForm_Main.SearchProcess(Prozessname: String):Boolean;
var
  hProcSnap: THandle;
  pe32: TProcessEntry32;
  sl: TStrings;
  i: integer;
begin
  sl := TStringList.Create();
  { Snapshot machen *PENG* }
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  if hProcSnap = INVALID_HANDLE_VALUE then exit;


  pe32.dwSize := SizeOf(ProcessEntry32);


  { wenn es geklappt hat }
  if Process32First(hProcSnap, pe32) = true then
    { und los geht's }
    { Process32First liefert auch schon einen Prozess, den System-Prozess }
    sl.Add(pe32.szExeFile);
    while Process32Next(hProcSnap, pe32) = true do
    begin
      sl.Add(pe32.szExeFile);
    end;
  CloseHandle(hProcSnap);
  for i:=0 to (sl.Count-1do
  begin
    if pos(Prozessname, SL[i]) = 0 THEN
    begin
      result := FALSE;
    end
    else
    begin
      result := TRUE;
    end;
  end;
  ShowMessage(BoolToStr(result));
  SL.Free;
end;
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: So 20.05.07 18:58 
Warum das ganze so umständlich ? Probiere es mal so :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
function TForm_Main.SearchProcess(Prozessname: String):Boolean;
var
  hProcSnap: THandle;
  pe32: TProcessEntry32;
begin
  Result := False;
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  if hProcSnap = INVALID_HANDLE_VALUE then exit;
  pe32.dwSize := SizeOf(ProcessEntry32);
  if Process32First(hProcSnap, pe32) = true then
    if Prozessname = pe32.szExeFile then
    begin
      Result := true;
      exit;
    end;
    while Process32Next(hProcSnap, pe32) = true do
    begin
      if Prozessname = pe32.szExeFile then
      begin
        Result := true;
        exit;
      end;
    end;
  CloseHandle(hProcSnap);
end;


So damit wird das Ergebnis als erste auf Falsch gesetzt. Wird jetzt der Prozessname (muss der Name der EXE Datei sein inkl. Dateiendung) gefunden, wird das Ergebnis True zurückgegeben und die Funktion wird verlassen.

P.S. : Wie immer alles ohne Gewähr.