Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   IsProcess funktioniert unter Delphi 2010 nicht mehr! (https://www.delphipraxis.net/153108-isprocess-funktioniert-unter-delphi-2010-nicht-mehr.html)

Koloss 21. Jul 2010 11:25


IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Bekomme bei rProcess.aExeFile, ein blödsinn Raus!

Unter Delphi 2007 funktioniert es noch! Betriebsystem WinXP!

Delphi-Quellcode:
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?

mkinzler 21. Jul 2010 11:27

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Welchen Typ hat ExeName?

Neutral General 21. Jul 2010 11:43

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Zitat:

Delphi-Quellcode:
function IsProcess(ExeName: string): Boolean;

Siehe Quelltext

mkinzler 21. Jul 2010 11:44

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Nimm AnsiString

himitsu 21. Jul 2010 11:45

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
was ist "blödsinn"?

Koloss 21. Jul 2010 11:56

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Delphi-Quellcode:
type
  TProcessEntry32 = packed record
    iSize,
    iUsage,
    iProcessID,
    iDefaultHeapId,
    iModuleId,
    iThreads,
    iParentProcessId,
    iPriClassBase,
    iFlags : Integer;
    aExeFile: array[0..MAX_PATH] of Char;
  end;

function CreateToolHelpSnapShot(lFlags, lProcessId: Longint): Longint; stdcall;
function ProcessFirst(hSnapshot: longint; var uProcess: TProcessEntry32): Longint; stdcall;
function ProcessNext(hSnapshot: Longint; var uProcess: TProcessEntry32): Longint; stdcall;
procedure CloseHandle(hPass: Longint); StdCall;
1. Was hat meine Variable ExeName damit zu tun? Ich spreche ja von rProcess.aExeName!

2. Sowas kommt z.b.: Viereck(Symbol meine ich), Viereck, Viereck, Viereck, . e x e, usw.

himitsu 21. Jul 2010 12:00

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Ich würde mal mkinzlers Beitrag 4 zustimmen.
vorallem wenn man eingene Deklarationen/Implementationen von etwas verwendet, dann sollte man schonmal aufpassen, daß auch die Richtigen APIs implentiert werden und dieses auch noch richtig, damit der Compiler notfalls auch mal Fehlermeldungen bezüglich AnsiChar<>Char<>WideChar ausgeben kann (gibt unterschiedliche APIs für Ansi und Unicode)

Delphi-Quellcode:
function ProcessIsRunning(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 := ExtractFileName(ExeName);
  lSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if lSnapShot <> 0 then
    try
      rProcess.dwSize := SizeOf(rProcess);
      if Process32First(lSnapShot, rProcess) then
        repeat
          if AnsiSameText(ExeName, rProcess.szExeFile) then begin
            Result := True;
            Exit;
          end;
        until not Process32Next(lSnapShot, rProcess);
    finally
      CloseHandle(lSnapShot);
    end;
end;
PS: Nur den Dateinamen zu prüfen ist nicht nicht sicher, da man auch gleichnamige Programme aus unterschiedlichen Verzeichnis starten kann,
oder versuch es inkl. der kompletten Pfade:

Was willst du denn damit erreichen?
eventuell ist Hier im Forum suchenOneInstance (und was es sonst noch dazu im Forum zu finden gibt) was Passenderes.

Koloss 21. Jul 2010 12:22

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Ok, jetzt funktionierts mit ProcessIsRunning!
Den Rest kann ich kicken jetzt!

Danke! Scheinbar wer der SourceCode zu alt!

Koloss 17. Mär 2016 10:03

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!
 
Problem gelöst


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