Aaron Greene
asked on
.bat file doesn't run when started from task scheduler
I have set up a .bat file to open an excel workbook that I need to run at 1:00 AM. The file is a .xlsm that I am using to generate a report. I can run the excel file manually and it works. I created a .vbs file to start the .xlsm file, and it works. I created a .bat file to run the .vbs file and it works as well. When I try to run the .bat file from a scheduled task, I can see the task status show running and then completed, but the report is not generated. I am not sure what the problem could be.
This is the .bat file.
@echo off
cscript "C:\REP_Reports\Report Design\vbScripts\vbsMRT.vb s"
This is vbsMRT.vbs.
option explicit
on error resume next
Dim objExcel
Dim objWorkbook
Dim MyFile
Set objExcel = CreateObject("EXCEL.APPLIC ATION")
objExcel.visible = true
Set objWorkbook = objExcel.Workbooks.Open("C :\REP_Repo rts\Report Design\2MARYMO_MRT01R01.xl sm")
Set objWorkbook = Nothing
Set objExcel = Nothing
This is the .bat file.
@echo off
cscript "C:\REP_Reports\Report Design\vbScripts\vbsMRT.vb
This is vbsMRT.vbs.
option explicit
on error resume next
Dim objExcel
Dim objWorkbook
Dim MyFile
Set objExcel = CreateObject("EXCEL.APPLIC
objExcel.visible = true
Set objWorkbook = objExcel.Workbooks.Open("C
Set objWorkbook = Nothing
Set objExcel = Nothing
For debugging you can try the following as well:
Program/script: cmd
Add arguments: /c c:\folder\file.bat>"C:\REP_Reports\Report Design\vbScripts\vbsMRT.lo g" 2>&1
Also remove the "on error resume next" in the VBS script.
Then after you try and run it from the task scheduler check the LOG file for any errors.
~bp
Program/script: cmd
Add arguments: /c c:\folder\file.bat>"C:\REP_Reports\Report Design\vbScripts\vbsMRT.lo
Also remove the "on error resume next" in the VBS script.
Then after you try and run it from the task scheduler check the LOG file for any errors.
~bp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sounds like something was set in the first task that was causing the problem. Can't really say what that might have been at this point, but glad that recreating it resolved the problem for you, well done.
~bp
~bp
ASKER
Do you know what the difference is between the "Create Task" and "Create Basic Task" options? Once the task is created, the properties screens are identical.
Conceptually the difference is just the complexity of the process. The "Basic" approach uses more of a wizard type approach, leading the user through a simpler set of steps and questions. The "create task" method takes you right to the screens involved and you have to know a bit more about what you need to enter.
The end result is the same, a scheduled task is added to the system. But there may be some differences since the basic approach probably defaults some settings that non-basic approach allows the user to change during initial task creation.
~bp
The end result is the same, a scheduled task is added to the system. But there may be some differences since the basic approach probably defaults some settings that non-basic approach allows the user to change during initial task creation.
~bp
ASKER
I still don't know what caused the problem. I'm chalking that up to user error.
Program/script: cmd
Add arguments: /c c:\folder\file.bat
Try playing with the task General, Security Options:
- "Run only when user is logged on", or "Run whether user is logged on or not".
- Also, set "Run with highest privleges"