468,738 Members | 1,750 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

Getting the handle of a running service.

Is it possible to get the handle of a running service? I have a program
(ActiveX program) running in memory.
When I start my service I need to pass the service's handle to that program
in order to attach to it.

I cannot use Me.Handle because there is no such information within a service
application.
I have tried this small routine:
Dim PID1 As Integer
Dim PID2 As Integer
Dim proc As Process
Dim processes() As Process
processes = Diagnostics.Process.GetProcessesByName("MyService" )
For Each proc In processes
PID1 = proc.Handle.ToInt32
PID2 = proc.MainWindowHandle.ToInt32
Next
If I loop through that routine both PID1 and PID2 give constantly changing
values. I thought the handle for the process
would always be the same. How can I get the correct handle of this service
so I can pass that
to another program?

Nov 21 '05 #1
1 1584
Patrick Dugan wrote:
Is it possible to get the handle of a running service? I have a program
(ActiveX program) running in memory.
When I start my service I need to pass the service's handle to that program
in order to attach to it.

I cannot use Me.Handle because there is no such information within a service
application.
I have tried this small routine:
Dim PID1 As Integer
Dim PID2 As Integer
Dim proc As Process
Dim processes() As Process
processes = Diagnostics.Process.GetProcessesByName("MyService" )
For Each proc In processes
PID1 = proc.Handle.ToInt32
PID2 = proc.MainWindowHandle.ToInt32
Next
If I loop through that routine both PID1 and PID2 give constantly changing
values. I thought the handle for the process
would always be the same. How can I get the correct handle of this service
so I can pass that
to another program?



I'm a little confused as to what your trying to do... But, you can get
the system process handle from Process class.

Dim procId As Integer = Process.GetCurrentProcess ().Id

Console.WriteLine (procId)

HTH

--
Tom Shelton [MVP]
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Simon Niederberger | last post: by
3 posts views Thread by Grant Schenck | last post: by
33 posts views Thread by JamesB | last post: by
2 posts views Thread by siddharthkhare | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.