我有一個呼叫 .bat 檔案的 VBS 腳本,因此它以隱藏模式運行。.bat 檔案需要在啟動時立即運行并一直等待創建檔案夾,以便殺死應用程式然后重新啟動它。它作業得很好,除了我不知道如何添加一個計時器,以便在 5 分鐘后不管結果如何都會停止。我嘗試添加超時,但沒有奏效。我也嘗試將其添加到批處理檔案中,但這不起作用。有什么建議 ?
for /l %%a in (1,1,48) do timeout 300 >nul
這是vbs腳本
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c %systemdrive%\ExecuteCmd.bat"
oShell.Run strArgs, 0, false
和bat檔案
@echo off
:search
if exist "%userprofile%\BlakFolder" (
goto StopThisProgram
) else (
goto search
)
:StopThisProgram
taskkill /im BlerApp.exe /f
goto ThisProgram
:StartThisProgram
TIMEOUT 10 /NOBREAK
START "" "C:\Program Files\BlerAp\BlerApp.exe"
Exit \b
uj5u.com熱心網友回復:
set /a timer=0
:search
if exist "%userprofile%\BlakFolder" goto StopThisProgram
timeout /t 1 >nul
set /a timer =1
if %timer% geq 300 goto stopthisprogram
goto search
這也將消除將占用 CPU 的硬回圈。
每 1 秒timer遞增一次。如果達到 300,則停止。
您可能希望重置timer到塊0內start...。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/437672.html
