473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 1834
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Niederberger | last post by:
Hi I've written a Windows Service which has - several (0-100) listeners threads which spawn worker threads based on events, timers etc - several (0-300) worker threads which handle data...
1
by: Tom J | last post by:
What do I have to do to get System.ServiceProcess.ServiceController.ExecuteCommand(int) to work? I have written a service that overrides OnCustomCommand to handle commands sent to it. If I...
2
by: David Hearn | last post by:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of the current...
5
by: MrBewsher | last post by:
Hi, I'm using VB.Net and writing an NT service that runs in the system account in the background with no interaction with the desktop. I'm running it on XP Pro. I'd like to get the URL of...
3
by: Grant Schenck | last post by:
Hello, I have a Windows Service developed in C# .NET. I'm making it a remote server and I can, via an IPC Channel, expose methods and call them from a client. However, I now want my remoted...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
0
by: monishch | last post by:
Hi!, I am developing a windows service using vb.net in VB 2005.Through the service I am trying to run a exe.While starting service I am getting the following error: ...
2
by: siddharthkhare | last post by:
Hi All, I am launching a IE using following code. ======================================================================= m_IeProcess = new Process(); m_IeProcess.StartInfo.WindowStyle =...
0
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I have WCF service and integrated with STS (WS-Federation). The Service exposes 5 endpoints Win, UNT and Federated Windows, Federated UNT and Mex endpoint. My STS Service exposes 3 endpoints...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.