После создания проекта установки службы в VS2010 необходимо добавить переопределение метода Install в классе, созданном VS, чтобы создать запись реестра для описания службы.
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_MACHINE\Services\CurrentControlSet
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_MACHINE\SYSTEM 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);
}
}
}
}
http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.aspx
http://www.codeproject.com/KB/dotnet/dotnetscmdescription.aspx