Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the process ID's of all running programs Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
10-Oct-02
Category
System
Language
Delphi 2.x
Views
115
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

I am trying to build a component to get info about the programs executing in my NT4 
environment. I managed to get the names for all the windows running (title text). 
Now, how can I get the process ID for each of them? Which function should I use? Is 
there any function that tells me for how long my process is running?

Answer:

It is better to use the EnumWindows function instead of FindWindow/GetWindow, 
because the latter isn't sensitive to windows being destroyed halfway through the 
loop and you can end up getting invalid handles. Here's an example:
1   
2   function EnumWindowsProc(hWnd: LongWord; Form: TForm1): WordBool; stdcall;
3   begin
4     Form.FoundAWindow(hWnd);
5     Result := True
6   end;
7   
8   procedure TForm1.FoundAWindow(hWnd: LongWord);
9   var
10    ProcessID: LongWord;
11    Title: array[0..255] of Char;
12  begin
13    GetWindowThreadProcessID(hWnd, @ProcessID);
14    GetWindowText(hWnd, Title, 256);
15    {Now, do whatever you want with Title and ProcessID, e.g.:}
16    Memo1.Lines.Add(Title + ' [' + IntToStr(ProcessID) + ']')
17  end;
18  
19  procedure TForm1.Timer1Timer(Sender: TObject);
20  begin
21    EnumWindows(@EnumWindowsProc, Integer(Self))
22  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC