Bagikan melalui


Service Class

The Service class represents an instance of the SQL Server service.

Inheritance Hierarchy

System.Object
  Microsoft.SqlServer.Management.Smo.SmoObjectBase
    Microsoft.SqlServer.Management.Smo.Wmi.WmiSmoObject
      Microsoft.SqlServer.Management.Smo.Wmi.Service

Namespace:  Microsoft.SqlServer.Management.Smo.Wmi
Assembly:  Microsoft.SqlServer.SqlWmiManagement (in Microsoft.SqlServer.SqlWmiManagement.dll)

Syntax

'Declaration
Public NotInheritable Class Service _
    Inherits WmiSmoObject _
    Implements IAlterable
'Usage
Dim instance As Service
public sealed class Service : WmiSmoObject, 
    IAlterable
public ref class Service sealed : public WmiSmoObject, 
    IAlterable
[<SealedAttribute>]
type Service =  
    class 
        inherit WmiSmoObject 
        interface IAlterable 
    end
public final class Service extends WmiSmoObject implements IAlterable

The Service type exposes the following members.

Properties

  Name Description
Public property AcceptsPause Gets the Boolean property value that specifies whether the SQL Server service can be paused.
Public property AcceptsStop Gets the Boolean property value that specifies whether the SQL Server service can be stopped.
Public property AdvancedProperties Represents a collection of Property objects. Each Property object represents an advanced property defined on the SQL Server service.
Public property Dependencies Returns a list of services that are dependent on the referenced SQL Server service.
Public property Description Gets a textual description of the SQL Server service.
Public property DisplayName Gets the display name of the SQL Server service.
Public property ErrorControl Gets the severity of the error if the SQL Server service fails to start during startup.
Public property ExitCode Gets the Win32 error code that defines problems encountered when starting and stopping the SQL Server service.
Public property IsHadrEnabled Gets whether the High Availability/Disaster Recovery is enabled.
Public property Name Gets or sets the name of the referenced Windows Management Instrumentation (WMI) object. (Inherited from WmiSmoObject.)
Public property Parent Gets the ManagedComputer object that is the parent of the Service object.
Public property PathName Gets the path and file name of the binary file that implements the SQL Server service.
Public property ProcessId Gets the process ID that uniquely identifies the SQL Server service.
Public property Properties Represents a collection of Property objects. Each Property object represents a property defined on the Windows Management Instrumentation (WMI) object. (Inherited from WmiSmoObject.)
Public property ServiceAccount Gets the system account under which the SQL Server service is running.
Public property ServiceState Gets the state of the SQL Server service, such as running, stopped, or paused.
Public property StartMode Gets or sets the method by which the SQL Server service is started.
Public property StartupParameters Gets or sets any startup parameters for the SQL Server service.
Public property State Gets the state of the referenced object. (Inherited from SmoObjectBase.)
Public property Type Gets the type of service, such as Microsoft Search service, SQL Server Agent service, or SQL Server service.
Public property Urn Gets the Uniform Resource Name (URN) address that represents the Windows Management Instrumentation (WMI) object. (Inherited from WmiSmoObject.)
Public property UserData Gets or sets user-defined data associated with the referenced object. (Inherited from SmoObjectBase.)

Top

Methods

  Name Description
Public method Alter Updates any Service object property changes on an instance of SQL Server.
Public method ChangeHadrServiceSetting Changes the HA/DR service settings.
Public method ChangePassword Changes the password for the system account under which the SQL Server service is running.
Public method Equals (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Public method Initialize Initializes the referenced object. (Inherited from WmiSmoObject.)
Protected method IsObjectInitialized Specifies whether the referenced object is initialized. (Inherited from WmiSmoObject.)
Public method Pause Pauses the SQL Server service.
Public method Refresh Refreshes the SQL Server service. (Overrides WmiSmoObject.Refresh().)
Public method Resume Resumes the SQL Server service.
Protected method SetName Sets the name of the referenced object. (Inherited from WmiSmoObject.)
Protected method SetParentImpl Sets the parent of the referenced object. (Inherited from WmiSmoObject.)
Public method SetServiceAccount Sets the account under which the SQL Server service runs.
Public method Start Starts the SQL Server service.
Public method Stop Stops the SQL Server service.
Public method ToString (Inherited from Object.)
Public method Validate Validates the state of an object. (Inherited from SmoObjectBase.)

Top

Events

  Name Description
Public event ManagementStateChange An event that occurs when the management state changes.

Top

Remarks

The Service object is used to programmatically manage the SQL Server service. With the Service object you can:

  • Connect to the service.

  • Modify the account and password used to connect to the service.

  • Start, stop, pause, and resume the service.

  • Check the properties of the service.

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Examples

Managing Services and Network Settings by Using WMI Provider

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.SqlServer.Management.Smo.Wmi Namespace

Other Resources

WMI and SQL Server