ken_nogi/bat/base.bat
Kenichiro NOGI 751823a8e0 bat
2025-07-10 10:11:07 +09:00

41 lines
1002 B
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
REM filepath: c:\Users\k.nogi\#GitHub\ken_nogi\bat\stop_service.bat
REM 管理者権限で再実行
net session >nul 2>&1
if %errorlevel% neq 0 (
echo 管理者権限で再実行します...
powershell -Command "Start-Process '%~f0' -Verb RunAs"
exit /b
)
REM サービス名を指定
set "SERVICENAME=Agent"
REM サービスの状態確認
sc query "%SERVICENAME%" | findstr /I "RUNNING" >nul
if %errorlevel%==0 (
echo サービス %SERVICENAME% は起動中です。停止します...
sc stop "%SERVICENAME%"
REM 停止完了まで待機最大30秒
setlocal enabledelayedexpansion
set "COUNT=0"
:WAITLOOP
sc query "%SERVICENAME%" | findstr /I "STOPPED" >nul
if !errorlevel! neq 0 (
timeout /t 1 >nul
set /a COUNT+=1
if !COUNT! lss 30 goto WAITLOOP
)
endlocal
)
REM 停止確認
sc query "%SERVICENAME%" | findstr /I "STOPPED" >nul
if %errorlevel%==0 (
echo サービス %SERVICENAME% は停止しています。
) else (
echo サービス %SERVICENAME% の停止に失敗しました。
)
pause