美文网首页
Windows bat 批处理守护进程

Windows bat 批处理守护进程

作者: 404d67ac8c12 | 来源:发表于2019-03-03 09:22 被阅读0次
    @echo off
    
    set _task=nodepad++.exe
    set _svr=%cd%\%_task%
    set _des=start.bat
    
    :checkstart
    for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
        if %%n==%_task% (goto checkag) else goto startsvr
    )
    
    :startsvr
    echo %time%
    echo ********Program Start********
    echo Program Start time at %time% ,Please check the log >> restart_service.log
    echo %_svr% > %_des%
    echo exit >> %_des%
    start %_des%
    set/p=.<nul
    for /L %%i in (1 1 10) do set /p a=.<nul&ping.exe /n 2 127.0.0.1>nul
    echo .
    echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
    cscript //b //nologo %tmp%\delay.vbs 10000
    del %_des% /Q
    
    echo ********Program Startup Completion********
    goto checkstart
    
    :checkag
    echo %time% The program runs normally and continues to check after 10 seconds...
    echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs
    cscript //b //nologo %tmp%\delay.vbs 10000
    
    goto checkstart
    

    如果不想显示守护进程页面可使用 vb 隐藏,将上面的守护代码保存为 watchdog.bat。

    set ws=WScript.CreateObject("WScript.Shell")  
    ws.Run "watchdog.bat",0
    

    把上面的代码保存为watchdog.vbs。守护进程需要从任务管理器中进行关闭。

    相关文章

      网友评论

          本文标题:Windows bat 批处理守护进程

          本文链接:https://www.haomeiwen.com/subject/lltpuqtx.html