Autor Beitrag
Shadow110
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Di 13.04.04 18:12 
Hallo.

Gibt es eine Api, die mir die PID zu einem Prozess (z.B Notepad.exe) zurückgibt?

Wenn es geht nicht über die EnumProcesses Sache, wo man erst alle Prozesse einzeln durchgehen muss.
Sowas wie getWindowThreadProcessId nur für den Prozess Namen wäre schick...
Vielleicht gibt es da was..


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject);
var
win:integer;
test2:integer;
test3:integer;
test4:integer;
begin

win := FindWindow(nil, 'ID´s');
getWindowThreadProcessId(Win,@test2);
test3 := getcurrentprocessId;
test4 := GetModuleHandle('ID´s');


Vielleicht könnte noch kurz jemand erklären, was man bei dem GetModuleHandle eigentlich genau zurück bekommt?


Danke euch.

Grüße
Alex
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 13.04.04 20:05 
Nein, sowas gibt es nicht... es gibt 2 Möglichkeiten: über die PSAPIs (nur NT) -> Suche in: Delphi-Forum, Delphi-Library ENUMPROCESSES oder aber über die ToolHelpAPIs (Win9x und 2k/XP) Suche in: Delphi-Forum, Delphi-Library CREATETOOLHELP32SNAPSHOT

In jedem Fall musst du aber durch die gesamte Prozess-Liste iterieren und deinen Prozess raussuchen...

Eine dritte Möglichkeit wäre eventuell WMI wo man den Prozess mit einer einfachen WQL-Abfrage suchen kann, aber das ist etwas komplizierter..!

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Shadow110 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Di 13.04.04 22:44 
Hi

Danke für deine Antwort. Hat eine der beiden Methoden einen Vorteil? Oder ist das eher egal?

Viele Grüße
Alex
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 13.04.04 23:07 
Ist IMHO eigentlich ziemlich egal... vielleicht ist EnumProcesses eine Spur schneller, aber sonst...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Delphi-Laie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1600
Erhaltene Danke: 232


Delphi 2 - RAD-Studio 10.1 Berlin
BeitragVerfasst: So 20.04.08 21:54 
user profile iconShadow110 hat folgendes geschrieben:
Hallo.

Gibt es eine Api, die mir die PID zu einem Prozess (z.B Notepad.exe) zurückgibt?

Wenn es geht nicht über die EnumProcesses Sache, wo man erst alle Prozesse einzeln durchgehen muss.
Sowas wie getWindowThreadProcessId nur für den Prozess Namen wäre schick...
Vielleicht gibt es da was..


Jo, gibt es, und zwar mal wieder von unserem Luckie:www.delphipraxis.net...nwendung+laeuft.html

Dort wird zwar auch nur "einzeln durchgegangen", jedoch wenigstens beim Fund abgebrochen.