0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Windowsのサービス開始停止をbat(コマンド)で実行

Posted at

概要

テスト環境のデータベースのサービス。

『誤ってテスト環境に向いたままの本番プログラム』
があったらエラーになって検知できるように、念の為普段はサービス停止してる。
(常にサービスを起動しておけない事情がある)

テスト環境で動作確認したい時は、
タスクマネージャー開いてサービスタブまで行って右クリック ⇒ 開始 or 停止
してる。
image.png
image.png

タスクマネージャー開くのとか面倒くさいのでコマンドで実行したい。
(bat用意しときたい)

やり方

サービス開始
sc start "サービス名"
サービス停止
sc stop "サービス名"

実行権限

下記のように『アクセスが拒否されました。』となったら、コマンドプロンプトを管理者権限で開いて実行する必要あり。
(停止についても同様)
image.png

すでに開始してるサービスを開始しようとした場合

下記のようにエラー。
image.png

すでに停止しているサービスを停止しようとした場合

下記のようにエラー。
image.png

参考サイトさん

バージョン

Windows 10 Pro 21H2 OSビルド 19045.2311

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?