Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Apps running...

Posted on 1998-02-11
13
Medium Priority
?
161 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 

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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

783 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