Dispatch('Excel.Application') on Vista from Task Scheduler

Discussion in 'Python' started by Cupric, Nov 8, 2008.

  1. Cupric

    Cupric Guest

    I have a python script that runs fine from the command line or from
    within IDLE, but doesn't work through the Vista Task Scheduler.

    The script downloads some csv files and then uses pywin32 to combine
    the csv files into a single document. When I run it through the task
    scheduler, it downloads the csv files, but then doesn't seem to launch
    excel. I can't figure out what is wrong or how to add enough logging
    to tell.

    I'm using Python 2.6 and pywin32-212.win32-py2.6 on Vista.

    Code snippet below.

    Any ideas? Does it have something to do with permissioning on Vista?
    I'm running the task as my regular user (that has administrative
    privileges).

    Thanks,
    Theo
    ---------------
    from win32com.client import Dispatch
    .....
    excel = Dispatch('Excel.Application')
    excel.visible =0
    print 'launched excel'
    workbook =excel.Workbooks.Add()
    Sheets = workbook.sheets
    defaultWorksheets = workbook.Worksheets(1)
    excel.application.displayalerts = 0

    for port in portList:
    print 'about to open' + basePath + port.filename
    port_book = excel.Workbooks.Open( basePath +
    port.filename)
    port_sheets = port_book.Sheets

    datasheet = port_sheets(1)

    datasheet.Activate()
    datasheet.Cells.Select()

    excel.Selection.Copy()

    Sheets.Add().Name = port.name
    newsheet=workbook.Worksheets(port.name)
    newsheet.Activate()
    newsheet.Paste()

    port_book.Close(SaveChanges=0)
     
    Cupric, Nov 8, 2008
    #1
    1. Advertising

  2. Cupric

    Larry Bates Guest

    Cupric wrote:
    > I have a python script that runs fine from the command line or from
    > within IDLE, but doesn't work through the Vista Task Scheduler.
    >
    > The script downloads some csv files and then uses pywin32 to combine
    > the csv files into a single document. When I run it through the task
    > scheduler, it downloads the csv files, but then doesn't seem to launch
    > excel. I can't figure out what is wrong or how to add enough logging
    > to tell.
    >
    > I'm using Python 2.6 and pywin32-212.win32-py2.6 on Vista.
    >
    > Code snippet below.
    >
    > Any ideas? Does it have something to do with permissioning on Vista?
    > I'm running the task as my regular user (that has administrative
    > privileges).
    >
    > Thanks,
    > Theo
    > ---------------
    > from win32com.client import Dispatch
    > ....
    > excel = Dispatch('Excel.Application')
    > excel.visible =0
    > print 'launched excel'
    > workbook =excel.Workbooks.Add()
    > Sheets = workbook.sheets
    > defaultWorksheets = workbook.Worksheets(1)
    > excel.application.displayalerts = 0
    >
    > for port in portList:
    > print 'about to open' + basePath + port.filename
    > port_book = excel.Workbooks.Open( basePath +
    > port.filename)
    > port_sheets = port_book.Sheets
    >
    > datasheet = port_sheets(1)
    >
    > datasheet.Activate()
    > datasheet.Cells.Select()
    >
    > excel.Selection.Copy()
    >
    > Sheets.Add().Name = port.name
    > newsheet=workbook.Worksheets(port.name)
    > newsheet.Activate()
    > newsheet.Paste()
    >
    > port_book.Close(SaveChanges=0)
    >

    Normally this has more to do with the context that the app runs in under Task
    Scheduler not having the same environment as the logged in user. Try telling
    the Task Scheduler to run the application using the same credentials as the
    foreground user to see if that makes a difference.

    -Larry
     
    Larry Bates, Nov 9, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Codemonkey
    Replies:
    8
    Views:
    9,619
  2. =?Utf-8?B?QnJ1Y2U=?=

    Task Scheduler GUI doe not allow new tasks to be added

    =?Utf-8?B?QnJ1Y2U=?=, Jul 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    408
    =?Utf-8?B?QnJ1Y2U=?=
    Jul 13, 2006
  3. Irmen de Jong

    ANN: kronos, a task scheduler

    Irmen de Jong, May 20, 2004, in forum: Python
    Replies:
    4
    Views:
    812
    Irmen de Jong
    Jun 21, 2004
  4. Replies:
    14
    Views:
    874
    =?UTF-8?B?QXJuZSBWYWpow7hq?=
    Jun 9, 2007
  5. Replies:
    0
    Views:
    333
Loading...

Share This Page