Running JetReport via Task Scheduler

I have a script that is run daily via task scheduler to generate reports with JetReport/AutoPilot.exe. Excel is installed and set up with a user named jetreport on the server that runs the task scheduled script. When running the script from cmd as this user, JetReport/AutoPilot.exe generates the reports as desired. However, if run via task scheduler then the reports are never generated but the log file still gets updated with action related information.

:: Find WeekNumber
SET /a D=1%DATE:~0,2% - 100
SET /a M=1%DATE:~3,2% - 100
SET /a Y=%DATE:~6,4%
SET /a N=(1461 * (%Y% + 4800 + (%M% - 14) / 12)) / 4 + (367 * (%M% - 2 - 12 * ((%M% - 14) / 12))) / 12 - (3 * ((%Y% + 4900 + (%M% - 14) / 12) / 100)) / 4 + %D% - 32075
SET /a T=(%N% + 31741 -(%N% %% 7)) %% 146097 %% 36524 %% 1461
SET /a W=((((%T% - (%T% / 1460)) %% 365) + (%T% / 1460)) / 7) + 1 
SET WeekNumber=WEEK %W%

:: Format Date
SET Fdate=%date:~-4,4%.%date:~-7,2%.%date:~-10,2%

:: Input file
SET Sales=Sales ver5.0.xlsx

:: Set paths
SET ReportPath=\\\share\finance\JetReport
SET AutoPilot="%ProgramFiles(x86)%\JetReports\AutoPilot.exe"
SET path2=%ReportPath%\reportset\AutoUpdate
SET Output=%ReportPath%\AutoOutput
SET logfile=%ReportPath%\reportset\Script\log\logfile_week_%W%.log

echo %DATE%	%TIME%  Generate Report daily starts >> %logfile%
::@ECHO %W% - %fdate%

:: Create output folder
IF exist "%output%\%WeekNumber%" (Echo folder exist) else (mkdir "%output%\%WeekNumber%")

:: Create Excel
::@ECHO on
echo %DATE%	%TIME%	%WeekNumber%\Sales %Fdate%.xlsx >> %logfile%
%AutoPilot% /M "VALUES" /I "%path2%\%Sales%" /O "%Output%\%WeekNumber%\Sales %Fdate%.xlsx" >> %logfile%
IF %ERRORLEVEL% neq 0 echo %DATE%	%TIME% Error Level is %ERRORLEVEL% >> %logfile%

:: Create PDF
echo %DATE%	%TIME%	%WeekNumber%\Sales %Fdate%.pdf >> %logfile%
%AutoPilot% /M "PDF" /I "%path2%\%Sales%" /O "%Output%\%WeekNumber%\Sales %Fdate%.pdf" >> %logfile%
IF %ERRORLEVEL% neq 0 echo %DATE%	%TIME% Error Level is %ERRORLEVEL% >> %logfile%
echo %DATE%	%TIME%	Generate Report daily ends >> %logfile%


Open in new window

Here is the output in the log file(but no reports):

27.04.2015      11:44:16,46      WEEK 18\Sales 2015.04.27.xlsx
27.04.2015      11:44:17,55      WEEK 18\Sales 2015.04.27.pdf
27.04.2015      11:44:18,38      Generate Report daily ends

The script is run from a UNC location. I have tried to copy the script to a local folder and change the ReportPath variable to a local folder, but that has given me the same result. I tried running the task with my domain administrator account, and that did not change the result.

The operating system of the server running the scheduled task is Windows Server 2012 R2 Build 9600.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lionel MMSmall Business IT ConsultantCommented:
Try checking the settings to run with the highest privileges and to run whether user is logged in or not; make sure hidden is not checked. If that does not work try running it "configured" for an earlier version of server (all these settings can be found on the general tab/page of scheduled tasks)
Gerwin Jansen, EE MVETopic Advisor Commented:
Try running the task with credentials of the user that has write access to that network share. The service that runs the task scheduler does not have access there.
itniflAuthor Commented:
Thank you for your replies.

Run with highest privileges: Checked
Run whether user is logged on or not: Checked
Configure for: Windows Vista, Windows Server 2008 (initial value). also tried without success:
Windows 7, Windows Server 2008 R2
Windows Server 2012 R2

The task is run with the user jetreport that has write permissions to that network share. As stated in the problem description of this thread, the scripts work when run in the cmd or powershell console when logged in as the user jetreport. So the credentials for jetreport are not the problem, or else we would experience the same problem when running with that user in the console session also. And as stated, I have tried running the scheduled task with a domain admin that has full access to all locations in question, but the task still does  not run the script so that the reports get generated. In both cases where the user jetreport or the domain admin is the runas user for the scheduled task, the log that the script generates is written to and the scheduled task is run without failure - but the reports that are supposed to be generated with JetReports\AutoPilot.exe via this script are not generated - this works in both cases only when the script is run via the console or other gui login/rdp.
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Lionel MMSmall Business IT ConsultantCommented:
please run this from a command prompt and post the results
schtasks /query /tn "Name of this task"
itniflAuthor Commented:
PS C:\Users\jetreport> schtasks /query /tn "GenerateReport_daily"

Folder: \
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
GenerateReport_daily                     30.04.2015 08:00:00    Ready
Lionel MMSmall Business IT ConsultantCommented:
my bad--what I wanted to see was schtasks /query /tn "GenerateReport_daily" /fo list to see what type of task it is, sorry
itniflAuthor Commented:
/FO   format         Specifies the format for the output.
                     Valid values: TABLE, LIST, CSV.

The /fo argument is for deciding format, here are some variations of possible results depending on the input to /fo

PS C:\Users\jetreport> schtasks /query /tn "GenerateReport_daily" /fo table

Folder: \
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
GenerateReport_daily                     30.04.2015 08:00:00    Ready
PS C:\Users\jetreport> schtasks /query /tn "GenerateReport_daily" /fo list

Folder: \
HostName:      hostnameHere
TaskName:      \GenerateReport_daily
Next Run Time: 30.04.2015 08:00:00
Status:        Ready
Logon Mode:    Interactive/Background

PS C:\Users\jetreport> schtasks /query /tn "GenerateReport_daily" /fo csv
"TaskName","Next Run Time","Status"
"\GenerateReport_daily","30.04.2015 08:00:00","Ready"

I assume you want the /V argument, for verbose:

PS C:\Users\jetreport> schtasks /query /tn "GenerateReport_daily" /fo list /v

Folder: \
HostName:                             hostName
TaskName:                             \GenerateReport_daily
Next Run Time:                        30.04.2015 08:00:00
Status:                               Ready
Logon Mode:                           Interactive/Background
Last Run Time:                        29.04.2015 14:55:52
Last Result:                          0
Author:                               domain\jetreport
Task To Run:                          \\\share\finance\JetReport\GenerateReport_daily.cmd
Start In:                             C:\Program Files (x86)\JetReports
Comment:                              Runs reports
Scheduled Task State:                 Enabled
Idle Time:                            Disabled
Power Management:                     Stop On Battery Mode, No Start On Batteries
Run As User:                          domain\jetreport
Delete Task If Not Rescheduled:       Disabled
Stop Task If Runs X Hours and X Mins: 72:00:00
Schedule:                             Scheduling data is not available in this format.
Schedule Type:                        Weekly
Start Time:                           08:00:00
Start Date:                           27.04.2015
End Date:                             N/A
Days:                                 MON, TUE, WED, THU, FRI
Months:                               Every 1 week(s)
Repeat: Every:                        Disabled
Repeat: Until: Time:                  Disabled
Repeat: Until: Duration:              Disabled
Repeat: Stop If Still Running:        Disabled
Lionel MMSmall Business IT ConsultantCommented:
I don't see anything wrong. Just to be sure can you look at the export of the scheduled task (right click on it and choose export) and see if you see anything wrong--from the above I don't think you will but shouldn't take too long. Them can you rename the .cmd to ,bat and see if that will make a difference--thanks.
itniflAuthor Commented:
Tried to export and see if there is anything to catch the eye, the xml and all the settings look fine. I tried renaming to bat and pointing to the renamed bat file in the task - it didn't make any difference.
Lionel MMSmall Business IT ConsultantCommented:
The final thing I have to suggest is to delete the scheduled task and recreate it. I have had success doing this in the past. I have also requested to have some other experts look at your question as this is the final suggestion I can think of right now (hopefully it works).
Does it work when you are logged in as the jetreport user, with the task set to "run only when user is logged on"?
Bob LearnedCommented:
Do you have a log file for JetReport?

How to Generate a Jet Essentials Log File

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.