Getting the handle of a running service.

P

Patrick Dugan

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?
 
T

Tom Shelton

Patrick said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top