.bat 判断并启动一个系统服务

@echo off
 
REM 定义服务名称变量
set SERVICE_NAME=RemoteClient
 
REM 检查服务状态
sc query %SERVICE_NAME% | findstr RUNNING > nul
 
if %errorlevel% equ 0 (
    echo %SERVICE_NAME% is already running.
) else (
    REM 启动服务
    net start %SERVICE_NAME%
    if %errorlevel% equ 0 (
        echo %SERVICE_NAME% has been started successfully.
    ) else (
        echo %SERVICE_NAME% failed to start.
    )
)

 

posted on 2023-05-10 16:15  空明流光  阅读(135)  评论(0编辑  收藏  举报

导航