ServiceInstaller.ServiceName 屬性


表示系統用來識別此服務的名稱。Indicates the name used by the system to identify this service. 這個屬性必須與您想要安裝之服務的 ServiceName 相同。This property must be identical to the ServiceName of the service you want to install.

 property System::String ^ ServiceName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[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=, 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 to be installed. 這個值必須在安裝公用程式嘗試安裝服務之前設定。This value must be set before the install utility attempts to install the service.



ServiceName 屬性為無效。The ServiceName property is invalid.


請務必與衍生自ServiceBase之類別的相同ServiceBase.ServiceNameServiceNameIt is crucial that the ServiceName be identical to the ServiceBase.ServiceName of the class you derived from ServiceBase. 一般來說, 服務的ServiceBase.ServiceName屬性值會在服務應用程式可執行檔的 Main () 函式內設定。Normally, the value of the ServiceBase.ServiceName property for the service is set within the Main() function of the service application's executable. 服務控制管理員會使用ServiceInstaller.ServiceName屬性來尋找此可執行檔內的服務。The Service Control Manager uses the ServiceInstaller.ServiceName property to locate the service within this executable.

當您設定ServiceName服務安裝程式的時, 相關Source聯事件記錄檔的會設定為相同的值。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.


如果電腦上已有相同名稱的來源存在, 但在應用程式記錄檔以外的記錄中, 則會擲回例外狀況。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.

不能是null或長度為零。 ServiceNameThe ServiceName cannot be null or have zero length. 其大小上限為256個字元。Its maximum size is 256 characters. 它也不能包含正斜線或反斜線、'/'\或 ' ', 或 ASCII 字元集中值小於十進位值32的字元。It also cannot contain forward or backward slashes, '/' or '\', or characters from the ASCII character set with value less than decimal value 32.