windows sc命令_Windows Sc从命令行进行服务管理

windows sc命令

windows sc命令

Operating systems run services to server operating system or user level features. These windows services generally starts in the startup and stopped at the shutdown. But some time we need to start service after the start or a configuration change.

操作系统运行针对服务器操作系统或用户级别功能的服务。 这些Windows服务通常在启动时启动,在关闭时停止。 但是有些时候,我们需要在启动或配置更改后启动服务。

Windows provides different tools to manage services. We have all ready looked the native Powershell service management tools following tutorial.

Windows提供了不同的工具来管理服务。 我们已经按照教程准备好了本机Powershell服务管理工具。

Service Management With Windows Powershell From Command Line

使用Windows Powershell从命令行进行服务管理

帮帮我(Help)

Detailed help about sc command can be get with /? option like below.

可以通过/?获得有关sc命令的详细帮助/? 如下所示的选项。

$ sc /?
Help
Help
帮帮我

句法(Syntax)

sc command syntax is similar to the most of the windows command. First we specify server names if we want to run service command remote systems and then provide real command to operate on service. After those we specify service name and other options.

sc命令的语法与大多数Windows命令相似。 如果要在远程系统上运行服务命令,则首先指定服务器名称,然后提供实际命令以对服务进行操作。 在这些之后,我们指定服务名称和其他选项。

sc <server> [command] [service name] <option1> <option2>...

命名服务 (Naming Service)

There are two identifier to name services. SERVICE_NAME is real name where we use for related service operations and will be used for identifier. DISPLAY_NAME is like a tag and used to provide more readable and understandable service names. In the following example we should use Appinfo for service operations.

有两个用于命名服务的标识符。 SERVICE_NAME是实名,我们用于相关服务操作,并将用作标识符。 DISPLAY_NAME就像一个标签,用于提供更具可读性和可理解性的服务名称。 在下面的示例中,我们应该使用Appinfo进行服务操作。

SERVICE_NAME: Appinfo
DISPLAY_NAME: Application Information

启动服务 (Start Service)

Services should be started in order serve. There are a lot of services in a windows operating systems. We will use start command in order to start windows service. Some services can be depended other services. In this situations we should start first dependency services.

服务应按顺序启动。 Windows操作系统中有很多服务。 我们将使用start命令来启动Windows服务。 某些服务可以依赖于其他服务。 在这种情况下,我们应该启动第一依赖服务。

In this example we will start the service named ProtectedStorage .

在此示例中,我们将启动名为ProtectedStorage的服务。

$ sc start ProtectedStorage
Start Service
Start Service
启动服务

If the service starts without a problem it will print the status of the service. The STATE line shows the service is pending for start.

如果服务启动没有问题,它将打印服务状态。 STATE行显示该服务正在等待启动。

LEARN MORE  How To Use Mysql / MariaDB From Console?
了解更多如何从控制台使用Mysql / MariaDB?

停止服务 (Stop Service)

Stopping a windows service is very similar to starting it. We will just change the start command with stop command. In this example we will stop the service named ProtectedStorage where we have started it in previous step.

停止Windows服务与启动它非常相似。 我们将只使用stop命令来更改启动命令。 在此示例中,我们将停止在上一步中启动的名为ProtectedStorage的服务。

$ sc stop ProtectedStorage
Stop Service
Stop Service
停止服务

显示详细的服务状态(Display Detailed Service Status)

Detailed information about a service can be displayed with query command by providing the service name. In this example we display information about ProtectedStorage service.

通过提供服务名称,可以使用query命令显示有关服务的详细信息。 在此示例中,我们显示有关ProtectedStorage服务的信息。

$ sc query ProtectedStorage
Display Detailed Service Status
Display Detailed Service Status
显示详细的服务状态

This command output will provide following information about the service.

此命令输出将提供有关该服务的以下信息。

  • SERVICE_NAME

    SERVICE_NAME

  • TYPE line shows service type

    TYPE行显示服务类型

  • STATE line shows current status of service like STOPPED , RUNNING , etc.

    STATE行显示服务的当前状态,如STOPPEDRUNNING等。

  • WIN32_EXIT_CODE line shows last stop event exit code

    WIN32_EXIT_CODE行显示了最后一次停止事件的退出代码

  • SERVICE_EXIT_CODE

    SERVICE_EXIT_CODE

  • CHECKPOINT

    CHECKPOINT

  • WAIT_HINT

    WAIT_HINT

列出所有服务 (List All Services)

There is a lot of service in a default Windows installation. After the installation 3 party applications may add new services too. All of these services can be listed with query command and state=all options like below.

默认的Windows安装中有很多服务。 安装后,第三方应用程序也可能会添加新服务。 所有这些服务都可以使用query命令和state=all选项列出,如下所示。

$ sc query state= all
List All Services
List All Services
列出所有服务

仅列出正在运行的服务(List Only Running Services)

Previous example lists  all services those running or stopped. We may interested with only running services. If we provide no option to the  query command it will only print running services by default.

上一个示例列出了所有正在运行或停止的服务。 我们可能只对正在运行的服务感兴趣。 如果我们不提供query命令的选项,则默认情况下将仅打印正在运行的服务。

$ sc query

重新启动服务 (Restart Service)

Services have configurations and these configurations can be changed during they are running. Or some services may start work incorrectly. In this situations restart services is the best way to make it work and apply new service configuration.

服务具有配置,并且可以在运行期间更改这些配置。 否则某些服务可能无法正常启动。 在这种情况下,重新启动服务是使其工作并应用新服务配置的最佳方法。

$ sc stop ProtectedStorage
$ sc start ProtectedStorage

暂停服务 (Pause Service)

A service can be paused without loosing its session related information and data. And then this service can be resumed too. In order to pause a service the service should support pausing. In this example  we will pause ProtectedStorage service.

可以在不丢失与会话相关的信息和数据的情况下暂停服务。 然后也可以恢复此服务。 为了暂停服务,服务应支持暂停。 在此示例中,我们将暂停ProtectedStorage服务。

$ sc pause ProtectedStorage

恢复或继续服务 (Resume or Continue Service)

We will resume and continue an all ready paused service with continue command like below.

我们将使用如下continue命令恢复并继续所有就绪的暂停服务。

$ sc continue ProtectedStorage

翻译自: https://www.poftut.com/service-management-windows-sc-command-line/

windows sc命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值