Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Handle of Running App

16 views
Skip to first unread message

Bikash

unread,
Apr 4, 2000, 3:00:00 AM4/4/00
to
Hi Everbody,

Is there any way to get the handle of a running executable ?

for e.g

long ll_hanlde
ll_handle = some_func("c:\test.exe") ....

Regards
Bikash

Boris Gasin [TeamSybase]

unread,
Apr 4, 2000, 3:00:00 AM4/4/00
to
On Tue, 4 Apr 2000 15:48:26 -0500, "Bikash"
<bikashprasa...@ushacomm.co.in> wrote:

>Is there any way to get the handle of a running executable ?
>
>for e.g
>
>long ll_hanlde
>ll_handle = some_func("c:\test.exe") ....
>

Bikash,

From within the same executable or from another app?

Why?


--
Boris Gasin [TeamSybase]
mailto:bga...@dynamictechgroup.com

Vote for your favorite tools!
http://www.sys-con.com/java/readerschoice2000/

Mine are:
- Sybase Enterprise Application Server
- PowerJ
- Sybase Adaptive Server Anywhere
- Power Designer V7

Bikash

unread,
Apr 4, 2000, 3:00:00 AM4/4/00
to
Hi Boris,

From another application ?

TIA
Bikash

Boris Gasin [TeamSybase] <NOSPAM...@dynamictechgroup.com> wrote in
message news:gGLqOC2m8wZJsLW2=f+x3U...@4ax.com...

Paul Horan

unread,
Apr 4, 2000, 3:00:00 AM4/4/00
to
You can get a handle to the main window of the application by using the
FindWindowA() API call.

Once you have a handle to the main window of an application, you can use the
Send() function to send it messages. We use this technique for
inter-application communication btw PB apps, and it works fine.

Paul Horan
VCI www.twoplus.com
Springfield, MA

"Bikash" <bikashprasa...@ushacomm.co.in> wrote in message
news:Jjs4Mgnn$GA....@forums.sybase.com...
> Hi Everbody,


>
> Is there any way to get the handle of a running executable ?
>
> for e.g
>
> long ll_hanlde
> ll_handle = some_func("c:\test.exe") ....
>

> Regards
> Bikash
>
>

Boris Gasin [TeamSybase]

unread,
Apr 5, 2000, 3:00:00 AM4/5/00
to
On Tue, 4 Apr 2000 17:39:43 -0500, "Bikash"
<bikashprasa...@ushacomm.co.in> wrote:

>Hi Boris,
>
>From another application ?

You can get a handle to the main window using the FindWindow API call:
Function ulong FindWindowA( ref string lpClassName, ref string
lpWindowName) Library "USER32.DLL"

FX Liagre

unread,
Apr 5, 2000, 3:00:00 AM4/5/00
to
HI everybody

And what if the App is a non-visual one (typically, an NT service) ?

FX LIAGRE

francois-xa...@lusis.fr
fxli...@hotmail.com

Boris Gasin [TeamSybase] a écrit dans le message ...

Roy Kiesler [TeamSybase]

unread,
Apr 5, 2000, 3:00:00 AM4/5/00
to
Check the following URL: http://puterwerks.hypermart.net/processes.html

--
pbm_hopethishelps,
Roy Kiesler [TeamSybase]
Sybase Developers Network (SDN) - http:///www.sybase.com/sdn

"FX Liagre" <francois-xa...@lusis.fr> wrote in message
news:XIEYEqsn$GA...@forums.sybase.com...

Bikash

unread,
Apr 5, 2000, 3:00:00 AM4/5/00
to
How to do inter application communication using a user defined message and
send(). Can you help me out I am not able to do it.

I am using WM_COMMAND but you it has an overhead.So how to define
user defined message and use it.

Thanks in advance
Bikash

Paul Horan <pa...@SpamBakedBeansandSpamTwoplus.com> wrote in message
news:dYcRO3pn$GA....@forums.sybase.com...

FX Liagre

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Tanks for the url, Roy. BTW... do you know the NT4 corresponding APIs ?...
(my customer has about 600 NT4 servers, and I'm not sure I can convince him
to migrate them before the end of the month !!!)

FX Liagre

Roy Kiesler [TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
The APIs used in the link I provided are valid for all Win32 platforms.

--
pbm_hopethishelps,
Roy Kiesler [TeamSybase]
Sybase Developers Network (SDN) - http:///www.sybase.com/sdn

"FX Liagre" <francois-xa...@lusis.fr> wrote in message

news:2RwcpH5n$GA....@forums.sybase.com...

FX Liagre

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
I'm afraid, it's not true : when I try to use the source provided into the
link, it crashes saying "error calling external function
CreateToolHelp32SnapShot"

And the html page does say that the kernel function are valid for win98 and
2000, but not for NT4...
Roy Kiesler [TeamSybase] a écrit dans le message ...

Roy Kiesler [TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
I stand corrected -- the NT API would be EnumProcesses, exported out of
psapi.dll. This function will populate an array of ulong as process IDs. To
get the process handles, you will have to call OpenProcess for each pid in
the array.

--
pbm_hopethishelps,
Roy Kiesler [TeamSybase]
Sybase Developers Network (SDN) - http:///www.sybase.com/sdn

"FX Liagre" <francois-xa...@lusis.fr> wrote in message

news:w5AsKm9n$GA....@forums.sybase.com...

Bill Green[TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Look at the RegisterWindowsMessage() API function. It will let you register a
user-defined message in an application and then when that message is published
by another application, it will be routed to the registered app. (See
component attached - PB7)

regards,
Bill

Bikash wrote:

--
Bill Green[TeamSybase]

-----------------------------------------------------------
Good Links to know, good places to go:

Sybase Developer Network (SDN) - http://www.sybase.com/sdn
Find things like:
-- Print to PDF component
-- Lotus Notes E-Mail component
-- Taking existing PB apps to the web white paper

PFC Guide - http://www.pfcguide.com
Power3 - Custom Training - http://www.power3.com
-----------------------------------------------------------

p3_Util_InterAppComms.pbl

Roy Kiesler [TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Nifty little API -- I use it to trap a crash in explorer to restore the
tray icon of my app as soon as explorer is back up.

--
pbm_hopethishelps,
Roy Kiesler [TeamSybase]
Sybase Developers Network (SDN) - http:///www.sybase.com/sdn

"Bill Green[TeamSybase]" <bill....@teamsybase.com> wrote in message
news:38ECB2F2...@teamsybase.com...

Bill Green[TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Cool. What message number are you catching?

I used it to create a remote logging app - Can capture performance data
without including everything in the existing app.


Bill

Roy Kiesler [TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Assuming you have IE4.0 or later, the shell notifies applications that the
taskbar has been created. When the taskbar is created, it registers a
message with the "TaskbarCreated" string and then broadcasts this message to
all top-level windows. When your taskbar application receives this message,
it should assume that any taskbar icons it added have been removed and add
them again.

// Global variable
uint gui_TaskbarRestart = RegisterWindowMessage( "TaskbarCreated" )

// Other event on window that implements tray icon functionality
IF Message.Number = gui_TaskbarRestart THEN
inv_shell.of_AddToSysTray( "ToolTip Text Here" )
END IF

--
pbm_hopethishelps,
Roy Kiesler [TeamSybase]
Sybase Developers Network (SDN) - http:///www.sybase.com/sdn

"Bill Green[TeamSybase]" <bill....@teamsybase.com> wrote in message

news:38ECCE08...@teamsybase.com...

Bill Green[TeamSybase]

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Great!! Thanks Roy.

FX Liagre

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
I tried to use theses PAI and... it seems to work. I write "seems", because
I can only retrieve the names of "application modules". For example, when I
tried to use the window (exported source under this message), I only recover
this list
* PB060.exe
* explorer.exe
* hh.exe
* systray.exe
* nddeagnt.exe

... but nothing about services ! Can you help me to understand what I
missed !

Thanks in advance

/* Source of the test window here */
$PBExportHeader$w_processes.srw
forward
global type w_processes from Window
end type
type lb_processes from listbox within w_processes
end type
type cb_ok from commandbutton within w_processes
end type
end forward

type processentry from structure
unsignedlong lpidprocess[500]
end type

type moduleentry from structure
unsignedlong lpidmodule[100]
end type

global type w_processes from Window
int X=1056
int Y=484
int Width=2043
int Height=856
boolean TitleBar=true
string Title="List of Current Processes:"
long BackColor=78682240
boolean ControlMenu=true
boolean MinBox=true
boolean MaxBox=true
boolean Resizable=true
lb_processes lb_processes
cb_ok cb_ok
end type
global w_processes w_processes

type prototypes
Function boolean CloseHandle (ref ulong hObject) Library "KERNEL32.DLL"
Function Boolean EnumProcesses(REF processEntry Process, long cb, REF long
cbNeeded ) Library "PSAPI.DLL"
Function long OpenProcess( long dwDesiredAccess, boolean bInheritHandle,
ulong dwProcessId) LIBRARY "KERNEL32.DLL"
Function boolean EnumProcessModules( ulong hProcess, REF ModuleEntry Module
, long cb, REF long lpcbNeeded ) LIBRARY "PSAPI.DLL"
Function long GetModuleBaseNameA(ulong hProcess, ulong hModule, REF string
lpBaseName,long nSize) LIBRARY "PSAPI.DLL"
Function long GetModuleFileNameExA(ulong hProcess, ulong hModule, REF string
lpBaseName,long nSize) LIBRARY "PSAPI.DLL"
end prototypes

type variables
constant ulong PROCESS_ALL_ACCESS = 2035711
end variables

on w_processes.create
this.lb_processes=create lb_processes
this.cb_ok=create cb_ok
this.Control[]={this.lb_processes,&
this.cb_ok}
end on

on w_processes.destroy
destroy(this.lb_processes)
destroy(this.cb_ok)
end on

event open;ProcessEntry Process // Window structure (array of 500 ulong)...
arbitrary value !
ModuleEntry Module // Window structure (array of 100 long)... idem
long tailleP=2000 // Size of Process
long TailleM=400 // Size of Module
long NeededP // returned size of Process
long NeededM // returned size of Module
long resName // size of returned name of the module
long ifx // for looping through processes
ulong HandleP // Handle of the process
boolean resultP, resultM // return codes for EnumProcesses and
EnumProcessModules
string name // Name of the module

resultP=EnumProcesses(Process,TailleP,NeededP)
if resultP=true then
for ifx=1 to integer(NeededP / 4)
HandleP = OpenProcess(PROCESS_ALL_ACCESS,false,Process.lpIdProcess[iFX])
resultM = EnumProcessModules(HandleP, Module, TailleM, NeededM)
if NeededM >= 4 then
Name=space(254)
resName=GetModuleFileNameExA(handleP, Module.lpidmodule[1], name ,254)
if resName>0 then
lb_processes.AddItem(name)
end if
end if
CloseHandle(HandleP)
next
else
lb_processes.AddItem ("Fail calling EnumProcesses")
end if


end event
type lb_processes from listbox within w_processes
int X=32
int Y=32
int Width=1641
int Height=680
int TabOrder=20
BorderStyle BorderStyle=StyleLowered!
boolean HScrollBar=true
boolean VScrollBar=true
long TextColor=33554432
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

type cb_ok from commandbutton within w_processes
int X=1714
int Y=32
int Width=247
int Height=108
int TabOrder=10
string Text="Ok"
boolean Default=true
int TextSize=-10
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type

event clicked;close(parent)
end event

/* End of the source */

fxli...@hotmail.com
francois-xa...@lusis.fr

Roy Kiesler [TeamSybase] a écrit dans le message ...

>I stand corrected -- the NT API would be EnumProcesses, exported out of
>psapi.dll. This function will populate an array of ulong as process IDs. To
>get the process handles, you will have to call OpenProcess for each pid in
>the array.
>

Roy Kiesler [TeamSybase]

unread,
Apr 12, 2000, 3:00:00 AM4/12/00
to
Services are executables, and their module name will be listed. If what you
are after is their friendly display name, e.g. "IIS Admin Service" instead
of "iissrv.exe" or "Telephony Service" instead of "tapisrv.exe", then you
should use the OpenSCManager and EnumServicesStatus API functions.

For a review of all service related API functions, go to
http://msdn.microsoft.com/library/psdk/winbase/services_2uwj.htm

--
pbm_hopethishelps,
Roy Kiesler [TeamSybase]
Sybase Developers Network (SDN) - http:///www.sybase.com/sdn

"FX Liagre" <francois-xa...@lusis.fr> wrote in message
news:b9qtEhHp$GA....@forums.sybase.com...

0 new messages