我正在使用this method来显示批处理文件中的消息框,当通过单击.bat文件启动或从cmd窗口调用时,它会按预期工作并显示消息框。
但是,通过任务计划程序运行批处理文件时,消息框不会显示。
我已验证任务计划程序正在成功运行批处理,因为批处理中的所有其他操作都按预期发生。
也许是相关的,即使在我希望批次完成之后,任务的状态似乎也显示为“正在运行”。
如果它是相关的,这是批处理代码:
@echo off
Goto :START
=======================================================================================================================
This batch checks the CloudStation (CS) sync software on the Synology servers in Brighton and Belfast offices are
syncing correctly in both directions.
Set the BelfastIP and BrightonIP variable accordingly to correct IP's, with no railing "\"
This routine tests for:
1. File created in Brigton is syncd to Belfast
2. File deleted in Brigton is deleted (syncd) in Belfast
3. File created in Belfast is syncd to Brighton
4. File deleted in Belfast is deleted (syncd) in Brighton
...and if any of the above operations fail will provide a message box giveing results of all 4 operations.
In the event of a failure, .txt files that should be deleted by CloudStation sync are NOT cleaned up manually because:
1) experience shows deleting files that CS will later try to delete it will confuse CloudStation and cause
further sync issues (it'll get stuck trying to delete a file that was already manually deleted)
2) it leaves an auditable trail of what/when things happened
3) It's a way of seeing that correct syncing operation has resumed
It is intended this batch is run every hour using Windows Task Sheduler (consider office hours only to avoid returning
to a desktop with hundreds of message boxes to clear if things go tits up over the weekend
=======================================================================================================================
:START
::++++++++++ALLOWABLE SYNC DELAY++++++++++++++++++++++++++++
rem Time allowed for sync delay
set Delay=60
::++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ++++++++CLOUDSTATION SYNC OPERATION CHECK+++++++++++++++
echo(
::++++++++++VARIABLES++++++++++++++++++++++++++++++++++
set BelfastIP=\\172.16.6.20\Haworth McCall\SyncStatus
set BrightonIP=\\192.168.1.11\Haworth McCall\SyncStatus
rem (don't include a trailing '\' in the above IP paths)
echo Checking servers are reachable...
::+++++++++CHEKC SERVERS ARE REACHABLE+++++++++++++++++
if NOT EXIST "%BelfastIP%\" (
cscript "%~dp0\MessageBox.vbs" "SYNC CHECK FAILED. Belfast server not reachable. Check VPN connection"
exit /b
) else (
echo -Belfast server found
)
if NOT EXIST "%BrightonIP%\" (
cscript "%~dp0\MessageBox.vbs" "SYNC CHECK FAILED. Brighton server not reachable."
exit /b
) else (
echo -Brighton server found
)
echo(
::++++++++++CREATE FILE NAME USING DATE&TIME++++++++++++++++
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set datestamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
set ErrorCounter=0
::++++++++TEST BRIGHTON TO BELFAST SYNCING+++++++++++++++++++
echo +++++++Brighton to Belfast sync testing+++++++++
echo (Sync considered as FAILED if file operation not synced within %Delay%seconds)
echo(
set filename=%datestamp%_Brighton.txt
REM Create file at Brighton
@echo>"%BrightonIP%\%filename%"
echo Test File added to Brighton server:
echo %BrightonIP%\%filename%
echo(
echo Wait %Delay%seconds to allow syncing:
timeout /t %Delay% /nobreak
echo(
rem Pause to allow time for sync
rem /t 5 = no. seconds to wait, /nobreak means no keyboard overide, >NUL means countdown not shown
REM Check file created in Brighton has synced to Belfast and if it has, delete file in Brighton and check deletion also syncs to Belfast
if EXIST "%BelfastIP%\%filename%" (
echo +++ PASS - CloudStation successfully synced Test File to Belfast server
echo(
echo Deleting Test File from Brighton server...
set Bri2Bel_create=PASS
del "%BrightonIP%\%filename%"
echo(
Echo Wait %Delay%seconds to allow Belfast to sync TestFile delete..."
timeout /t %Delay% /nobreak
if EXIST "%BelfastIP%\%filename%" (
set Bri2Bel_delete=FAIL
set /A ErrorCounter = %ErrorCounter%+1
rem del "%BelfastIP%\%filename%"
echo +++ FAIL - CloudStation did not remove deleted file from Belfast server
) ELSE (
set Bri2Bel_delete=PASS
echo(
echo +++ PASS - CloudStation successfully removed Test File from Belfast server
)
) ELSE (
rem del "%BrightonIP%\%filename%"
set Bri2Bel_create=FAIL
set Bri2Bel_delete=n/a
set /A ErrorCounter = %ErrorCounter%+1
echo +++ FAIL - Cloudstation did not sync Test File to Belfast server
)
echo(
echo ...Brighton to Belfast testing complete
echo(
echo(
::++++++++TEST BELFAST TO BRIGHTON SYNCING+++++++++++++++++++
echo +++++++Belfast to Brighton sync testing+++++++++
echo(
set filename=%datestamp%_Belfast.txt
@echo>"%BelfastIP%\%filename%"
echo Test File added to Belfast server:
echo %BelfastIP%\%filename%
echo(
echo Wait %Delay%seconds to allow syncing:
timeout /t %Delay% /nobreak
REM Check file created in Belfast has synced to Brighton
if EXIST "%BrightonIP%\%filename%" (
echo +++ PASS - CloudStation successfully synced Test File to Brighton server
echo(
echo Deleting Test File from Brighton server...
del "%BelfastIP%\%filename%"
set Bel2Bri_create=PASS
REM Check file deletion in Belfast has synced and deleted file in Brighton
echo(
Echo Wait %Delay%seconds to allow Belfast to sync TestFile delete..."
timeout /t %Delay% /nobreak
if EXIST "%BrightonIP%\%filename%" (
rem del "%BrightonIP%\%filename%"
set Bel2Bri_delete=FAIL
set /A ErrorCounter = %ErrorCounter%+1
echo +++ FAIL - CloudStation did not remove deleted file from Brighton server
) ELSE (
set Bel2Bri_delete=PASS
echo +++ PASS - CloudStation successfully removed Test File from Brighton server
)
) ELSE (
rem del "%BrightonIP%\%filename%"
set Bel2Bri_create=FAIL
set Bel2Bri_delete=n/a
set /A ErrorCounter = %ErrorCounter%+1
echo +++ FAIL - Cloudstation did not sync Test File to Belfast server
)
echo(
echo ...Belfast to Brighton sync testing complete.
echo(
echo(
::++++++++SHOW MESSAGE BOX IF ANY SYNC TESTS FAIL+++++++++++++++++++
if %ErrorCounter% GTR 0 (
echo === !!! SYNC ERROR !!! ===
rem list each operation with the true/false (success/fail) displayed next to it
rem need to find a way to put each bit of date on a new line
cscript "%~dp0\MessageBox.vbs" "WARNING! CLOUDSTATION SYNC FAILURE!" "" "%datestamp%" "" "" "Brighton to Belfast:" "" "File Sync = %Bri2Bel_create%" "File Delete = %Bri2Bel_delete%" "" "Belfast to Brighton:" "" "File Sync = %Bel2Bri_create%" "File Delete = %Bel2Bri_delete%"
) else (
Echo ===ALL SYNC TESTS WERE SUCCESSFUL===
rem Sync appers to be functioning correctly
cscript "%~dp0\MessageBox.vbs" "CLOUDSTATION SYNC OK"
)
timeout /t 120 >NUL
exit /b
答案 0 :(得分:1)
您必须设置"仅在用户登录时运行"使任务可见。否则它将被隐藏(无论" Hidden"复选框的设置如何。)
如果您无法看到cmd窗口或messageBox,请在修改操作标签下,更改
程序/脚本字段到cmd
将添加参数字段添加到/k "C:\DSCloudSync_Test\DS_CloudStation_SyncTest.bat"