System.ServiceProcess 命名空间

System.ServiceProcess 命名空间提供用于实现、安装和控制 Windows 服务应用程序的类。 The System.ServiceProcess namespace provides classes that allow you to implement, install, and control Windows service applications. 服务是长期运行的可执行文件,它们不通过用户界面来运行。 Services are long-running executables that run without a user interface. 实现服务涉及以下方面:从 ServiceBase 类继承,定义在传入开始、停止、暂停和继续命令时要处理的特定行为,以及定义在系统关闭时要执行的自定义行为和操作。 Implementing a service involves inheriting from the ServiceBase class and defining specific behavior to process when start, stop, pause, and continue commands are passed in, as well as custom behavior and actions to take when the system shuts down.

ServiceBase

为将作为服务应用程序的一部分而存在的服务提供基类。Provides a base class for a service that will exist as part of a service application. 在创建新的服务类时,必须从 ServiceBase 派生。ServiceBase must be derived from when creating a new service class.

ServiceController

表示 Windows 服务并允许连接到正在运行或者已停止的服务、对其进行操作或获取有关它的信息。Represents a Windows service and allows you to connect to a running or stopped service, manipulate it, or get information about it.

ServiceControllerPermission

允许服务控制器对代码访问安全权限的控制。Allows control of code access security permissions for service controllers.

ServiceControllerPermissionAttribute

允许声明性的服务控制器权限检查。Allows declarative service controller permission checks.

ServiceControllerPermissionEntry

定义为 ServiceController 设置的代码访问安全性权限的最小单位。Defines the smallest unit of a code access security permission that is set for a ServiceController.

ServiceControllerPermissionEntryCollection

包含 ServiceControllerPermissionEntry 对象的强类型集合。Contains a strongly-typed collection of ServiceControllerPermissionEntry objects.

ServiceInstaller

安装一个类,该类扩展 ServiceBase 来实现服务。Installs a class that extends ServiceBase to implement a service. 在安装服务应用程序时由安装实用工具调用该类。This class is called by the install utility when installing a service application.

ServiceProcessDescriptionAttribute

指定属性或事件的说明。Specifies a description for a property or event.

ServiceProcessInstaller

安装一个可执行文件,该文件包含扩展 ServiceBase 的类。Installs an executable containing classes that extend ServiceBase. 该类由安装实用工具(如 InstallUtil.exe)在安装服务应用程序时调用。This class is called by installation utilities, such as InstallUtil.exe, when installing a service application.

TimeoutException

当指定的超时时间已过时引发的异常。The exception that is thrown when a specified timeout has expired.

结构

SessionChangeDescription

确认终端服务会话更改的原因。Identifies the reason for a Terminal Services session change.

枚举

PowerBroadcastStatus

指示系统的电源状态。Indicates the system's power status.

ServiceAccount

指定服务的安全上下文,安全上下文定义其登录类型。Specifies a service's security context, which defines its logon type.

ServiceControllerPermissionAccess

定义 ServiceController 权限类使用的访问级别。Defines access levels used by ServiceController permission classes.

ServiceControllerStatus

指示服务的当前状态。Indicates the current state of the service.

ServiceStartMode

指示服务的启动模式。Indicates the start mode of the service.

ServiceType

表示服务的类型。Represents the type of the service.

SessionChangeReason

指定终端服务会话更改通知的原因。Specifies the reason for a Terminal Services session change notice.

注解

使用一个安装实用程序,如 InstallUtil.exe 安装服务。Services are installed using an installation utility such as InstallUtil.exe. System.ServiceProcess命名空间提供服务信息写入注册表的安装类。The System.ServiceProcess namespace provides installation classes that write service information to the registry. ServiceProcessInstaller类提供了一个包含类,它将安装到安装中的所有服务的常见组件。The ServiceProcessInstaller class provides an encompassing class which installs components common to all the services in an installation. 为每个服务创建的实例ServiceInstaller类安装特定于服务的功能。For each service, you create an instance of the ServiceInstaller class to install service-specific functionality.

ServiceController类,可连接到现有服务并对其进行操作或获取有关它的信息。The ServiceController class enables you to connect to an existing service and manipulate it or get information about it. 此类通常用于管理容量,并使您能够启动、 停止、 暂停、 继续,或在服务上执行自定义命令。This class is typically used in an administrative capacity, and enables you to start, stop, pause, continue, or perform custom commands on a service. 其中ServiceBase类定义服务执行命令时,处理ServiceController是代理,使你可以在服务上调用这些命令。Where the ServiceBase class defines the processing a service performs when a command occurs, the ServiceController is the agent that enables you to call those commands on the service.