ServiceBase.ServiceName 屬性

定義

取得或設定用來識別系統服務的簡短名稱。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); };
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ServiceProcess.ServiceProcessDescription("SBServiceName")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ServiceName { get; set; }
member this.ServiceName : string with get, set
Public Property ServiceName As String

屬性值

服務的名稱。The name of the service.

屬性

例外狀況

已經啟動服務。The service has already been started. 一旦已經啟動服務,就無法變更 ServiceName 屬性。The ServiceName property cannot be changed once the service has started.

指定的名稱是零長度字串或比 MaxNameLength 更長,或者指定的名稱包含斜線或反斜線字元。The specified name is a zero-length string or is longer than MaxNameLength, or the specified name contains forward slash or backslash characters.

備註

會向服務控制管理員識別服務。ServiceNameThe ServiceName identifies the service to the Service Control Manager. 這個屬性的值必須與對應之安裝程式類別的ServiceInstaller.ServiceName屬性中為服務所記錄的名稱相同。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. 在程式碼中ServiceName ,服務的通常是main()在可執行檔的功能中設定。In code, the ServiceName of the service is usually set in the main() function of the executable.

也會用來指定與EventLog屬性相關聯的EventLog.SourceServiceNameThe ServiceName is also used to specify the EventLog.Source associated with the EventLog property. EventLog是將服務命令資訊寫入應用程式記錄檔的實例。This EventLog is an instance that writes service command information to the Application log.

提供ServiceName事件記錄檔之來源字串的必須在服務寫入事件記錄檔之前設定。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.

適用於

另請參閱