Communicating with a Windows Service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Is it possible to have an application communicate with a Windows Service and make the windows service execute another application based on the parameters passed by the application to the windows service

Thanks.
 
H

It can be done using the OnCustomCommand method of the servicebase

Sooraj P
Microsoft India Community Star
 
Thank you Sooraj for your post

Can this be done remotely; meaning, is it possible to have a windows service, being controlled remotely from another machine?
 
This interface only permits a custom command code (a number) to be passed
from a managing .Net application (may be another service) to a running
service -- this does not permit any transfer of data or information. Is .Net
remoting the only mechanism available to achieve this in the .Net manner? I
know that named pipes can be created and managed (we are using this approach
to permit existing services written in C++ 6 to communicate with a new .Net
service), but the only viable alternative I see in .Net is the use of
remoted interfaces.

-Ken
 
Ken

Could you give me an example on how to use remoted interfaces? Or if you could give me links to articles on remoted interfaces, it will be nice

Thanks
 
Let me explain the scenario, I am dealing with

I want to pass numbers to the service, and in the OnCustomCommand event of the service, I would write desired code for each number value

I would have a user interface on the server, which would allow me to connect to the client. Based on the menu option, I would like to pass parameters from the server to the client. On connection, I would like to programatically, execute the controlling application (which would accept the parameters passed). I would write code in the OnCustomcommand; based on the numbers, I would execute different applications. How can this be done?
 
There are some resources available online, but they require a certain degree
of scatter/gather research to determine the approach that is right for you
(there are a number of variations). Wathc for line breaks in these links.

These are introductory links that are actually quite good:
http://www.developer.com/net/cplus/article.php/1479761
http://www.developer.com/services/article.php/2201701

This another introductory overview:
http://www.dotnetjohn.com/articles/articleid84.aspx

And this is one more:
http://www.rick-ross.com/papers/borcon2003/1207.html

And this is one more:
http://www.c-sharpcenter.com/csnet/remoting/remoting.asp

Microsoft also has their own overview:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconnetremotingoverview.asp

There is also a specific example of using remoting at this link:
http://www.codeproject.com/dotnet/clipsend.asp

One of the better books that I have read on this topic is "Advanced .Net
Remoting C# Edition" by Ingo Rammer (ISBN: 1-59059-025-2).

Hope this helps!

-ken

Wilma said:
Ken,

Could you give me an example on how to use remoted interfaces? Or if you
could give me links to articles on remoted interfaces, it will be nice.
 
Wilma said:
Let me explain the scenario, I am dealing with.

I want to pass numbers to the service, and in the OnCustomCommand
event of the service, I would write desired code for each number
value.

I would have a user interface on the server, which would allow me to
connect to the client. Based on the menu option, I would like to pass
parameters from the server to the client. On connection, I would like
to programatically, execute the controlling application (which would
accept the parameters passed). I would write code in the
OnCustomcommand; based on the numbers, I would execute different
applications. How can this be done?

First, if you want to communicate between a process and a service you should
use an interprocess communication mechanism. .NET provides web services,
sockets and .NET remoting. OnCustomCommand is really part of the
communications mechanism used by the service control manager, its very
basic.

Let me caution you about writing a service. The whole point about services
is that they are used to extend the operating system, and to be honest I was
a little wary about the classes in .NET because I think it should be
*difficult* to extend the operating system to prevent novices doing it. The
two main reasons for writing a service is having a process start
automatically when the system starts, and to be able to run at elevated
security. If you do not need either of these, then just write a normal
process and avoid services. The dangerous bit is the 'elevated' security.
The general principal that everyone should follow is to run under the lowest
possible privileges, however, a service can be run under LOCALSYSTEM which
is the highest privileged account on your XP machine! Think of the damage
your process could do!

You said that you'll want to use the service to start other processes.
Again, there is a problem here. The default action of the Win32
CreateProcess (which is wrapped up by .NET) is to create the new process
under the same security token. Thus if your service is running under
LOCALSYSTEM then so will the child process. Neither of these will be visible
to the interactive user, and although you can check a box to make them
visible, this is a kludge and you should *never* do it in production code.
Also, if you end up running all of your processes under the same account it
kind of makes you wonder what user accounts are for. If your process will be
run under your interactive user account, or some other lower priviledged
account, then you have to question if you *really* need a service.

Richard
 
Back
Top