Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word automation does only work for administrator, or with a delay after creating word.application

We have a program made in Borland Delphi that uses Word automation to create documents. On an installation (terminal server) we are only able to get the Word automation to work when running as local administrator.
When runnnig as anoter user we get an error message "Opdracht mislukt -2146824090" (its dutch version of Office), wich I guess is translated to "Operation failed" or "Command failed".

The user has read/write access to the folder where the program try to put the new document.

Office 2010
64bits Windows server 2008 R2 standard

The applicaion is 32bit windows application.

If I add a delay (500ms) after the word.application is created, everything works as normall.

WordApp   := CreateOleObject('Word.Application');
sleep(500);
Doc := WordApp.documents.Open(sFile,EmptyParam,true);

Anybody knows why the CreateOleObject command now returns before the Word application can be used?

like image 536
Mike Avatar asked Nov 06 '22 07:11

Mike


2 Answers

If you want to track out that, you could use a tool like ProcessMonitor to trace the Word automation executions till the point which you can use the app.

Seems some kind of rights check is taking place - but half a second seems too much time just for this.

like image 74
Fabricio Araujo Avatar answered Nov 10 '22 19:11

Fabricio Araujo


You could try to open the Document a few times, or is Word totally borked after it gave the error?

WordApp := CreateOleObject('Word.Application');

while True do
begin
  try
    Doc := WordApp.documents.Open(sFile,EmptyParam,true);
    Break;
  except
    on E: EOleSysError do
    begin
      // raise error if it's not the expected "Command failed" error
      if E.ErrorCode <> -2146824090 then
        raise;
    end;
  end;
end;

Edit:

Please see my answer here which provides a better solution and an explanation why this happens.

like image 31
The_Fox Avatar answered Nov 10 '22 20:11

The_Fox