編輯

共用方式為


ServiceInstaller.ServiceName Property

Definition

Indicates the name used by the system to identify this service. This property must be identical to the ServiceName of the service you want to install.

public:
 property System::String ^ ServiceName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ServiceName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ServiceProcess.ServiceProcessDescription("ServiceInstallerServiceName")]
public string ServiceName { get; set; }
[System.ServiceProcess.ServiceProcessDescription("ServiceInstallerServiceName")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ServiceName { get; set; }
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ServiceName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
[<System.ServiceProcess.ServiceProcessDescription("ServiceInstallerServiceName")>]
member this.ServiceName : string with get, set
[<System.ServiceProcess.ServiceProcessDescription("ServiceInstallerServiceName")>]
[<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 to be installed. This value must be set before the install utility attempts to install the service.

Attributes

Exceptions

The ServiceName property is invalid.

Remarks

It is crucial that the ServiceName be identical to the ServiceBase.ServiceName of the class you derived from ServiceBase. Normally, the value of the ServiceBase.ServiceName property for the service is set within the Main() function of the service application's executable. The Service Control Manager uses the ServiceInstaller.ServiceName property to locate the service within this executable.

When you set the ServiceName of the service installer, the Source of the associated event log is set to the same value. This allows the service to automatically log service commands (such as Start and Stop) calls to the Application log on the computer.

Note

If a source by the same name already exists on the computer, but in a log other than the Application log, an exception will be thrown. If the source exists and is associated with the Application log, that source is used to report command calls to the service, and no exception is thrown.

The ServiceName cannot be null or have zero length. Its maximum size is 256 characters. It also cannot contain forward or backward slashes, '/' or '\', or characters from the ASCII character set with value less than decimal value 32.

Applies to

See also