计划的批处理脚本停止运行

时间:2013-04-20 13:20:08

标签: batch-file task

我从CMD运行时有一个脚本正常运行,但是当我从任务调度程序运行它时虽然它按预期执行了所有操作,但脚本状态仍然挂起“正在运行”

这是脚本:

    @echo OFF
    tasklist /FI "IMAGENAME eq utorrent.exe" 2>NUL | find /I /N "utorrent.exe">NUL
    if "%ERRORLEVEL%"=="0" (echo UTorrent is running nothing to do) ELSE (
    echo UTorrent is not running, starting Utorrent!
    start C:\Users\Adonis\AppData\Roaming\uTorrent\uTorrent.exe
    )

    tasklist /FI "IMAGENAME eq steam.exe" 2>NUL | find /I /N "steam.exe">NUL
    if "%ERRORLEVEL%"=="0" (echo Steam is running nothing to do) ELSE (
    echo Steam is not running, starting Steam!
    start X:\Games\SteamLibrary\Steam.exe
    )

    exit

任何人都可以建议为什么会这样吗? IE为什么脚本通过调度程序停留在运行状态?

有问题的操作系统是Windows 8。 它设置为仅在用户登录并具有最高权限时运行。

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试使用/ B参数启动应用程序,不要停止执行脚本。

此外,我改进了代码的语法:

@echo OFF

(Tasklist /FI "IMAGENAME eq utorrent.exe" | find /I "utorrent.exe">NUL && (
    Echo: UTorrent is running nothing to do)
) || (
    Echo: UTorrent is not running, starting Utorrent!
    Start /B "" "C:\Users\Adonis\AppData\Roaming\uTorrent\uTorrent.exe"
)

(Tasklist /FI "IMAGENAME eq steam.exe" | find /I "steam.exe">NUL && (
    Echo: Steam is running nothing to do)
) || (
    Echo: Steam is not running, starting Steam!
    Start /B "" "X:\Games\SteamLibrary\Steam.exe"
)

Exit