Send a message to a Windoes services

  • Thread starter Thread starter George D. Lake
  • Start date Start date
G

George D. Lake

Hi,
I have a Windows Service in VB.NET and now I need to send a message to
it from a different PC. How can I do this in a very simple way? (No SQL or
other external way), I need to talk directly to the service.


Thanks.
George.
 
Hi,
I have a Windows Service in VB.NET and now I need to send a message to
it from a different PC. How can I do this in a very simple way? (No SQL or
other external way), I need to talk directly to the service.


Thanks.
George.

Well, there are a couple of things you can do... The first, and
probably simplist way is to make use of the ServiceController class.
You can get a reference to the service through the constructor:

Imports System.ServiceProcess

....

Dim controller As New ServiceController ("servicename", "machinename")

This will let you use the ExecuteCommand method on the service... The
limitation is that the command is an integer value only. So, if you
need to send additional parameters, you can't really use this method
(unless you can some how encode them into an integer)...

' exectue a custom command on the service
controller.ExecuteCommand (23)

If that won't work for you... There is always Sockets and Remoting as
alternatives.
 
Tom,

This will work, all I need to do it to manually trigger an event, so I
can send a 1 and that will do the trick

So, on the client side I would do what you said, but on the service
side? How do I capture that command?

Thanks.
George.
 
Tom,

This will work, all I need to do it to manually trigger an event, so I
can send a 1 and that will do the trick

So, on the client side I would do what you said, but on the service
side? How do I capture that command?

Thanks.
George.

In your service class, you would override your services OnCustomCommand
method...

Protected Override Sub OnCustomCommand (ByVal command As Integer)

HTH
 
Thanks....
Now I have a permissions problem.

I need to impersonate form the client, the domain user that is running that
service.
I have done that in ASP.NET but I gant get it to work in win forms.
 

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

Back
Top