タイトル: Install/Remove of the Service Denied!
SEOタイトル: Windows「Install/Remove of the Service Denied!」管理者権限不足の原因と対処
| この記事の要点 |
|
このエラーの典型
C:\opt\tomcat\bin> service.bat install
Installing the service 'Tomcat9' ...
Using CATALINA_BASE: "C:\opt\tomcat"
Using CATALINA_HOME: "C:\opt\tomcat"
...
Install/Remove of the Service Denied!
C:\opt\tomcat\bin> service.bat remove
Removing the service 'Tomcat9' ...
Install/Remove of the Service Denied!
Windows のサービス登録/削除は SC_MANAGER_CREATE_SERVICE 権限が必要で、通常ユーザでは拒否されます。
原因
- cmd / PowerShell を通常モードで起動している
- UAC (User Account Control) が有効で、管理者アカウントでも昇格していない
- そもそも管理者グループに属していないアカウント
- グループポリシーでサービス操作が制限されている
対処 1: 管理者として実行
もっとも確実。Win キー → 「cmd」または「powershell」と入力 → Ctrl+Shift+Enter で管理者起動。または:
- スタートメニュー → 「Windows ターミナル」または「コマンドプロンプト」を右クリック
- 「管理者として実行」
- UAC ダイアログで「はい」
- タイトルバーに「管理者:」と表示されることを確認
対処 2: 管理者状態かをコマンドで確認
# PowerShell で確認
([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator)
# True なら管理者、False なら通常モード
# cmd で確認
net session > nul 2>&1 && echo Administrator || echo Not admin
対処 3: スクリプト内から自動昇格
# install-tomcat.ps1
if (-not ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator)) {
# 自分自身を管理者で再起動
Start-Process powershell.exe `
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" `
-Verb RunAs
exit
}
# ここからは管理者として実行される
cd C:\opt\tomcat\bin
.\service.bat install
sc.exe config Tomcat9 start= auto
sc.exe start Tomcat9
サービス操作の標準コマンド
# 管理者 PowerShell で
# サービス作成
sc.exe create MyService binPath= "C:\path\to\app.exe" start= auto
# サービス削除
sc.exe delete MyService
# 開始 / 停止
sc.exe start MyService
sc.exe stop MyService
net start MyService
net stop MyService
# 状態確認
sc.exe query MyService
Get-Service MyService
# 自動起動設定
sc.exe config MyService start= auto
Set-Service -Name MyService -StartupType Automatic
Tomcat の service.bat 詳細
# 管理者 cmd / PowerShell で
cd C:\opt\tomcat\bin
# デフォルト名 (Tomcat9, Tomcat10) でインストール
.\service.bat install
# カスタム名でインストール
.\service.bat install MyTomcat
# JVM オプション等の設定 GUI
.\tomcat9w.exe //ES//Tomcat9
# 削除
.\service.bat remove
.\service.bat remove MyTomcat
nginx を Windows サービス化
nginx 自体はサービス機能を持たないので NSSM (Non-Sucking Service Manager) や winsw を使うのが定番:
# Chocolatey で NSSM
choco install nssm -y
# 管理者 PowerShell で
nssm install nginx "C:\nginx\nginx.exe"
nssm set nginx AppDirectory "C:\nginx"
nssm set nginx Start SERVICE_AUTO_START
nssm start nginx
# 削除
nssm remove nginx confirm
MySQL を Windows サービス化
# 管理者 cmd で MySQL のインストールフォルダへ
cd C:\Program Files\MySQL\MySQL Server 8.0\bin
# サービス登録
.\mysqld --install MySQL80 --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"
# 削除
.\mysqld --remove MySQL80
# 起動
net start MySQL80
グループポリシーで制限されている場合
gpedit.mscを管理者起動- コンピュータの構成 → Windows の設定 → セキュリティの設定 → ローカル ポリシー → ユーザー権利の割り当て
- 「サービスとしてログオン」, 「サービスとしてログオンを拒否する」を確認
- ドメイン環境では Active Directory 側 GPO の制約を IT 管理者に依頼
FAQ
Q: 管理者で起動しても Denied になる
A: アンチウイルス(特に法人向け Symantec / Trend Micro)がサービス改変をブロックしているケース。一時的に無効化 → 再試行。
Q: コマンドプロンプトを毎回管理者で起動するのが面倒
A: ショートカットのプロパティ → 詳細設定 → 「管理者として実行」を ON にしておく。または PowerShell プロファイルで関数化。
Q: Linux でも同じことを?
A: Linux は systemctl に sudo を付ければよく、エラーメッセージは Permission denied / Failed to issue method call。