ServiceController.DisplayName Property

Definition

Gets or sets a friendly name for the service.

C#
public string DisplayName { get; set; }
C#
public string DisplayName { get; }
C#
[System.ServiceProcess.ServiceProcessDescription("SPDisplayName")]
public string DisplayName { get; set; }

Property Value

The friendly name of the service, which can be used to identify the service.

Attributes

Exceptions

An error occurred when accessing a system API.

The service was not found.

Examples

The following example uses the ServiceController class to display the set of services that are dependent on the Event Log service.

C#

ServiceController sc =  new ServiceController("Event Log");
ServiceController[] scServices = sc.DependentServices;

// Display the list of services dependent on the Event Log service.
if (scServices.Length == 0)
{
   Console.WriteLine("There are no services dependent on {0}",
                      sc.ServiceName);
}
else
{
   Console.WriteLine("Services dependent on {0}:",
                      sc.ServiceName);

   foreach (ServiceController scTemp in scServices)
   {
      Console.WriteLine(" {0}", scTemp.DisplayName);
   }
}

Remarks

You can set the DisplayName to an empty string (""), but setting the property to null throws an exception.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)