Entwickler-Ecke

Windows API - Programm nach Exe-Namen finden


seddto - Do 06.05.04 17:44
Titel: Programm nach Exe-Namen finden
Hallo,

Ich möchte gerne festellen ob ein bestimmter Prozess läuft. Ich hab mir schon verschiedene Threads hier zu diesem Thema durchgelesen, zb. über Enumwindows. Allerdings wurde das problem dort immer über die Suche nach einem bestimmten String im Fenstertitel gesucht. Das funktioniert bei meinem Problem leider nicht weil ich wie gesagt, weil ich die laufenden Prozess nach einem bestimmten Exe-Namen durchsuchen möchte. Ich hab auch schon versucht die Fenster-Class herauszubekommen, das funktioniert allerdings auch nicht, weil das entsprechende Programm eine Konsolenanwendung ist. Außerdem kommen, wenn ich mit Enumwindows die aktiven Fenster durchlaufe unter getwindowclass immer nur ganz abstrackte Bezeichnungen, nach denen ich nicht darauf schliessen kann, welches Programm dahinter steckt. Weiss jemand wie ich mit enumwindows oder einer anderen Funktion die laufenden Prozesse nach einem Exe-Namen durchsuchen kann?
Wäre echt dankbar für ein bisschen Hilfe :)

LG Seddto.


bms - Do 06.05.04 19:05

Welches System?


Motzi - Do 06.05.04 20:59

Suche in: Delphi-Forum, Delphi-Library SNAPSHOT - funzt unter allen OS außer NT 4.0


MSCH - Do 06.05.04 22:18

Statt Suche, sollten

Zitat:
Takes a snapshot of the processes and the heaps, modules, and threads used by the processes.

HANDLE WINAPI CreateToolhelp32Snapshot(DWORD dwFlags,
DWORD th32ProcessID);


Parameters

dwFlags

Flags specifying portions of the system to include in the snapshot. These values are defined:

TH32CS_INHERIT Indicates that the snapshot handle is to be inheritable.
TH32CS_SNAPALL Equivalent to specifying the TH32CS_SNAPHEAPLIST, TH32CS_SNAPMODULE, TH32CS_SNAPPROCESS, and TH32CS_SNAPTHREAD values.
TH32CS_SNAPHEAPLIST Includes the heap list of the specified process in the snapshot.
TH32CS_SNAPMODULE Includes the module list of the specified process in the snapshot.
TH32CS_SNAPPROCESS Includes the Win32 process list in the snapshot.
TH32CS_SNAPTHREAD Includes the Win32 thread list in the snapshot.

th32ProcessID
Process identifier. This parameter can be zero to indicate the current process. This parameter is used when the TH32CS_SNAPHEAPLIST or TH32CS_SNAPMODULE value is specified. Otherwise, it is ignored.

Return Value
Returns an open handle to the specified snapshot if successful or - 1 otherwise.


Zitat:

BOOL WINAPI Process32First(HANDLE hSnapshot, LPPROCESSENTRY32 lppe);

Parameters
hSnapshot
Handle of the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.

lppe
Address of a PROCESSENTRY32 structure.

Return Value
Returns TRUE if the first entry of the process list has been copied to the buffer or FALSE otherwise. The ERROR_NO_MORE_FILES error value is returned by the GetLastError function if no processes exist or the snapshot does not contain process information.


und
Zitat:
BOOL WINAPI Process32Next(HANDLE hSnapshot, LPPROCESSENTRY32 lppe);

Parameters
hSnapshot
Handle of the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.
lppe
Address of a PROCESSENTRY32 structure.
Return Value
Returns TRUE if the next entry of the process list has been copied to the buffer or FALSE otherwise. The ERROR_NO_MORE_FILES error value is returned by the GetLastError function if no processes exist or the snapshot does not contain process information.



Zitat:

typedef struct tagPROCESSENTRY32 {
DWORD dwSize;
DWORD cntUsage;
DWORD th32ProcessID;
DWORD th32DefaultHeapID;
DWORD th32ModuleID;
DWORD cntThreads;
DWORD th32ParentProcessID;
LONG pcPriClassBase;
DWORD dwFlags;
char szExeFile[MAX_PATH];
} PROCESSENTRY32;
typedef PROCESSENTRY32 * PPROCESSENTRY32;
typedef PROCESSENTRY32 * LPPROCESSENTRY32;


(aus W32 SDK)
das richtige sein.

grez
msch


Motzi - Do 06.05.04 22:25

Und die Suche führt auch gleich zu ein paar hilfreichen Code-Schnipsel wie man genau diese Funktionen verwendet..! ;)


scrooge - Fr 07.05.04 15:24

Um das ganze etwas sicherer u machen (es könnten schließlich mehere Exe mit selben NAme laufen) könntest du auch noch GetModuleFilenameEx aus der psApi holen.


Shadow110 - Fr 07.05.04 16:10

Wir sind zwar im Windows API Forum... aber vielleicht ist es ja trotdem interessant..
Madcollection installieren

http://www.madshi.net

Und dann


Delphi-Quelltext
1:
2:
3:
4:
5:
var
  antwort:boolean;
begin
  antwort := Process('calc.exe').IsStillRunning;
end;


Grüße
Alex

Moderiert von user profile iconPeter Lustig (16:10, 07.05.2004): Delphi-Tags hinzugefügt