//This code should be inserted into your ProjectInstaller class’ code
public override void Install(IDictionary stateServer){ Microsoft.Win32.RegistryKey system, currentControlSet, services, service, config; //config is where I’ll be putting service-specific configuration(Parameters) try {
//Let the project installer do its job base.Install(stateServer);
//Open the HKEY_LOCAL_MACHINE\SYSTEM key system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(“System”); //Open CurrentControlSet
currentControlSet = system.OpenSubKey(“CurrentControlSet”);
//Go to the services key
services = currentControlSet.OpenSubKey(“Services”);
//Open the key for your service, and allow writing
service = services.OpenSubKey(this.serviceInstaller1.ServiceName, true);
//Add your service’s description as a REG_SZ value named “Description” service.SetValue(“Description”, “This is my service’s description.”);
//(Optional) Add some other information your service will be looking for…
config = service.CreateSubKey(“Parameters”);
}
catch(Exception e)
{
Console.WriteLine(“An exception was thrown during serviceinstallation:\n” + e.ToString()); }
} public override void Uninstall(IDictionary stateServer){ Microsoft.Win32.RegistryKey system, currentControlSet, services, service; try { //Drill down to the service key and open it with write permission system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(“System”); currentControlSet = system.OpenSubKey(“CurrentControlSet”);
services = currentControlSet.OpenSubKey(“Services”);
service = services.OpenSubKey(this.serviceInstaller1.ServiceName, true);
//Delete any keys you created during installation (or that your servicecreated) service.DeleteSubKeyTree(“Parameters”);
//…
}
catch(Exception e)
{
Console.WriteLine(“Exception encountered while uninstalling service:\n”+ e.ToString());
}
finally {
//Let the project installer do its job
base.Uninstall(stateServer);
}
}