AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi IsProcess funktioniert unter Delphi 2010 nicht mehr!

IsProcess funktioniert unter Delphi 2010 nicht mehr!

Ein Thema von Koloss · begonnen am 21. Jul 2010 · letzter Beitrag vom 17. Mär 2016
Antwort Antwort
Koloss

Registriert seit: 21. Jul 2010
74 Beiträge
 
Delphi 2 Desktop
 
#1

IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 12:25
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?

Geändert von mkinzler (21. Jul 2010 um 12:26 Uhr) Grund: Delphi-Tag eingefügt
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 12:27
Welchen Typ hat ExeName?
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#3

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 12:43
Zitat:
function IsProcess(ExeName: string): Boolean;
Siehe Quelltext
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 12:44
Nimm AnsiString
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.017 Beiträge
 
Delphi 12 Athens
 
#5

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 12:45
was ist "blödsinn"?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Koloss

Registriert seit: 21. Jul 2010
74 Beiträge
 
Delphi 2 Desktop
 
#6

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 12:56
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.

Geändert von mkinzler (21. Jul 2010 um 13:36 Uhr) Grund: Delphi-Tag eingefügt
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.017 Beiträge
 
Delphi 12 Athens
 
#7

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 13:00
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.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (21. Jul 2010 um 13:06 Uhr)
  Mit Zitat antworten Zitat
Koloss

Registriert seit: 21. Jul 2010
74 Beiträge
 
Delphi 2 Desktop
 
#8

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 21. Jul 2010, 13:22
Ok, jetzt funktionierts mit ProcessIsRunning!
Den Rest kann ich kicken jetzt!

Danke! Scheinbar wer der SourceCode zu alt!
  Mit Zitat antworten Zitat
Koloss

Registriert seit: 21. Jul 2010
74 Beiträge
 
Delphi 2 Desktop
 
#9

AW: IsProcess funktioniert unter Delphi 2010 nicht mehr!

  Alt 17. Mär 2016, 11:03
Problem gelöst

Geändert von Koloss (17. Mär 2016 um 11:11 Uhr)
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:48 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