Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private System.ServiceProcess.ServiceInstaller serviceInstaller =
- new System.ServiceProcess.ServiceInstaller();
- this.serviceInstaller.Description = "Handles Service Stuff";
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Configuration.Install;
- using System.ServiceProcess;
- using Microsoft.Win32;
- namespace SomeService
- {
- [RunInstaller(true)]
- public partial class ProjectInstaller : System.Configuration.Install.Installer
- {
- public ProjectInstaller()
- {
- InitializeComponent();
- }
- /// <summary>
- /// Overriden to get more control over service installation.
- /// </summary>
- /// <param name="stateServer"></param>
- public override void Install(IDictionary stateServer)
- {
- RegistryKey system;
- //HKEY_LOCAL_MACHINEServicesCurrentControlSet
- RegistryKey currentControlSet;
- //...Services
- RegistryKey services;
- //...<Service Name>
- RegistryKey service;
- // ...Parameters - this is where you can put service-specific configuration
- // Microsoft.Win32.RegistryKey config;
- try
- {
- //Let the project installer do its job
- base.Install(stateServer);
- //Open the HKEY_LOCAL_MACHINESYSTEM key
- system = 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("MyService", true);
- //Add your service's description as a REG_SZ value named "Description"
- service.SetValue("Description", "A service that does so and so");
- //(Optional) Add some custom information your service will use...
- // config = service.CreateSubKey("Parameters");
- }
- catch (Exception e)
- {
- throw new Exception(e.Message + "n" + e.StackTrace);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment