4

On Windows Server 2008, i was scheduling a task to run a batch file which in turn will trigger a console application. When double clicked on the application, its running perfectly. But when ran from the task scheduler i was getting the below error in the logs.

exception from hresult 0x800a03ec

The ID with which i was logged in and running task scheduler had full admin rights.

I had tried these solutions.. Batch File runs manually but not in task scheduler

Batch file called by scheduled task throws error when scheduled, runs fine when double clicked

Batch runs manually but not in scheduled task

But the issue is not resolved. Infact when ran from task scheduler its triggering both success and exception mails in the console application. But this is not the case when ran manually. Need help!!

Note: All the output reports i am processing through console application will be in .xlsx format.

The batch file is as mentioned below

@ECHO. 
@ECHO /***************************************************************/ 
@ECHO               Report Application 
@ECHO /**************************************************************/
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( 
            Set Month=%%A
            Set Day=%%B
                Set Year=%%C
)

 SET DRV=E:\ReportApplication
cd %DRV%\bin\Release\

ReportSolution.exe >> %DRV%\Log\ReportSolutionlog%Month%%DAY%%Year%.txt
cd\
cd %DRV%


@ECHO  Application is completed successfully
@ECHO /**********************************************/
Community
  • 1
  • 1
1Sherlock
  • 81
  • 2
  • 9

2 Answers2

3

Finally the issue had been resolved. I do not think the problem is any way with the batch file or with the application.

This solution is in...

・Windows 2008 Server x64

Please create this folder.

C:\Windows\SysWOW64\config\systemprofile\Desktop

・Windows 2008 Server x86

Please create this folder.

C:\Windows\System32\config\systemprofile\Desktop

...instead of dcomcnfg.exe.

This operation took away office automation problems in my system.

A Desktop folder seems to be necessary in the systemprofile folder to open file by Excel.

It disappears from Windows2008, Windows2003 had the folder, and I think it cause this error.

I found this answer in the link mentioned below. Answer by Ogawa.

https://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64?forum=innovateonoffice

But i do not have any idea how by creating a empty folder had solved the issue. But it works.. Hope this will be helpful for some one with similar issue

1Sherlock
  • 81
  • 2
  • 9
  • That is indeed very interesting. It would be also interesting if adding above call of `ReportSolution.exe` first the line `if not exist E:\ReportApplication\Desktop md E:\ReportApplication\Desktop` and second the line `set "USERPROFILE=E:\ReportApplication"` in case of Excel checks for folder `%USERPROFILE%\Desktop`. This will not work if Excel gets profile directory of system account directly from Windows registry. – Mofi Apr 29 '15 at 12:29
0

Following 2 lines could be a problem:

SET DRV=E:\ReportApplication
cd %DRV%\bin\Release\

cd without parameter /D does not change current drive. So with current working directory being C:\Windows\System32 as usual on running a batch file with task scheduler, the directory change does not work and %SystemRoot%\System32 (that's better) remains current working directory.

On double clicking a batch file, Windows sets the directory of the batch file as current working directory. This results in a working batch file on double click when it is located on drive E:.

Solution is:

SET "DRV=E:\ReportApplication"
cd /D "%DRV%\bin\Release\"
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • I had made the changes you had mentioned but still there is no change with the situation. When i double clicked and started application from batch file its working fine. I had also observed that exception is coming in production application while opening and writing into excel sheet.This happens only when ran through Task scheduler. Any other suggestion? – 1Sherlock Apr 24 '15 at 12:08
  • Thanks for you help in trying to solve the issue. It had been resolved. The code related to excel and xls were written in the reportapplication.exe mentioned in the batch file. This batch will just run the application and creates Log file. – 1Sherlock Apr 29 '15 at 09:44