我看到這個帖子..
Batch runs manually but not in scheduled task任務計劃程序運行Windows批處理文件
它不贏2008,但服務器2003
有一個關於時間計劃任務..
不運行。無論是預定還是「詢問」手動運行。
運行.. d:\工作\腳本\ res_tc.bat
具有與使用雙冒號之前有問題「::」之前也曾嘗試過用:REM代替 - 但是有沒有不同。
運行方式: NT AUTHORITY \ SYSTEM
@ECHO OFF
CLS
REM DISABLE TOMCAT CHECK
SCHTASKS /QUERY|find /i "TCCheck">NUL
IF NOT ERRORLEVEL 1 SCHTASKS /CHANGE /TN "TCCheck" /DISABLE
ECHO CHECKING FOR AND KILLING JAVA
TASKLIST | FIND /I "java.exe" && IF NOT ERRORLEVEL 1 TASKKILL /F /IM java.exe
REM LOOK FOR TOMCAT..
REM If Tomcat was not installed using the installer - instead using a batch file
REM We have to look for the service instead
REM We cannot depend on the Registry key - HKLM\SOFTWARE\Apache Software Foundation\Tomcat
REM Instead, we have to look for it using the registry key
REM HKLM\SYSTEM\CurrentControlSet\services
REM However, we know Tomcat - could be tomcat5, tomcat6, or tomcat7
FOR /F "usebackq tokens=1" %%a in (`reg query "HKLM\SYSTEM\CurrentControlSet\services" ^| find /i "tomcat"`) do SET TomcatService=%%a
REM THANKS FOR THIS - https://stackoverflow.com/questions/17279114/split-path-and-take-last-folder-name-in-batch-script
set TomcatServiceName1=%TomcatService:~0,-1%
for %%f in (%TomcatServiceName1%) do set TomcatServiceName=%%~nxf
FOR /F "usebackq tokens=3" %%a in (`reg query "%TomcatService%" /v ImagePath`) do SET TomcatFolder=%%a
FOR /F "tokens=1-2,* delims=\" %%1 IN ("%TomcatFolder%") do Set TomcatLocation= %%1\%%2
REM Stop Service: Apache Tomcat
ECHO STOPPING SERVICE Apache Tomcat
NET STOP %TomcatServiceName%
ECHO CHECKING TO INSURE SERVICE Apache Tomcat IS STOPPED
NET START | FIND /I "Apache Tomcat"
IF NOT ERRORLEVEL 1 ECHO Apache Tomcat IS STARTED... STOPPING NOW
IF NOT ERRORLEVEL 1 NET STOP %TomcatServiceName%
ECHO DOUBLE-CHECKING TO INSURE SERVICE Apache Tomcat IS STOPPED
PING 127.0.0.1 -w 1 > NUL
NET START | FIND /I "Apache Tomcat"
IF ERRORLEVEL 1 ECHO Apache Tomcat IS STOPPED... GOOD TO GO
IF NOT ERRORLEVEL 1 ECHO Apache Tomcat IS STARTED...
REM -- SOME FAILURE IN STOPPING THE SERVICE, YOU WILL WANT TO EXIT
IF NOT ERRORLEVEL 1 GOTO END
PING 127.0.0.1 -w 1000 > NUL
REM DELETE LOGS - YOU DON'T WANT TO DELETE LOGS IN A PRODUCTION ENVIRONMENT
ECHO DEL Tomcat Log files
ECHO Y | DEL %TomcatLocation%\aa*.*
ECHO Y | DEL %TomcatLocation%\logs\*.*
ECHO DEL Log files
ECHO Y | DEL D:\logs\*.*
ECHO Y | DEL D:\bo_logs\*.*
REM DELETE FOLDER: %TomcatLocation%\work (Catalina Work Directory)
ECHO DELETING THE %TomcatLocation%\work DIRECTORY
RD /S/Q %TomcatLocation%\work
REM DELETE FOLDER: %TomcatLocation%\temp (Temp Directory)
ECHO DELETING THE %TomcatLocation%\temp DIRECTORY
RD /S/Q %TomcatLocation%\temp
IF NOT EXIST %TomcatLocation%\temp\. MD %TomcatLocation%\temp
REM START SERVICE: APACHE TOMCAT
ECHO STARTING Apache Tomcat
NET START | FIND /I "Apache Tomcat"
IF ERRORLEVEL 1 NET START %TomcatServiceName%
IF NOT ERRORLEVEL 1 ECHO Apache Tomcat IS ALREADY STARTED
PING 127.0.0.1 -w 1000 > NUL
ECHO.
ECHO PROCESS IS COMPLETE - VISUALLY DOUBLE CHECK TO INSURE
ECHO Apache Tomcat
ECHO ARE STARTED
REM ENABLE TOMCAT CHECK
SCHTASKS /QUERY|find /i "TCCheck">NUL
IF NOT ERRORLEVEL 1 SCHTASKS /CHANGE /TN "TCCheck" /ENABLE
GOTO END
:END
rem pause
EXIT
另一個考慮在計劃任務使用。你可能需要堅持使用ARGS(參數)的安全,這樣的文件是不是「自動」援引..
考慮..
SET /A ARGS_COUNT=0
FOR %%A in (%*) DO SET /A ARGS_COUNT+=1
REM ECHO %ARGS_COUNT%
If %ARGS_COUNT% == 0 GOTO END
If %ARGS_COUNT% == 1 GOTO CONTINUE
:CONTINUE
REM DISABLE TOMCAT CHECK
SCHTASKS /QUERY|find /i "TCCheck">NUL
IF NOT ERRORLEVEL 1 SCHTASKS /CHANGE /TN "TCCheck" /DISABLE
...
在你的計劃任務,修改運行爲(注意蝙蝠後的空間和1).. D:\ WORK \ Scripts \ res_tc.bat 1
然後,您必須從命令提示符運行批處理文件,如下所示:res_tc.bat 1或類似的東西..如果您只運行一個res_tc.bat沒有ARGS,fille只會以不執行而結束。希望這可以幫助。
注意:此下一部分不建議在調度任務中,但是對於獨立文件。如果你想相對快速和可靠的方式來啓動/停止的Apache Tomcat,你可以做以下(靠近頂部 - 注意選擇的附加):
@ECHO OFF
CLS
CHOICE /C YN /M "DO YOU WANT TO RESTART APACHE TOMCAT WEB SERVICE?"
IF %ERRORLEVEL% == 2 GOTO END
REM DISABLE TOMCAT CHECK
SCHTASKS /QUERY|find /i "TCCheck">NUL
IF NOT ERRORLEVEL 1 SCHTASKS /CHANGE /TN "TCCheck" /DISABLE
...
只是增值業務的位置更大的註冊表檢測,安裝文件夾和服務名稱,使這項工作與Apache Tomcat上的任何更新版本。 – Leptonator