By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Getting the handle of a running service.

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.