Windows Service name/description
-
Hi all, Does anybody know how to set a windows service description? The serverinstaller component's Displayname property maps to the Service Name in the Services MMC snap-in. The Description in the MMC is empty. I can't find any property that maps to this description. Thanks, Peter
-
Hi all, Does anybody know how to set a windows service description? The serverinstaller component's Displayname property maps to the Service Name in the Services MMC snap-in. The Description in the MMC is empty. I can't find any property that maps to this description. Thanks, Peter
Since the
ServiceInstaller
doesn't define such a property, you have to write it to the registry yourself. The easiest way is, in yourInstaller
derivative (the class that references theServiceInstaller
andServiceProcessInstaller
), overrideInstall
(andUninstall
with code to remove the key) like so:public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
using (RegistryKey key = Registry.LocalMachine.OpenSubkey(
@"SYSTEM\CurrentControlSet\Services\" + serviceInstaller1.ServiceName))
{
if (key != null)
key.SetValue("Description", description);
}
}
string description;
public string Description
{
get { return description; }
set { description = value; }
}You wouldn't have to define it as a property, but it makes for a good design. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]
-
Since the
ServiceInstaller
doesn't define such a property, you have to write it to the registry yourself. The easiest way is, in yourInstaller
derivative (the class that references theServiceInstaller
andServiceProcessInstaller
), overrideInstall
(andUninstall
with code to remove the key) like so:public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
using (RegistryKey key = Registry.LocalMachine.OpenSubkey(
@"SYSTEM\CurrentControlSet\Services\" + serviceInstaller1.ServiceName))
{
if (key != null)
key.SetValue("Description", description);
}
}
string description;
public string Description
{
get { return description; }
set { description = value; }
}You wouldn't have to define it as a property, but it makes for a good design. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]
Fot those interrested, Heath's hint returns a read-only reference to the registry key. Few bytes changed and it works:
public override void Install(IDictionary stateSaver) { this.Description = "Blah blah."; base.Install(stateSaver); string p = @"SYSTEM\CurrentControlSet\Services\" + serviceInstaller1.ServiceName; RegistryKey key = Registry.LocalMachine.OpenSubKey(p,true); { if (key != null) key.SetValue("Description", description); } }
Ciao and thanks for your help Heath! Peter