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

From: Tore Busch (tore.busch_at_extend.no)
Date: 12/07/04


Date: Tue, 07 Dec 2004 09:45:05 +0100

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
(SharePoint is installed and used)

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:tore.busch@extend.no
http://www.extend.no/                         tlf: (+47) 73 54 61 00
Key fingerprint = 13CF 752E D5F3 A95A 6A8D  5F62 9A94 2387 C3FC AFC1


Relevant Pages

  • Re: WORD 98 cant open WORD 2004
    ... and ensure that the "Type:" is shown as Microsoft Word Document. ... Windows has not "required" file extensions for years, ... Consultant Technical Writer ...
    (microsoft.public.mac.office.word)
  • RE: Configured Identity incorrect for COM applications using Windows 2000 server
    ... Configured Identity incorrect for COM applications using Windows ... MS-Word 2000 SR-1 is installed on the server for this purpose. ... The properties for the Microsoft Word application are configured using ... the utility that allows configuration of COM applications. ...
    (microsoft.public.win2000.security)
  • RE: Configured Identity incorrect for COM applications using Windows 2000 server
    ... Configured Identity incorrect for COM applications using Windows ... MS-Word 2000 SR-1 is installed on the server for this purpose. ... The properties for the Microsoft Word application are configured using ... the utility that allows configuration of COM applications. ...
    (microsoft.public.win2000.active_directory)
  • Re: Why is Windows Automatically Renaming Documents I save with a "~$"
    ... sudden Windows started renaming any Microsoft Word document I open ... "New Communication Log". ... are not a PART of Windows XP --> they are seperate products. ...
    (microsoft.public.windowsxp.general)
  • Re: Arrrrrrrgh! Context Menu Handlers !
    ... How to Add Items to the "Send To" Menu in Windows XP ... Or in New | Microsoft Word Document? ... Right click point to New and select Microsoft Word Document. ... I tried the Powertoy Tweak UI JJS mentions in the link but that doesn't ...
    (microsoft.public.windowsxp.customize)