alafarm has asked for the wisdom of the Perl Monks concerning the following question:

My perl program uses Win32::OLE to open/change/save documents in MS Word. Works fine when I run it from the command line.

However, when I schedule my task via Task Scheduler (windows server 2008) the Word process hangs (as seen in Task Manager). I suspect Word might be trying to ask a user something.

I did set these, but when run from Task Scheduler, Word never becomes visible:
$Word->{'Visible'} = 1;
$Word->{DisplayAlerts} = 0;

Can anyone think what difference it makes running the script via command line vs. Task Scheduler?

Replies are listed 'Best First'.
Re: Win32::OLE from Task Scheduler
by Anonymous Monk on Aug 08, 2011 at 19:43 UTC

    Can anyone think what difference it makes running the script via command line vs. Task Scheduler?

    Permissions

    The event log will have the relevant error message

Re: Win32::OLE from Task Scheduler
by Marshall (Canon) on Aug 09, 2011 at 05:10 UTC
    I looked at the Task Scheduler schedules for one of my Perl scripts on Windows. It's not that hard to do this.

    To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Accessories | Scheduled Tasks.

    You need to set the path that the Perl script starts - find the Perl script. Set that.
    There is a "start in" path - this is the path that the Perl script will inherit. Set that.
    There is a "run as" parameter. This is the permission level. It could be something like this: \boogie\Marshall. "boogie" is a machine name. Marshall is a user name.
    Tell us how you have done with the above directions.

      Thanks for the input:

      Setting the Start-in path didn't help

      The user I'm running as is not on the machine but one on the domain and has adminstrator privileges on the machine. I'm sure this has something to do with it.

      Note that the perl script runs, but an interesting bit is this: if I choose "Run with highest privileges" Word starts and hangs. But if I don't choose this, Word does not start at all. All the event log shows is that the perl script successfully ran and is unaware of the Word instance.

      So I think I just need to plug away at this permissions thing until I can find something that works. Maybe I'll try creating an admin user on the machine and run the task as that user. (somebody else created the one user account that's currently on the machine).

        The user I'm running as is not on the machine but one on the domain and has adminstrator privileges on the machine. I'm sure this has something to do with it.

        I suspect problems here also! While you are testing, get a simple "hello world" program to run every 2 minutes. Get that working while you are logged on and watching it. Then progress from there (does it still run when you log off, etc..).