Autor Beitrag
TheMexx
Hält's aus hier
Beiträge: 10


D7 Ent, D6 Ent
BeitragVerfasst: Mi 21.07.10 12:13 
Bekomme bei rProcess.aExeFile, ein blödsinn Raus!

Unter Delphi 2007 funktioniert es noch! Betriebsystem WinXP!

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:
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
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: 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. ;-)
ausblenden 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;

_________________
We are, we were and will not be.
Sybok Factor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50
Erhaltene Danke: 5

Win XP, Win Vista
Delphi 2010 Professional
BeitragVerfasst: Mi 21.07.10 13:36 
Ich nehme an, dass dieser Crosspost dazu gehört: www.delphipraxis.net...ehr.html#post1036576.

Viele Grüße
Sybok

_________________
Jetzte michse verstehen dein Problem.
TheMexx Threadstarter
Hält's aus hier
Beiträge: 10


D7 Ent, D6 Ent
BeitragVerfasst: Mi 21.07.10 13:54 
Richtige annahme, Problem damit gelöst!
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: 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:
ausblenden 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. ;-)