Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

SetServiceDescription

0.00/5 (No votes)
14 Jan 2008 1  
A method for setting the description of a Windows Service.

Introduction

When you create a Windows Service by deriving from System.ServiceProcess.ServiceBase, you can set various properties of the service, but not the value that gets displayed in the "Description" column of the "Computer Management" screen. This is how to set it by using the Windows API rather than mucking about in the registry.

How It's Done

The Windows API provides several methods for working with the Service Control Manager; these are documented here.

The source code included with this article does the following:

  • Calls OpenSCManager to connect to the service control manager
  • Calls OpenService to connect to the requested service
  • Calls ChangeServiceConfig2w to set the description (this is the Unicode version of the function)
  • Calls CloseServiceHandle to close the service and service control manager

Using the Code

Add the included file to your project.

In classes that derive from System.ServiceProcess.ServiceBase, add something like the following:

public void AfterInstallEventHandler
    (object sender, System.Configuration.Install.InstallEventArgs e)
{
    SetServiceDescription ( ServiceName , "This is my service" ) ;
}

In classes that derive from System.Configuration.Install.Installer, after instantiating each System.ServiceProcess.ServiceInstaller, add something like the following:

serviceInstaller.AfterInstall += new System.Configuration.Install.InstallEventHandler
    ( myservice.AfterInstallEventHandler ) ;

History

  • 2006-06-03: First posted
  • 2008-01-07: Updated

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here