The ServiceController class of the System.ServiceProcess namespace enables you to programmatically control Windows services from your programs. Table 7.5 lists some important methods and properties of this class.
Table 7.5. Important Members of the ServiceController Class
Member | Type | Description |
---|
CanPauseAndContinue | Property | A value of true indicates that the service can be paused and resumed. |
CanShutdown | Property | A value of true indicates that the service should be notified when the system is shutting down. |
CanStop | Property | A value of true indicates that the service can be stopped after it has started. |
Close() | Method | Disconnects the ServiceController object from the Windows service. |
Continue() | Method | Continues a Windows service after it has been paused. |
DisplayName | Property | Specifies a friendly name for the service. |
ExecuteCommand() | Method | Executes a custom command on the service. |
GetServices() | Method | Retrieves the Windows services installed on a computer. |
MachineName | Property | Specifies the name of the computer on which this service resides. Its default value is set to the local computer. You need to change the MachineName property only if you want to control the Windows services on a remote machine. |
Pause() | Method | Suspends a Windows service's operation. |
Refresh() | Method | Refreshes the values of all the properties with their latest values. |
ServiceName | Property | Specifies the name of the Windows service. |
ServicesDependedOn | Property | Specifies the set of services on which this Windows service depends. |
ServiceType | Property | One of the ServiceType enumeration values that specifies how the Windows service is used. A Windows service can be of the type InteractiveProcess (can communicate with the desktop), Win32OwnProcess (runs in its own process), or Win32ShareProcess (shares the process with other Windows services). |
Start() | Method | Starts the Windows service. |
Status | Property | Retrieves the status of the Windows service. |
Stop() | Method | Stops the Windows service and other services that are dependent on this service. |
WaitForStatus() | Method | Waits for the service to reach the specified status, which is a value of the ServiceControllerStatus enumeration. Its possible values are ContinuePending, Paused, PausePending, Running, StartPending, Stopped, and StopPending. |