Edit

Share via


ServiceBase.ServiceName Property

Definition

Gets or sets the short name used to identify the service to the system.

public:
 property System::String ^ ServiceName { System::String ^ get(); void set(System::String ^ value); };
public string ServiceName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ServiceProcess.ServiceProcessDescription("SBServiceName")]
public string ServiceName { get; set; }
[System.ServiceProcess.ServiceProcessDescription("SBServiceName")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ServiceName { get; set; }
[System.ServiceProcess.ServiceProcessDescription("SBServiceName")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ServiceName { get; set; }
member this.ServiceName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
[<System.ServiceProcess.ServiceProcessDescription("SBServiceName")>]
member this.ServiceName : string with get, set
[<System.ServiceProcess.ServiceProcessDescription("SBServiceName")>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ServiceName : string with get, set
[<System.ServiceProcess.ServiceProcessDescription("SBServiceName")>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ServiceName : string with get, set
Public Property ServiceName As String

Property Value

The name of the service.

Attributes

Exceptions

The service has already been started. The ServiceName property cannot be changed once the service has started.

The specified name is a zero-length string or is longer than MaxNameLength, or the specified name contains forward slash or backslash characters.

Remarks

The ServiceName identifies the service to the Service Control Manager. The value of this property must be identical to the name recorded for the service in the ServiceInstaller.ServiceName property of the corresponding installer class. In code, the ServiceName of the service is usually set in the main() function of the executable.

The ServiceName is also used to specify the EventLog.Source associated with the EventLog property. This EventLog is an instance that writes service command information to the Application log.

The ServiceName, which supplies the source string for the event log, must be set before the service writes to the event log. Trying to access the event log before the source name is set causes an exception to be thrown.

Applies to

See also