Installing a Service Programmatically
Author Date Of Submission User Level
Sachin Nigam 09/04/2003 Intermediate
 
 
With the arrival of .Net, creation of a windows service has become a piece of cake by just selecting Windows Service as project type in the New Project Dialog Box. For installing a service, .Net provides a utility called installutil.exe which installs the service and registers it with Service Control Manager(SCM) but at times there is a need to install the service programmatically for example as a part of your custom installer program where you don't want your user to manually install the service using installutil.
The following piece of code shows how to install/uninstall a given service and register it with SCM calling appropriate APIs using P/Invoke in C#

 
SERVICEINSTALLER.CS
 

Installing a Service Programmaticallyusing System;
Installing a Service Programmatically
using System.Runtime.InteropServices;
Installing a Service Programmatically 
Installing a Service Programmatically
namespace SvcInstaller

 

The above code shows that installing a service programmatically is as simple if not simpler than using installutil and gives you far more flexibility.

相关文章: