Board index » delphi » Getting a list of running Windows programs

Getting a list of running Windows programs

I would like to know how to retrieve a list of
running Windows applications using Delphi code.  I
ultimately need to find out if a certain application
is running by checking for a Window Title.  I have
been trying to figure this out by using the
TaskFirst and TaskNext Windows API functions, but I
can't seem to get it to work.

If anyone can help it would be much appreciated.

Thanks,

John Smale
sma...@cadvision.com

 

Re:Getting a list of running Windows programs


Quote
sma...@cadvision.com (John Smale) wrote:
>I would like to know how to retrieve a list of
>running Windows applications using Delphi code.  I
>ultimately need to find out if a certain application
>is running by checking for a Window Title.  I have
>been trying to figure this out by using the
>TaskFirst and TaskNext Windows API functions, but I
>can't seem to get it to work.

        Well, if you're looking for a window with a certain title to
recognize the application then maybe you want to use GetWindow, etc.

        But my guess is that the best way to get a list of the running
programs is by ModuleFirst and ModuleNext, because there's this field in
the TModuleEntry containing the module name. Probably ModuleFirst and
ModuleNext won't work any better than TaskFirst/Next the first time.
There's a trick to it - you have to fill in the dwSize field first:

var AModule:TModuleEntry;
begin
AModule.dwSize:=SizeOf(TModuleEntry); {Oh...}
ModuleFirst(AModule);
{etc}
end;

        You need to do the same thing with TaskFirst, and probably with other
Toolhelp structures/functions.

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Re:Getting a list of running Windows programs


Here is some Visual Basic code that use WINAPI calls and finds a Netscape
window currently running:

Declare Function GetNextWindow% Lib "User" (ByVal hWnd%, ByVal wFlag%)
Declare Function GetWindowText% Lib "User" (ByVal hWnd%, ByVal lpstring$,
ByVal aint%)
Declare Function GetWindowTextLength% Lib "User" (ByVal hWnd%)

  Dim n%

  handle% = hWnd
  n% = 0
  Do
    handle% = GetNextWindow%(handle%, GW_HWNDNEXT)
    aint% = GetWindowTextLength%(handle%)
    lpstring$ = String$(aint%, Chr$(0))
    result% = GetWindowText%(handle%, lpstring$, aint% + 1)
    If InStr(UCase$(lpstring$), "NETSCAPE") > 0 Then
      Exit Do
    End If
    n% = n% + 1
  Loop

  CurrentPage$ = lpstring$

It should be easy to translate into DELPHI for your purposes.

--
Alexander Medwedew
Computer Ventures, Inc.
compv...@tribeca.ios.com
http://tribeca.ios.com/~compvent/

Re:Getting a list of running Windows programs


On 24 Jan 1996 18:09:00 GMT, Alexander Medwedew

Quote
<compv...@tribeca.ios.com> wrote:
>Here is some Visual Basic code that use WINAPI calls and finds a Netscape
>window currently running:

>Declare Function GetNextWindow% Lib "User" (ByVal hWnd%, ByVal wFlag%)
>Declare Function GetWindowText% Lib "User" (ByVal hWnd%, ByVal lpstring$,
>ByVal aint%)
>Declare Function GetWindowTextLength% Lib "User" (ByVal hWnd%)

>  Dim n%

>  handle% = hWnd
>  n% = 0
>  Do
>    handle% = GetNextWindow%(handle%, GW_HWNDNEXT)
>    aint% = GetWindowTextLength%(handle%)
>    lpstring$ = String$(aint%, Chr$(0))
>    result% = GetWindowText%(handle%, lpstring$, aint% + 1)
>    If InStr(UCase$(lpstring$), "NETSCAPE") > 0 Then
>      Exit Do
>    End If
>    n% = n% + 1
>  Loop

>  CurrentPage$ = lpstring$

>It should be easy to translate into DELPHI for your purposes.

VB..... YUK

Anyway, slightly off the original topic but a much easier way to find
a *known* window is to use the findwindow call ie.

   NoteHandle := FindWindow('Notepad','Notepad - SQLSCRCH.TXT');

If you don't know the class (the first parameter) you can replace it
with zero.

and just to finish it off, if you want to close it down then you can
use

   if NoteHandle <> 0 then
      wmret:=PostMessage(NoteHandle,WM_CLOSE,0,0);

=============================================
Sandy Cooper             Software Specialists
MOSSL                    Aberdeen
==============================================

Other Threads