1

我有一个从 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。它设置为仅在用户登录并具有最高权限时运行。

谢谢!

4

1 回答 1

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
于 2013-04-21T08:05:47.533 回答