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