Share via


Batch files appear to start but don't fully execute on Windows 10 Task Scheduler

Question

Monday, July 8, 2019 12:29 PM

I recently set up a new system with Windows 10 Pro and copied the C:\Batch folder to the new system

These systems are essentially identical in their hardware configuration except for the motherboard, memory & video card. ( Both are ASUS Motherboards and Video cards with i7 Processors.)

All drives are duplicated in size, manufactures and drive letter assignment.

 

I use Robocopy in a batch file to copy files at the end of the day to a second set of hard drives on the same box.  This has been executing perfectly on Windows 7 for years.

 

When I attempt to set this up in Scheduler on Windows 10, Scheduler says it is running but there is no activity taking place.  Task Manager and Resource Monitor bear this out not to mention the obvious that the files aren't copied across.

When I execute this batch file from the command prompt it runs as expected.  There are no "call" statements in the batch file.

 

Example:

  Robocopy /MIR /MT:8 /R:2 /W:5 /Log:H:\BackupLogs\BULog.txt /X /V /TEE "C:\Batch" "H:\DataBU\Batch"

 

I have configured Task Scheduler as follows:

 

Under General Tab I have set the user account under Security Options to the Domain user that has local admin rights.

It is set to run whether user is logged on or not and with the highest privileges.

Configure for Windows 10 is selected

 

Triggers; it is set to run daily at 23:00:00. It is set to stop the task if it runs later than 1 day and it is enabled.

 

Actions tab is set to 'Start a Program' and the full path to the batch file is correct.  There are no arguments added and I have entered 'C:\Batch' as the 'Start In' option.

 

Conditions have Start task only if on AC power and Wake computer to run this task selected.

 

Settings have the following selected:

 - Allow task to be run on demand

 - Run task as soon as possible after . . .

 - Stop task if runs longer is set to 1 day

 - If the running task  does not end . . . force it to stop

And 'Do not start a new instance' is selected

 

The History will show;

 - Event 107 - Task Triggered on Scheduler

 - Event 129 - Created Task Process

 - Event 100 - Task Started

 - Event 200 - Action Started

 

And it will sit there until I manually stop it.  I haven’t let it run for 24 hour but this task should only take seconds.

On my W7 box, this task executes and ends in under 3 minutes daily.

Any suggestions would be appreciated.

Cheers! HawkEye007

All replies (13)

Tuesday, July 9, 2019 3:04 AM

Hi,

Thanks for your question.

When you edit the action tab, you don't need to enter 'C:\Batch' as the 'Start In' option.

'start in' tab is used to make sure that if you have relative paths in the task to run it understands which directory to run the script in.

For example:

If you have write the full path of batch file in Program/script tab, you don'r need to add something in 'start in' tab.

Or:

Please try to delete 'C:\Batch' in the 'Start In' option.It works for me.

Best regards,

Lee

Just do it.


Wednesday, July 10, 2019 10:53 AM

Hi Lee,

Thanks for this explanation and confirming for me the purpose of this setting.

This was originally empty, I had found a few threads where this was recommended as a possible solution.

It has been removed and still no change in behaviour.

Hawkeye

Cheers! HawkEye007


Wednesday, July 10, 2019 11:29 AM

Set the program/script field to:

cmd.exe

Set the Add arguments (optional) to:

/c c:\YourFolder\YourBatFile.bat 1> c:\YourFolder\YourBatFile.log 2>&1

The /c tells cmd.exe to execute the bat file and then terminate. "1" is stdout, "2" is stderr. This will capture errors and any output from the bat file. You can review this to see what it did.  


Friday, July 12, 2019 12:00 PM

Great work Lee on helping identify the cause of the failure!!

Set up as described and the log file showed;

    C:\Windows\system32>C:\Batch\Outlook_Shutdown.vbs

This is a VB Script in the same 'C:\Batch' folder that closes Outlook so the files can be backed up.

The VB Script is two lines:

     Set objOutlook = CreateObject("Outlook.Application")
     objOutlook.Quit

The call for this in the batch file is:

     C:\Batch\Outlook_Shutdown.vbs
     timeout /T 10

REM'd out the above two lines and tested again.  This time the Scheduler executed and the batch file ran.

I then went back and enabled my original scheduled task entry and it also ran without any issues.

Now we have identified the cause of the failure, the question is how do we correct this?

The above VB script ran in WXP, W7, & W8.  What is different about W10?

Thanks again!

Cheers! HawkEye007


Friday, July 12, 2019 1:44 PM

Wscript.exe is the default processor for vbs files. That is the GUI version. Use the command line version so that error messages are captured into the log.

cscript.exe C:\Batch\Outlook_Shutdown.vbs


Friday, July 12, 2019 3:41 PM

Hi Lee,

I have made the recommended changes.

As noted before, the VB Script is two lines:

     Set objOutlook = CreateObject("Outlook.Application")
     objOutlook.Quit

The call for this inside the batch file is:

     cscript.exe C:\Batch\Outlook_Shutdown.vbs

When I run the batch file manually from the command line, it executes perfectly. When the Scheduler starts it, I get the following error in the log file

     C:\Batch\Outlook_Shutdown.vbs(1, 1) Microsoft VBScript runtime error: ActiveX component can't create object: 'Outlook.Application'

Not being a programmer, self taught on batch files and what I can find online to solve challenges, I am a little challenged with this one.

Thanks again for the assist.

Cheers! HawkEye007


Friday, July 12, 2019 4:44 PM

Either you don't have Outlook installed, or the version that you have installed doesn't expose that COM application.


Friday, July 12, 2019 7:18 PM

Sorry, I don't understand.

First, I have Outlook 2016 installed as part of Microsoft Office Professional Plus 2016.

The batch file runs and shuts down Outlook when it is run from the command line.

It fails when Scheduler calls the batch file.

Does the Exposure of the COM application only matter when Scheduler executes the Batch file?

How can I determine if the COM application is exposed?

Thank you,

Cheers! HawkEye007


Friday, July 12, 2019 8:59 PM

Sorry I missed the part where you said that works fine if you run it manually. 

It would appear that the script needs to run in the context of the logged on user. 

Try this.. in the task settings, set it to run as the Users group, and only when the user is logged on. 


Wednesday, July 31, 2019 8:27 AM

Hi,

Was your issue resolved?

If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

If no, please reply and tell us the current situation in order to provide further help.

Best Regards,

Lee

Just do it.


Saturday, August 3, 2019 12:17 PM

Hi, sorry for the delay. Took some needed vacation.

This script runs at night and the user isn't logged in.

The purpose of this is to run off hours without interrupting user functionality.

Why is this different in Windows 10?

Thanks.

Hawkeye007

Cheers! HawkEye007


Saturday, August 3, 2019 12:18 PM

Hi Lee,

Sorry for the delay, took some badly needed vacation.

This hasn't been resolved.  I have tested on a W8.1 set up and it works fine.  What is with Windows 10?

Thanks,

Hawkeye007

Cheers! HawkEye007


Monday, August 5, 2019 2:04 PM

This script runs at night and the user isn't logged in.

If the task is set to run when the user is logged in, and the user isn't logged in then obviously, the task is not going to run. 

The purpose of this is to run off hours without interrupting user functionality.

Why is this different in Windows 10?

I can't speak for other users, but I'm confused about what you are doing and how you have it currently configured.  Is the task set to "Run only when the user is logged on"? What account did you use? "Builtin\Users"? 

If the user is not logged on, then there is no Outlook process to shut down. 

Did you add in the logging as I had suggested? What's in the logs?