This documentation is archived and is not being maintained.

ServiceBase.ServiceName Property

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

[Visual Basic]
Public Property ServiceName As String
public string ServiceName {get; set;}
public: __property String* get_ServiceName();
public: __property void set_ServiceName(String*);
public function get ServiceName() : String;
public function set ServiceName(String);

Property Value

The name of the service.


Exception Type Condition
InvalidOperationException The service has already been started. The ServiceName property cannot be changed once the service has started.
ArgumentException The ServiceName property is invalid.


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.


Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

ServiceBase Class | ServiceBase Members | System.ServiceProcess Namespace | ServiceInstaller.ServiceName | EventLog.Source