Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

phpmyadmin fehler rechte unerlaubte mischung, WWWXXXApc, lilo trying to map files from unnamed device 0x0000", Wwwxxxapc, CAM::PDF::Renderer::TextF Fragen, adodb.recordset error '800a0cc1', php save mails as eml, WWWXXXAPC, sqlexpress database file auto-creation error, sqlexpress database file auto-creation error



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

Posted on 2004-12-07 09:45:05 by Tore Busch

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
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
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...

OLE exception from "Microsoft Word":

Command Failed

Win32::OLE(0.1701) error 0x800a1066

'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.


Tore Busch

#!/usr/bin/perl -w
# Example:
# perl 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";
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();

$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";


print "OK!\n";

Tore Busch, System Developer, Extend AS tlf: (+47) 73 54 61 00
Key fingerprint = 13CF 752E D5F3 A95A 6A8D 5F62 9A94 2387 C3FC AFC1

Report this message