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

I am using Win32::OLE and have written a script that succesfully starts an instance of MS-Word and performs the tasks I need. I am using Windows XP SP3. However, when I am logged off the computer and try to run the program overnight through Windows Scheduled Tasks (other perl scipts will run in this manner), the script seems to fail here: my $word = CreateObject Win32::OLE 'Word Application' or die $!; Is there a way around this when trying to execute in this state? Thanks!

Replies are listed 'Best First'.
Re: Win32::OLE and Windows Scheduled Tasks (windowstation)
by tye (Sage) on Mar 09, 2011 at 02:12 UTC

    Launching Word surely requires access to a 'desktop' (and 'windowstation'). If you aren't logged in, there may well be no desktop. (Even when you are not logged in, a Scheduled Task might not be run in a security context that gives it access to your desktop.)

    http://support.microsoft.com/kb/165194 talks about how to use CreateProcessAsUser() to have a virtual (hidden) desktop and windowstation created so a GUI application can be automated.

    I'd probably use Win32::API to be able to call CreateProcessAsUser() (which I'd use to re-launch Perl to run the script that does the real work).

    - tye        

Re: Win32::OLE and Windows Scheduled Tasks
by Anonymous Monk on May 04, 2018 at 18:25 UTC

    I realize this is an old post, but I'm posting this this in hopes of helping someone else. You have to create a "Desktop" folder.

    64-Bit:

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

    32-Bit & 64-Bit:

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

Re: Win32::OLE and Windows Scheduled Tasks
by GrandFather (Saint) on Mar 08, 2011 at 23:05 UTC

    What is the error message that the die produces?

    I've noticed with one script I run regularly that uses OLE that I often get a failure the first time I run it and it succeeds the second time. Maybe you could test the result from CreateObject and rety if it fails?

    True laziness is hard work