C# Class Opc.Ua.Configuration.ServiceManager

Provides functionalities to manage Windows services such as Start/Stop service.
ファイルを表示 Open project: OPCFoundation/UA-.NET Class Usage Examples

Public Methods

Method Description
GetAllServices ( ) : Opc.Ua.Configuration.Service[]

Gets all installed Windows services.

GetNumberOfLogicalProcessors ( ) : int

Gets the number of logical processors on the system.

GetNumberOfProcessors ( ) : int

Gets the number of physical processors on the system.

GetService ( string serviceName ) : Service

Gets the Service with the given name.

GetServiceProcessorAffinity ( string serviceName ) : bool[]

Gets the affinity for the service with the given name.

If the system has 2 processor and the service is running on processor 2 the affinity bit mask will be : [true][false] If the system has 2 processor and the service is running on both processors the affinity bit mask will be : [true][true]

GetServiceStartMode ( string serviceName ) : StartMode

Gets the start mode of the service with the given name.

GetServiceStatus ( string serviceName ) : ServiceStatus

Gets the status of the service with the given name.

IsServicePaused ( string serviceName ) : bool

Determine whther the service with the given name is paused.

IsServiceRunning ( string serviceName ) : bool

Determine whther the service with the given name is running.

IsServiceStopped ( string serviceName ) : bool

Determine whther the service with the given name is stopped.

PauseService ( string serviceName ) : bool

Pause the service with the given name. This method returns as soon as the Pause method on the service is called and does not guarantee the paused status of the service.

PauseService ( string serviceName, System.TimeSpan timeout ) : bool

Pause the service with the given name and wait until the service status is paused. If the service status is not paused after the given timeout then the service is considered not paused.

ServiceExists ( string serviceName ) : bool

Gets a value whteher the service with the given name is installed.

SetServiceProcessorAffinity ( string serviceName, bool affinity ) : bool

Set the processor affinity for the service with the given name.

If the system has 2 processor and the service is running on processor 2 the affinity bit mask will be : [true][false] If the system has 2 processor and the service is running on both processors the affinity bit mask will be : [true][true]

SetServiceStartMode ( string serviceName, StartMode startMode, uint &retValue ) : bool

Modifies the start mode of a Windows service.

StartService ( string serviceName ) : bool

Start the service with the given name. This method returns as soon as the Start method on the service is called and does not guarantee the running status of the service. You can call this method after stop or pause the service in order to re-start it.

StartService ( string serviceName, System.TimeSpan timeout ) : bool

Start the service with the given name and wait until the status of the service is running. If the service status is not running after the given timeout then the service is considered not started. You can call this method after stop or pause the service in order to re-start it.

StopService ( string serviceName ) : bool

Stop the service with the given name. This method returns as soon as the Stop method on the service is called and does not guarantee the stopped status of the service.

StopService ( string serviceName, System.TimeSpan timeout ) : bool

Stop the service with the given name and wait until the service status is stopped. If the service status is not stopped after the given timeout then the service is considered not stopped.

Private Methods

Method Description
ConvertServiceControllerStatusToServiceStatus ( ServiceControllerStatus status ) : ServiceStatus
ConvertStartModeToString ( StartMode startMode ) : string
ConvertStringToServiceStatus ( string status ) : ServiceStatus
ConvertStringToStartMode ( string startMode ) : StartMode
GetComputerSystem ( ) : System.Management.ManagementObject
GetProcessorAffinity ( int processId ) : bool[]

Gets the processor affinity for the process with the given id.

ServiceFromManagementObject ( System.Management.ManagementBaseObject service ) : Service

Method Details

GetAllServices() public static method

Gets all installed Windows services.
public static GetAllServices ( ) : Opc.Ua.Configuration.Service[]
return Opc.Ua.Configuration.Service[]

GetNumberOfLogicalProcessors() public static method

Gets the number of logical processors on the system.
public static GetNumberOfLogicalProcessors ( ) : int
return int

GetNumberOfProcessors() public static method

Gets the number of physical processors on the system.
public static GetNumberOfProcessors ( ) : int
return int

GetService() public static method

Gets the Service with the given name.
public static GetService ( string serviceName ) : Service
serviceName string The service name.
return Service

GetServiceProcessorAffinity() public static method

Gets the affinity for the service with the given name.
If the system has 2 processor and the service is running on processor 2 the affinity bit mask will be : [true][false] If the system has 2 processor and the service is running on both processors the affinity bit mask will be : [true][true]
public static GetServiceProcessorAffinity ( string serviceName ) : bool[]
serviceName string the service name.
return bool[]

GetServiceStartMode() public static method

Gets the start mode of the service with the given name.
public static GetServiceStartMode ( string serviceName ) : StartMode
serviceName string The service name.
return StartMode

GetServiceStatus() public static method

Gets the status of the service with the given name.
public static GetServiceStatus ( string serviceName ) : ServiceStatus
serviceName string The name of the service.
return ServiceStatus

IsServicePaused() public static method

Determine whther the service with the given name is paused.
public static IsServicePaused ( string serviceName ) : bool
serviceName string The name of the service.
return bool

IsServiceRunning() public static method

Determine whther the service with the given name is running.
public static IsServiceRunning ( string serviceName ) : bool
serviceName string The name of the service.
return bool

IsServiceStopped() public static method

Determine whther the service with the given name is stopped.
public static IsServiceStopped ( string serviceName ) : bool
serviceName string The name of the service.
return bool

PauseService() public static method

Pause the service with the given name. This method returns as soon as the Pause method on the service is called and does not guarantee the paused status of the service.
public static PauseService ( string serviceName ) : bool
serviceName string The name of the service
return bool

PauseService() public static method

Pause the service with the given name and wait until the service status is paused. If the service status is not paused after the given timeout then the service is considered not paused.
public static PauseService ( string serviceName, System.TimeSpan timeout ) : bool
serviceName string The name of the service
timeout System.TimeSpan The timeout.
return bool

ServiceExists() public static method

Gets a value whteher the service with the given name is installed.
public static ServiceExists ( string serviceName ) : bool
serviceName string The service name.
return bool

SetServiceProcessorAffinity() public static method

Set the processor affinity for the service with the given name.
If the system has 2 processor and the service is running on processor 2 the affinity bit mask will be : [true][false] If the system has 2 processor and the service is running on both processors the affinity bit mask will be : [true][true]
public static SetServiceProcessorAffinity ( string serviceName, bool affinity ) : bool
serviceName string the service name.
affinity bool The affinity bitmask.
return bool

SetServiceStartMode() public static method

Modifies the start mode of a Windows service.
public static SetServiceStartMode ( string serviceName, StartMode startMode, uint &retValue ) : bool
serviceName string The service name.
startMode StartMode The new start mode.
retValue uint The return value. /// Return value Description: /// 0 Success /// 1 Not Supported /// 2 Access Denied /// 3 Dependent Services Running /// 4 Invalid Service Control /// 5 Service Cannot Accept Control /// 6 Service Not Active /// 7 ervice Request Timeout /// 8 Unknown Failure /// 9 Path Not Found /// 10 Service Already Running /// 11 Service Database Locked /// 12 Service Dependency Deleted /// 13 Service Dependency Failure /// 14 Service Disabled /// 15 Service Logon Failure /// 16 Service Marked For Deletion /// 17 Service No Thread /// 18 Status Circular Dependency /// 19 Status Duplicate Name /// 20 Status Invalid Name /// 21 Status Invalid Parameter /// 22 Status Invalid Service Account /// 23 Status Service Exists /// 24 Service Already Paused ///
return bool

StartService() public static method

Start the service with the given name. This method returns as soon as the Start method on the service is called and does not guarantee the running status of the service. You can call this method after stop or pause the service in order to re-start it.
public static StartService ( string serviceName ) : bool
serviceName string The name of the service
return bool

StartService() public static method

Start the service with the given name and wait until the status of the service is running. If the service status is not running after the given timeout then the service is considered not started. You can call this method after stop or pause the service in order to re-start it.
public static StartService ( string serviceName, System.TimeSpan timeout ) : bool
serviceName string The name of the service
timeout System.TimeSpan The timeout.
return bool

StopService() public static method

Stop the service with the given name. This method returns as soon as the Stop method on the service is called and does not guarantee the stopped status of the service.
public static StopService ( string serviceName ) : bool
serviceName string The name of the service
return bool

StopService() public static method

Stop the service with the given name and wait until the service status is stopped. If the service status is not stopped after the given timeout then the service is considered not stopped.
public static StopService ( string serviceName, System.TimeSpan timeout ) : bool
serviceName string The name of the service
timeout System.TimeSpan The timeout.
return bool