Solved

Apps running...

Posted on 1998-02-11
13
137 Views
Last Modified: 2010-04-04
I´m developing an application will execute in Win95 and WindowsNT. I need some function (or component) to identify all programs running in the computer. This function should be able in both platforms. Thanks!!
PD: My english is not good, sorry!!
0
Comment
Question by:Marcelito
  • 6
  • 4
  • 3
13 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1359037
You can use EnumWindows
0
 
LVL 4

Expert Comment

by:d003303
ID: 1359038
EnumWindows will return all windowed applications. Do you want to identify all running programs or all running processes (like the applications/processes page on NT task manager) ?
0
 

Author Comment

by:Marcelito
ID: 1359039
Ok! I need identify all programs running, but if I can identify all processes also is better. I have a primary solution, but not work properly in some cases. Thanks!!
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1359040
Can you be more specific about what is the porblem with your solution
0
 

Author Comment

by:Marcelito
ID: 1359041
When I execute the program in IDE, it´s work (sometimes I have an Access Violation error when close the main form). When I execute the .exe file, the program perform an invalid operation, and Windows close the task. I´m confused!!

PD: I´m not using components, only API functions. THANKS!!
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1359042
Post your code and we'll see why it fails

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Marcelito
ID: 1359043
Here is the code. Good Luck MikeP!!

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

var hWnd, hWndAux:integer;
    spBuffer:pChar;
    sWndTitle, sAux:string;
    encontre: boolean;
    nTitleSize,comp: integer;

begin
    nTitleSize:=0;
    hWnd:= 0;
    encontre:= false;
    spBuffer:='';
    hWnd:=GetTopWindow(0);
    nTitleSize:= GetWindowTextLength(hWnd);
    GetWindowText(hWnd,spBuffer,nTitleSize);
    sWndTitle:= StrPas(spBuffer);
    ShowMessage(sWndTitle);
    while hWnd <> 0 do
      begin
         hWndAux:=hWnd;
         hWnd:= GetNextWindow(hWndAux,GW_HWNDNEXT);
         if IsWindow(hWnd) then
           begin
             nTitleSize:= GetWindowTextLength(hWnd);
             GetWindowText(hWnd,spBuffer,nTitleSize+1);
             sWndTitle:= StrPas(spBuffer);
             sWndTitle:=Trim(sWndTitle);
             ShowMessage(sWndTitle);
           end;

      end;
end;

end.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1359044
you have to init/uninit the spBuffer with GetMem and FreeMem before each call to GetWindowText. PChar is only a pointer to a character chain. You always have to allocate the memory before and free memory after you used it.

hWnd:=GetTopWindow(0);
nTitleSize:= GetWindowTextLength(hWnd);
// here you allocate the memory
GetMem(spBuffer, nTitleSize + 1);
// there was the + 1 missing
GetWindowText(hWnd,spBuffer,nTitleSize + 1);
sWndTitle:= StrPas(spBuffer);
// here you free it
FreeMem(spBuffer, nTitleSize + 1);
ShowMessage(sWndTitle);
while hWnd <> 0 do
begin
hWndAux:=hWnd;
hWnd:= GetNextWindow(hWndAux,GW_HWNDNEXT);
if IsWindow(hWnd) then
begin
nTitleSize:= GetWindowTextLength(hWnd);
// here you allocate the memory
GetMem(spBuffer, nTitleSize + 1);
GetWindowText(hWnd,spBuffer,nTitleSize+1);
sWndTitle:= StrPas(spBuffer);
// here you free it
FreeMem(spBuffer, nTitleSize + 1);
sWndTitle:=Trim(sWndTitle);
ShowMessage(sWndTitle);
end;

Slash/d003303
0
 

Author Comment

by:Marcelito
ID: 1359045
Well, I think that I have a cloud in my mind. How I can forget it? Thanks, d003303!! My solution is working now!! Thanks to MikeP also! See you.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1359046
Your question has to be graded if you got a working answer. Please let us know if the main part of the question was solved by MikeP or me, that he / I can give an answer to put the question to the PAQ area.
0
 

Author Comment

by:Marcelito
ID: 1359047
Sorry. Really the main part of question was resolved by you, d003303. I was not know the way to grade the answer. Please, tell me and I will do! Thanks  
0
 
LVL 4

Accepted Solution

by:
d003303 earned 100 total points
ID: 1359048
OK, you have to accept this answer and grade the question. Have a look at the Expert grading help link below.

Good luck on all your projects,
Slash/d003303
0
 

Author Comment

by:Marcelito
ID: 1359049
Thanks!! Good luck for you!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 96
LAN or WAN ? 11 82
Dynamically Created Query 3 50
Delphi...Split view - idea? 1 42
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now