Learn how to a build a cloud-first strategyRegister Now


Obtain an instance of a windows service in .NET

Posted on 2004-11-05
Medium Priority
Last Modified: 2010-04-17
I wrote a windows service using c#.  It communicates with my application using .net remoting.  I can obtain an instance of my service using .net remoting, however using the methods is too much slower than doing the method within the application.

Is there a way to obtain an instance of the service so I can execute its methods directly?  I know I can get a ServiceController object based on the service name.  Is there a way for my application to get the instance itself, so that I can execute

Or is remoting the only way?
Question by:lynx2sw1
  • 2
LVL 22

Expert Comment

ID: 12511141
Modify the service to respond to custom messages and use ControlService() to pass them:


Author Comment

ID: 12511467
I had thought those custom message parameters were only integers, without a control value.  I want to pass in other things than intts, a

I am coding in C#.  But I followed your link and it gave me the idea to try to use kernal32 in my c#.  
[DllImport("advapi32.dll", EntryPoint="OpenService")] public static extern int OpenServiceA(int hSCManager, string lpServiceName, int dwDesiredAccess)
LVL 22

Accepted Solution

cookre earned 500 total points
ID: 12511571
Well, yes, you have to use OpenService() to get a handle to the service to tell ControlService() which service's control handler to send the message to.  The value of the message would tell the service which method to call.

Perhaps you could use object serialization for passing data.  If you don't have too many object types to pass, the custom control code could be used to specify both method and object.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question