I have a perl web page that does some Excel manipulation, in pretty much
the same way and environment, and all runs well....  But, it's an ASP
page.

Googling the error you are getting, suggests that you might want to log
in as 'runword' and check to make sure that Word isn't asking for
install files or something weird like that, registry keys may be
missing, etc.  And also, checking the existance of the file, because CGI
may not be able to find the path you are trying to access.

if (-e $filename) {
  print "Nope, not a problem finding the file"; #I forget the syntax for
CGI output.
}

The dcomcnfg should be all you need (and perms to the file -- and, you
probably know this, but the administrators group is good for testing,
but not practical in your secure environment.)

HTH

Steven

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Tore Busch
Sent: Friday, December 03, 2004 1:48 AM
To: [EMAIL PROTECTED]
Subject: Problem with Win32::Ole and Word under ActiveState PerlEx
onWindows 2003 Server.


Problem with Win32::Ole and Word under ActiveState PerlEx on Windows
2003 Server.

The setup:
Windows 2003 Server
IIS 6.0
ActiveState Perl 5.6.1 Build 638
PerlEx 2.3.1 Build 235

I have a CGI application that needs to start Word, have it open a
document and then save that document as HTML. This is something that
works and have worked on Windows NT, Windows 2000 and Windows 2003, but
not on this one Windows 2003 server I have to install on.

It works perfectly from the 'cmd' prompt, ref 'Testscript' below.

I have requested more information about the server in question and I
hope I get that information soon, but it is obviously a server that was
installed with a very strict security policy.

To make the ODBC connection work I had to give permissions in the
Registry:
My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<odbc name>
Right click - Properties - Security. Add "Everyone".

And that is something I have never had to do before (and it took some
hours to figure it out too).

To enable us to run Word via IIS, we created a local user 'runword' on
the server. This user is made a member of the 'Administrators' group.
In dcomcnfg we set that Microsoft Word Document is to be run with
identity 'runword':
Console Root | Component Services | Computers | My Computer | DCOM
Config | Microsoft Word Document, right click and choose Properties.

The creation of the Word object seems to go fine, the problem comes in
the $ex->Documents->open() call. This produces this fine error
message...

-------------8<------------------
OLE exception from "Microsoft Word":

Command Failed

Win32::OLE(0.1701) error 0x800a1066
    in METHOD/PROPERTYGET "Open" at...
-------------8<------------------

'Everyone' got full access to the directory where the files are stored.
The Word document is uploaded by the user before it is converted by
Word, so we know that the permissions should be fine.

I am totally in the dark here. Any help appreciated.

Regards,

Tore Busch

Testscript:
----------8<---------------
#!/usr/bin/perl -w
#
# Example:
# perl test_msword.pl C:/temp/dok.doc C:/temp/

use strict; use warnings;

use Win32;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

use vars qw( %const $wd );

my $document = shift;
my $outpath  = shift;

$wd = Win32::OLE::Const->Load(".*Word.*");
%const = %{ $wd };

my $ex = Win32::OLE->GetActiveObject('Word.Application');
if (Win32::OLE->LastError()) {
    print Win32::OLE->LastError() . "\n";
}

unless( defined( $ex ) ) {
    # $ex = Win32::OLE->new('Word.Application', sub {$_[0]->Quit;});
    $ex = Win32::OLE->new( 'Word.Application', 'Quit' );
}

unless( defined( $ex ) ) {
    if (Win32::OLE->LastError()) {
        print 'Error starting MSWord: ' . Win32::OLE->LastError() .
"\n";
    }
    exit();
}
my $doc = '';

$doc = $ex->Documents->Open( {
                 FileName              => $document,
                 ConfirmConversions    => 0,
                 ReadOnly              => 1,
                 AddToRecentFiles      => 0,
                 PasswordDocument      => '',
                 PasswordTemplate      => '',
                 Revert                => 0,
                 WritePasswordDocument => '',
                 WritePasswordTemplate => '',
                 Format                => $const{'wdOpenFormatAuto'},
                 Visible               => 1,
              } );

unless( defined( $doc ) || Win32::OLE->LastError() ) {
    print "Error trying to open '$document':" . Win32::OLE->LastError()
. "\n";
    $ex->Quit();
    exit();
}

$doc->WebOptions->{OrganizeInFolder} = 0;

my $html_document = $outpath . 'test_msword.html';
$doc->SaveAs( { FileName => $html_document,
                FileFormat => $const{'wdFormatFilteredHTML'} } );
if( Win32::OLE->LastError() ) {
    print $document . ' Error saving: ' . Win32::OLE->LastError() .
"\n";

    $doc->Close(0);
    exit();
}

print "OK!\n";
----------8<---------------

-- 
Tore Busch, System Developer, Extend AS  mailto:[EMAIL PROTECTED]
http://www.extend.no/                         tlf: (+47) 73 54 61 00
Key fingerprint = 13CF 752E D5F3 A95A 6A8D  5F62 9A94 2387 C3FC AFC1

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to