windows - Batch file calling vbs wont run from Task scheduler -
i have batch file scheduled in task scheduler. if run batch file manually cmd, work , taking 20 mins. if schedule in task scheduler, finishes when starting run , shows result "successfully finished...." (vbs didnt run...) batch file call 2 vbs scripts run. not sure if there wrong task scheduler or batch file gets wrong code in there.
@echo off set logfile=c:\temp\shop_floor_schedule.%time:~0,2%.log echo %date% %time% > %logfile% cscript "c:\work\scripts\export.vbs" >> %logfile% 2>&1 cscript "c:\work\scripts\schedule.vbs" >> %logfile% 2>&1 echo "batch complete" >> %logfile%
i got error massages in log file
fri 06/19/2015 10:00:00.13 microsoft (r) windows script host version 5.8 copyright (c) microsoft corporation. rights reserved. starting excel opening workbook c:\work\scripts\export.vbs(30, 1) microsoft excel: microsoft excel cannot access file 'c:\ntfs3\scripts\production.xls'. there several possible reasons: file name or path not exist. file being used program. workbook trying save has same name open workbook.
i message task scheduler, if run cmd manually, well.
get out of habit of logging using wscript.echo & stdout vbscript outputs... terrible practice , reduces ability include logic work around problems this.
i recommend fix method. instead of using >> %log% 2>&1... use argument vbscripts logfile. it's simple solution. point scheduled task @ vbscript.. should fix issues batch file issue.
const forreading = 1, forwriting = 2, forappending, 8 set fso = createobject("scripting.filesystemobject") set shell = wscript.createobject ("wscript.shell") logfile = "c:\temp\shop_floor_schedule" & hour(now()) & ".log" ' start export.vbs '============================================================ call writelog("starting export vbscript") shell.run "cmd /c cscript c:\work\scripts\export.vbs >> """ & logfile & """ 2>&1" ' start schedule.vbs '======================================== call writelog("starting schedule vbscript") shell.run "cmd /c cscript c:\work\scripts\schedule.vbs >> """ & logfile & """ 2>&1" 'terminate objects , exit script '============================================================ call writelog("terminating script") set objshell = nothing set fso = nothing sub writelog(strmessage) set logf = fso.opentextfile(logfile, forappending, true) strtime = hour(now()) & ":" & minute(now()) logf.writeline = date() & " - " & strtime & " " & strmessage logf.close set logf = nothing end sub
Comments
Post a Comment