Add a description to the Windows service

Source: Internet
Author: User
Tags config win32
Window
Recently, a Windows service (Windows services) has been written, and after installation, it feels different from existing Windows services. Why? My lack of description, the middle column is empty.

Look again. NET ServiceBase class does not add a description of the attribute.

There are no attributes to add to the public class ProjectInstaller:System.Configuration.Install.Installer. After searching from the net to know to overload ProjectInstaller install and Uninstall virtual method. In fact, the purpose of rewriting these virtual methods is to add a key value "Description" to the corresponding service in the registry, and the value should be filled with the corresponding description.

public override void Install (IDictionary stateserver)
{
Microsoft.Win32.RegistryKey system,
Service
Config

Try
{
Let the project installer does its job
Base. Install (StateServer);
System = Microsoft.Win32.Registry.LocalMachine.OpenSubKey ("System"). OpenSubKey ("CurrentControlSet"). OpenSubKey ("Services");

Service = System. OpenSubKey (This.serviceInstaller1.ServiceName, true);

Service. SetValue ("Description", "service description");

Add extra keys
Config = service. CreateSubKey ("Additionalinformation");
}
catch (Exception e)
{

}
}
public override void Uninstall (IDictionary stateserver)
{
Microsoft.Win32.RegistryKey system,
CurrentControlSet,
Services
Service

Try
{
System = Microsoft.Win32.Registry.LocalMachine.OpenSubKey ("system");
CurrentControlSet = System. OpenSubKey ("CurrentControlSet");
Services = Currentcontrolset.opensubkey ("services");
Service = Services. OpenSubKey (This.serviceInstaller1.ServiceName, true);
Remove the extra keys
Service. Deletesubkeytree ("Additionalinformation");
//...
}
catch (Exception e)
{
}
Finally
{
Base. Uninstall (StateServer);
}
}

Note that the code is in the ProjectInstaller file.

Perhaps there is a better way, hope everyone advice.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.