Entwickler-Ecke

Sonstiges (Delphi) - IsProcess funktioniert unter Delphi 2010 nicht mehr!


TheMexx - Mi 21.07.10 12:13
Titel: IsProcess funktioniert unter Delphi 2010 nicht mehr!
Bekomme bei rProcess.aExeFile, ein blödsinn Raus!

Unter Delphi 2007 funktioniert es noch! Betriebsystem WinXP!


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:
function IsProcess(ExeName: string): Boolean;
(*
** This routine examines Windows processes currently running to see if a
** certain program is running.
**
** sExe  : The executable name of the program to check.
** Result: True if the program is running, False otherwise.
*)

var
  liI, lSnapShot: Longint;
  rProcess      : TProcessEntry32;
begin
  Result := False;
  ExeName := UpperCase(ExeName);
  lSnapShot := CreateToolHelpSnapShot(TH32CS_SNAPPROCESS, 0);
  if lSnapShot <> 0 then begin
    rProcess.iSize := SizeOf(rProcess);
    liI := ProcessFirst(lSnapShot, rProcess);
    while liI <> 0 do begin
      if Pos(ExeName, UpperCase(rProcess.aExeFile)) <> 0 then begin
        Result := True;
        Break;
      end;
      liI := ProcessNext(lSnapShot, rProcess);
    end;
    CloseHandle(lSnapShot);
  end;

end;

Hat wer eine Idee?

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt


Gausi - Mi 21.07.10 12:52

Wenn es unter 2007 noch klappt, und unter 2010 Blödsinn rauskommt, würde ich spontan auf ein Unicode-Problem wetten. Zeigt der Compiler irgendwelche Hinweise an, dass irgendwo String/AnsiString/UnicodeString/UTF8String durcheinanderkommen?

Edit: Wenn ich richtig gegoogelt habe, sollte dir das weiterhelfen. ;-)

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
TProcessEntry32 = packed record
  iSize,
  iUsage,
  iProcessID,
  iDefaultHeapId,
  iModuleId,
  iThreads,
  iParentProcessId,
  iPriClassBase,
  iFlags: Integer;
  aExeFile: array[0..MAX_PATH] of AnsiChar;
end;


Sybok Factor - Mi 21.07.10 13:36

Ich nehme an, dass dieser Crosspost dazu gehört: http://www.delphipraxis.net/153108-isprocess-funktioniert-unter-delphi-2010-nicht-mehr.html#post1036576.

Viele Grüße
Sybok


TheMexx - Mi 21.07.10 13:54

Richtige annahme, Problem damit gelöst!


jaenicke - Mo 26.07.10 05:46

Das ist gar nicht notwendig. Mit der mitgelieferten TlHelp32 Unit funktioniert es wunderbar. Da gibt es aExeFile auch gar nicht, sondern szExeFile. Das ist ein WideChar-Array, mit dem es mit Unicode wunderbar funktioniert.

Ich vermute daher, dass hier aus irgendeinem Grund TProcessEntry32 selbst deklariert wurde und das geht dann eben schief...

Und da die aufgerufenen Funktionen auf die WideChar-Versionen gemappt sind, wird es mit AnsiChar erst recht nicht gehen, sondern mit:

Delphi-Quelltext
1:
    szExeFile: array[0..MAX_PATH - 1of WChar;                    
Natürlich geht theoretisch auch AnsiChar, dafür gibts Process32FirstA, TProcessEntry32A, ..., aber das ist ja Blödsinn. ;-)