Link to home
Start Free TrialLog in
Avatar of fireguy1125
fireguy1125

asked on

Server 2008 R2 Batch File Scheduled Task Not Completing

I have 2 scheduled tasks that are both set to start a program, which is a *.bat file.

One of the scheduled tasks specifies a batch file, with the contents of that batch file containing a vbs file.  When executed manually it runs without issue, only through scheduled tasks it does not run.

I use the same account credentials in the task that I do when it runs.  I've also specified both just the Program/Script setting as the batch file, and also the Start in (optional) parameter in the folder path of where the batch file is located, and it still does not complete.

I have the same issue with another scheduled task that is a batch file, where the contents of that batch file is just a path to an Excel document.  Again, when the batch file is executed manually it works without issue, but does not work through scheduled tasks.

Other settings I have configured as:

Run as the following user: same domain user account that is used to run it manually
Run whether user is logged on or not
Run with highest privileges
Configure for Server 2008
Avatar of Sudeep Sharma
Sudeep Sharma
Flag of India image

Is there anything in the event logs about the task which are executed?

When you try to run the task from the TaskScheduler and choose it to run, does it run then?

Sudeep
Avatar of fireguy1125
fireguy1125

ASKER

When I execute it by right click and run in task scheduleder, it shows status of the task is currently running.  

The time it takes to execute the batch file manually (without task scheduler) is under 5 seconds.  But I let the task run for several minutes and it still stays at the task is currently running, by that point I end the task manually.

Here are the events in my event viewer when I run the task, and then cancel it manually after 5 minutes because it does not complete:


Task Scheduler launched "{a73a1227-03d3-4d21-a114-2a20db12db92}"  instance of task "\Convert XLSX to XLS"  for user "TaskAdmin" .

Task Scheduler started Task Engine "S-1-5-21-1471991497-2808089978-3145653412-13858:DOMAIN\TaskAdmin:Password:Highest"  process. Command="taskeng.exe" , ProcessID=5644, ThreadID=5128

Task Scheduler started Task Engine "S-1-5-21-1471991497-2808089978-3145653412-13858:DOMAIN\TaskAdmin:Password:Highest"  process.

Task Engine "S-1-5-21-1471991497-2808089978-3145653412-13858:DOMAIN\TaskAdmin:Password:Highest"  received a message from Task Scheduler service requesting to launch task "\Convert XLSX to XLS" .

Task Scheduler started "{a73a1227-03d3-4d21-a114-2a20db12db92}" instance of the "\Convert XLSX to XLS" task for user "DOMAIN\TaskAdmin".

Task Scheduler launched action "xlsconvert.bat" in instance "{a73a1227-03d3-4d21-a114-2a20db12db92}" of task "\Convert XLSX to XLS".

Task Scheduler launch task "\Convert XLSX to XLS" , instance "C:\Windows\SYSTEM32\cmd.exe"  with process ID 4264.

Task Engine "S-1-5-21-1471991497-2808089978-3145653412-13858:DOMAIN\TaskAdmin:Password:Highest"  received a message from Task Scheduler service requesting to stop task instance "{a73a1227-03d3-4d21-a114-2a20db12db92}" .

Task Scheduler stopped instance "{a73a1227-03d3-4d21-a114-2a20db12db92}"  of task "\Convert XLSX to XLS"  as request by user "DOMAIN\TaskAdmin" .

Task Scheduler terminated "{a73a1227-03d3-4d21-a114-2a20db12db92}"  instance of the "\Convert XLSX to XLS"  task.
Does any of your batch has ability to generate the log? Just making sure if we have anything in the logs which could point to the issue.

Sudeep
Also, trying several combinations, I found that when the option to Run only when user is logged on is checked, it works.  It only seems to not work when I have the option to Run whether user is logged on or not.  How can I make it so it does.
No, the contents of my batch files are very simple:

1st batch file (renames file extension  by using a vbs script):

C:\Scripts\xlsx2xls.vbs "C:\Reports\FromHR\active.xlsx" "C:\Reports\Rename\active.xls"

2nd batch file (executes xls file):

C:\Reports\Rename\active.xls
So where are the files getting written or created?

Is this server in the domain?

Are you sure you are not writing to the User Profile which is on the File server?

Sudeep
The files are getting created in a specified folder C:\Reports, C:\Reports\HR Reports, and C:\Reports\Rename directories.  I have verified all of these directories have full access permissions for the domain user account specified for scheduled tasks (it is the same domain user account I am logged into the server as well).

Yes, the server is on our domain.

No, there is nothing in the batch writing to local user profiles.
What are you calling in your vbs script to do the conversion?  Does it pop up a dialog box?  Programs that need to pop up a dialog box can't run if you're not logged in.  Maybe you need to run a different program or figure out a switch to silence the dialog.
The contents of my vbscript is:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(Wscript.Arguments(0))
objExcel.Application.Visible = False
objExcel.Application.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs Wscript.Arguments(1), 56
objExcel.ActiveWorkbook.Close
objExcel.Application.DisplayAlerts = True
objExcel.Application.Quit
WScript.Quit

Open in new window

You don't need to use .Application here - skip that for making the script more simple.
Replace objExcel.ActiveWorkbook with objWorkbook.
That won't change the behaviour, but is better practise. In particular since accessing "Active*" is prone to failures, if e.g. the user or other applications perform actions while running the VBA/VBS code.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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
Thanks for all your patience and help.