Επεξεργασία

Κοινή χρήση μέσω


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
Source:
ServiceController.cs
Source:
ServiceController.cs

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

public:
 ServiceController();
public ServiceController ();
Public Sub New ()

Applies to

ServiceController(String)

Source:
ServiceController.cs
Source:
ServiceController.cs
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.

public:
 ServiceController(System::String ^ name);
public ServiceController (string name);
new System.ServiceProcess.ServiceController : string -> System.ServiceProcess.ServiceController
Public Sub New (name As String)

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.

// 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);
' Display properties for the Simple Service sample 
' from the ServiceBase example
Dim sc As New ServiceController("Simple Service")
Console.WriteLine("Status = " + sc.Status.ToString())
Console.WriteLine("Can Pause and Continue = " + _
    sc.CanPauseAndContinue.ToString())
Console.WriteLine("Can ShutDown = " + sc.CanShutdown.ToString())
Console.WriteLine("Can Stop = " + sc.CanStop.ToString())

Applies to

ServiceController(String, String)

Source:
ServiceController.cs
Source:
ServiceController.cs
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.

public:
 ServiceController(System::String ^ name, System::String ^ machineName);
public ServiceController (string name, string machineName);
new System.ServiceProcess.ServiceController : string * string -> System.ServiceProcess.ServiceController
Public Sub New (name As String, machineName As String)

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