【问题标题】:windows Script file which continuously look out on a user app and restarts automatically if it closes?windows 脚本文件不断查看用户应用程序并在关闭时自动重新启动?
【发布时间】:2017-05-16 08:59:46
【问题描述】:

大家好,我该如何编写一个 .bat 文件,它应该在其中执行以下操作

1) on running the script file-> my user app must be executed.
2) continuously  or periodically checks  if user app is running 
3) if app closes it should start the app again.

而且,我怀疑当我的用户应用程序崩溃时,它并没有完全关闭 显示应用程序停止工作错误,我如何绕过这个,以便我的 bat 文件可以检测到应用程序已关闭并需要打开。 ?? 我对此完全陌生,因此非常感谢任何提示和帮助。

【问题讨论】:

    标签: windows terminal scripting windows-7


    【解决方案1】:
    @ECHO OFF
    SETLOCAL
    SET /a counter=60
    :again
    tasklist|FINDSTR /i /b /L "boinc.exe" >NUL
    IF NOT ERRORLEVEL 1 cls&exit
    timeout /t 6 >NUL
    SET /a counter-=1
    IF %counter% gtr 0 GOTO again 
    SET /a counter=60
    ECHO execute BOINC
    START "boinc" "C:\Program Files\eFMer\BoincTasks\boinctasks64.exe"
    GOTO again
    

    我使用这个批处理来确保boinc.exe 启动(这是为了在后台运行研究科学)。

    如果if not errorlevel 1... 行改为

    IF NOT ERRORLEVEL 1 timeout /t 60 >NUL&goto again
    

    然后检查将每 60 秒重新运行一次。就目前而言,它旨在通过超时 6 秒 60 次来延迟检查之间的 6 分钟。这可以通过将counttimeout 参数设置为不同的值来修改。

    (接下来您可能想搜索如何静默运行批处理文件。这里有关于 SO 的文章 - 只需使用页面顶部的 search

    【讨论】:

    • 到了页面顶部。在右侧的黑条上,有一个search 设施。尝试在那里搜索batch silent。它通常涉及 .vbs 例程,因为批处理没有静默模式 - 尽管可能使用 task sceduler
    【解决方案2】:

    从.bat文件执行exe请参考以下链接:-http://www.computerhope.com/issues/ch001345.htm

    但我不确定您是否能够使用 .bat 文件检测正在运行的应用程序。 为了检测应用程序,您可以为此编写自动化脚本。 一切顺利。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      相关资源
      最近更新 更多