+ Reply to Thread
Results 1 to 3 of 3

Slight problem automating Excel in a service

  1. #1
    someone
    Guest

    Slight problem automating Excel in a service

    I hope someone can help me out here.

    I'm using VB.Net and VS .Net 2003 to write code that automates Excel 2003.
    Basically, a FileSystemWatcher object watches a folder and it's subfolders
    if a user desires. If an Excel generated HTM files is output to the
    folder(s), the FSW detects the creation of the file, loads it into Excel in
    the background (visible = false), and prints out the document.

    I wish I had a copy of the code to paste (forgot to bring some home with
    me). Basically, I let the program thread sleep for 1 second (to ensure the
    file is fully written out), I just create an Excel Workbook object in code,
    add the HTM file to it to load it up, I print the document out, then I set
    saved to true so I won't get a prompt asking me to save the file, then I
    quit/close the application.

    The code itself runs fine. I developed and tested the code in a desktop
    application. I could run it, set the program to watch a folder, and
    whenever such a file is written to the directory, Excel loads up in the
    background, prints it out, and closes itself just fine.

    Problem: I needed this code to run in a service so the files will always
    print out because someone won't always be logged in. So, I created a
    service and copied the code into the service. At first, it wouldn't work.
    After debugging the service and looking at task manager, it appears Excel
    starts up but for some reason hangs in the background. I noticed while
    stepping through the code in the service it appears to stop at the line
    where the file is being loaded into Excel and stays there until I shut down
    the Excel program running in the background via task manager. Once I do
    this, I get some sort of an error message I can't recall at the moment (the
    code is inside a try...catch block). After reading up on services and such,
    I decided to set the account the service runs under from localsystem to
    user. Once I do this, I get asked for a userid and password upon
    installation of the service. Once I do this, I can start the service. Once
    I do this, the service runs fine and does what it's supposed to i.e. it
    prints out the document that's inserted into the specified directory. I
    created an administrative account on the local machine and set the service
    to this. Funny thing is, it wouldn't work using the admin account on the
    machine. Same problem as before (Excel hanging in background upon load of
    file into Excel). It seems to work fine when entering an admin account from
    the Network/domain.

    The code ran fine while in a program and it runs fine fine after I set the
    service run account to user while entering a userid/password during the
    service install. As such, I'm left to conclude there is some sort of a
    security problem. Thing is, the service was initially set to run under the
    localsystem account. I thought setting the service to this account type
    would let it do anything, but apparently I was wrong. Any ideas on how to
    fix this?

    Thanks for any advice.

    Chris Smith



  2. #2
    Lee Gillie
    Guest

    Re: Slight problem automating Excel in a service

    I have found it to work best with a privileged domain user. I have not
    had problems automating office from a service, just in getting the
    processes to go away when I am done with them.

  3. #3
    someone
    Guest

    Re: Slight problem automating Excel in a service

    Any idea why? It must be possible to do this. We have purchased a product
    that creates Excel based reports for us. It doesn't use a Domain based
    userid. Although I think we did have to create an administrative userid and
    password but it was a new user on the machine, not the domain. Yet, this
    process works fine as it's a service that runs as a Localsystem account.
    There must be a way to do this. I just don't know how.

    Thanks!

    Chris Smith

    "Lee Gillie" <Lee@nospam.odp.com> wrote in message
    news:OQZvjv$VFHA.2124@TK2MSFTNGP14.phx.gbl...
    >I have found it to work best with a privileged domain user. I have not had
    >problems automating office from a service, just in getting the processes to
    >go away when I am done with them.




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1