ServiceController Constructors

Definition

Initializes a new instance of the ServiceController class.

Overloads

ServiceController()

Initializes a new instance of the ServiceController class that is not associated with a specific service.

ServiceController(String)

Initializes a new instance of the ServiceController class that is associated with an existing service on the local computer.

ServiceController(String, String)

Initializes a new instance of the ServiceController class that is associated with an existing service on the specified computer.

ServiceController()

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Initializes a new instance of the ServiceController class that is not associated with a specific service.

C#
public ServiceController();

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

ServiceController(String)

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Initializes a new instance of the ServiceController class that is associated with an existing service on the local computer.

C#
public ServiceController(string name);

Parameters

name
String

The name that identifies the service to the system. This can also be the display name for the service.

Exceptions

name is invalid.

Examples

The following example demonstrates the use of the ServiceController.ServiceController(String) constructor to create a ServiceController object that is used to control a sample service. This example is part of a larger example that is provided for the ServiceController class.

C#
// Display properties for the Simple Service sample
// from the ServiceBase example.
ServiceController sc = new ServiceController("Simple Service");
Console.WriteLine("Status = " + sc.Status);
Console.WriteLine("Can Pause and Continue = " + sc.CanPauseAndContinue);
Console.WriteLine("Can ShutDown = " + sc.CanShutdown);
Console.WriteLine("Can Stop = " + sc.CanStop);

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

ServiceController(String, String)

Source:
ServiceController.cs
Source:
ServiceController.cs
Source:
ServiceController.cs

Initializes a new instance of the ServiceController class that is associated with an existing service on the specified computer.

C#
public ServiceController(string name, string machineName);

Parameters

name
String

The name that identifies the service to the system. This can also be the display name for the service.

machineName
String

The computer on which the service resides.

Exceptions

name is invalid.

-or-

machineName is invalid.

Remarks

For the machineName parameter, you can use "." to represent the local computer.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)