Install a Service Programmatically ?

  • Thread starter Thread starter David Sworder
  • Start date Start date
D

David Sworder

Hi there,

I'm designing an application in C#. One of the files in my application
is "server.exe". This assembly listens for inbound connections and handles
various incoming requests. I want to give the user of my application the
option to allow server.exe to execute and handle requests even after the
user has logged off.

My plan is to ask the user "Would you like this service to continue
running after you log off?". If the user answers yes, I want to install
"server.exe" as a service. I've done this successfully in a manual way using
the 'installutil' .NET helper application, but my application will need to
do this in an automated way.

How can I accomplish this? Shall I shell out to a command prompt and
execute installutil against server.exe? Does the user need to be an
administrator of his machine? Can I be 100% certain that if the user has the
..NET framework installed that 'installutil' will be installed as well? If
so, how do I find it? Is there some sort of macro (i.e. %DOTNET_FOLDER% for
example) that will allow me to easily determine the dotnet folder where
'installutil' resides?

Is there any way to get server.exe to execute after a user has logged
off *other* than using a service? I'd appreciate any suggestions.
 
Hi David,

I surpose you already has added an installer component to your project ??

If so, you can use the AssemblyInstaller class in namespace
System.Configuration.Install to either install or uninstall your service.
If you want me to i can mail you an example

Soren
 
If so, you can use the AssemblyInstaller class in namespace
System.Configuration.Install to either install or uninstall your service.

Wow, how easy!... thanks!
 
Could you post it to the group?

Or at least post enough that we can go find it ourselves?

Thanks.
 
Back
Top