Task scheduler wont run my .net console app

211 Views Asked by At

I have an app to write data into excel. It works well when I run the .exe manually by double clicking it. Now I want to run is as a scheduled task, but see a .net error in the event viewer:

System.Runtime.InteropServices.COMException at Microsoft.Office.Interop.Excel.Workbooks.Open(System.String, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object, System.Object))

Below is the partial code:

    Dim testworkbook As Workbook = Nothing
    Dim testworksheet As Worksheet = Nothing
    Dim countcell As Integer = 1
    Dim failcell As Integer = 3
    Dim Machine As String
    Dim WMBBdate As String
    Dim OSCmachine As String
    Dim OSCdate As String

    Dim xls As New Microsoft.Office.Interop.Excel.Application
    xls.DisplayAlerts = False
    xls.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow


    testworkbook = xls.Workbooks.Open("\\YY088132\Users\310288557\Desktop\Virtual Line auto email\Test3.xlsx")
    testworksheet = testworkbook.Worksheets("Sheet1")
    testworksheet.UsedRange.Clear()
    testworksheet.Cells.Font.Color = ColorTranslator.ToOle(System.Drawing.Color.Black)

I suspect it stops at line that open workbook.

I have tried every possible solution that I found on google such as:

  1. create Desktop folder at syswow64 and system32
  2. DCOM config
  3. And more.
0

There are 0 best solutions below