📜  windows 启动停止服务 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:35:42.299000             🧑  作者: Mango

Windows 启动停止服务 - Shell/Bash

简介

Windows 操作系统中服务是以一种特别的方式运行的程序,可以在系统启动时自动开始运行,也可以通过管理工具手动启动和停止。在 Shell/Bash 下,我们也可以通过命令来启动和停止服务。本篇文章将会讲解如何使用 Shell/Bash 启动和停止 Windows 服务。

启动服务

要在 Shell/Bash 中启动 Windows 服务,我们需要使用 sc 命令。该命令常用于与服务打交道,如在 Shell/Bash 下启动、停止、安装、卸载服务等。下面的命令将启动 dnscache 服务:

sc start dnscache

执行该命令后,系统会尝试启动 dnscache 服务。如果该服务已经启动,则不会有任何提示。如果该服务未启动,则会输出如下内容:

> sc start dnscache
[SC] StartService FAILED 1056:

An instance of the service is already running.

以上是因为 dnscache 服务已经在运行中,不能重复启动。在这种情况下,我们无需采取任何进一步的操作。

停止服务

要在 Shell/Bash 中停止 Windows 服务,我们同样需要使用 sc 命令。下面的命令将停止 dnscache 服务:

sc stop dnscache

执行该命令后,系统会尝试停止 dnscache 服务。如果该服务未在运行,则不会有任何提示。如果该服务正在运行,则会输出如下内容:

> sc stop dnscache
[SC] ControlService FAILED 1062:

The service has not been started.

以上是因为 dnscache 服务未在运行中,不能停止。在这种情况下,我们无需采取任何进一步的操作。

参考资料