【问题标题】:Batch file - restart program after every 20 minutes批处理文件 - 每 20 分钟后重新启动程序
【发布时间】:2013-03-24 19:03:58
【问题描述】:

我想创建一个启动程序的批处理文件,20分钟后将关闭程序并重新启动。

关于批处理文件,我唯一知道的就是如何启动程序:

@echo off
Start [adress of application]

【问题讨论】:

  • 您可能希望使用 schtasks.exe 来安排任务。它将允许您将任务安排在某个时间,并限制它运行的时间。如果您想要更具体的答案,请告诉我们您使用的是什么操作系统。

标签: batch-file


【解决方案1】:

这行得通:

@echo off                           //Turn off screen text messages
:loop                               //Set marker called loop, to return to
start "Wicked_Article_Creator" "C:\Wicked Article Creator\Wicked Article Creator.exe"  //Start program, with title and program path 
timeout /t 1200 >null               //Wait 20 minutes
taskkill /f /im "Image Name" >nul   //Image name, e.g. WickedArticleCreator.exe, can be found via Task Manager > Processes Tab > Image Name column (look for your program)
timeout /t 7 >null                  //Wait 7 seconds to give your prgram time to close fully - (optional)
goto loop                           //Return to loop marker

【讨论】:

  • 我正在寻找类似的东西,它工作得非常好。不过,只有一件事,命令提示符始终可见。是否可以隐藏cmd窗口,只在exe启动时显示,然后再次隐藏?
【解决方案2】:
@echo off
:loop
start yourtarget.exe ...
timeout /t 1200 >null
taskkill /f /im yourtarget.exe >nul
goto loop

应该做的工作。

【讨论】:

  • I get Error invalid query: 'timeout' is not known as an internal or external command , operable program or batch program.
  • timeout.exe 是一个内置实用程序,本应随 Windows 提供。自 W2000 不同版本可能不包含它以来,它显然是标准的。在我的 W7 Home Premium 系统上,它位于 c:\windows\system32 中,而 c:\windows\syswow64 中有一个 64 位版本。试试dir /s \timeout.exe。如果找到该文件,请确保它所在的目录包含在您的 PATH 中。如果找不到,请尝试谷歌搜索timeout.exe download
  • 添加后我得到:ERROR invalid query
  • 您需要准确说出您使用的 TASKKill 行。
  • @echo off :loop start "" "C:\Wicked Article Creator\Wicked Article Creator.exe" timeout /t 1200 >null taskkill /f /im "C:\Wicked Article Creator\Wicked Article Creator.exe" >nul goto loop
【解决方案3】:
@echo off                           
:loop                               
timeout /t 20 >null   ( Wait for 20 seconds before kill program)            
taskkill /F /IM terminal.exe  
timeout /t 3600 >null ( wait for 1hr before returning to loop or recycle the process)           
goto loop              

我使用另一个名为 mt4bar 的程序来监控我的应用程序,并在它们崩溃或关闭时重新启动它们

【讨论】:

    【解决方案4】:

    对于遇到这个老问题的任何人: 除了 timeout.exe,您还可以 ping 到一个绝对不存在的地址:

    ping 999.199.991.91 -n 1 -w 60000 >NUL
    

    您可以将 60000 更改为您想要的任何延迟(以毫秒为单位)。

    1 second = 1000
    
    10 seconds = 10000
    
    60 seconds = 60000
    

    等等..

    【讨论】:

    • 与超时相比听起来资源密集。
    猜你喜欢
    • 1970-01-01
    • 2016-05-24
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2012-03-08
    • 1970-01-01
    相关资源
    最近更新 更多