Link to home
Start Free TrialLog in
Avatar of Aaron Greene
Aaron GreeneFlag for United States of America

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.vbs"

This is vbsMRT.vbs.

option explicit
on error resume next
Dim objExcel
Dim objWorkbook
Dim MyFile
Set objExcel = CreateObject("EXCEL.APPLICATION")
objExcel.visible = true
Set objWorkbook = objExcel.Workbooks.Open("C:\REP_Reports\Report Design\2MARYMO_MRT01R01.xlsm")
Set objWorkbook = Nothing
Set objExcel = Nothing
Avatar of NVIT
NVIT
Flag of United States of America image

What does your Action look like? Per your post, it should be...

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"
Avatar of Bill Prew
Bill Prew

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.log" 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
ASKER CERTIFIED SOLUTION
Avatar of Aaron Greene
Aaron Greene
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Aaron Greene

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
I still don't know what caused the problem.  I'm chalking that up to user error.