Word Automation only works for the administrator or with a delay after creating word.application

We have a program created in Borland Delphi that uses Word to create documents. On the installation (terminal server), we can only make Word Automation work at startup as a local administrator.
When runnnig as anoter user, we get the error message "Opdracht mislukt -2146824090" (its Dutch version of Office), which I believe is translated into "Operation failed" or "Command failed".

The user has read / write access to the folder in which the program tries to place a new document.

Office 2010
64-bit Windows Server 2008 R2

Application - 32-bit Windows application.

If I add a delay (500 ms) after creating the word. application, everything works as normal.

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

Does anyone know why the CreateOleObject command now returns before the Word application can be used?

+5
source share
4 answers

The delayed admin account does not seem to have any execute rights, but for this account this is faster than regular domain user accounts.

I can live with a delay, but if anyone knows a better way, let me know.

0
source

, , ProcessMonitor, Word , .

, - - .

+1

, Word , ?

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 not the expected "Command failed" error
      if E.ErrorCode <> -2146824090 then
        raise;
    end;
  end;
end;

Edit:

, . , , .

+1
source

I understand that this thread is pretty old, but I solved this problem by making sure you closed the document before exiting (oleDocument.Close). Thus, there is no need for any delays, etc. See the Delphi code snippet below.

Example:

  oleWord     := Unassigned;
  oleDocument := Unassigned;

  Screen.Cursor := crHourGlass;

  try
    oleWord               := CreateOleObject('Word.Application');
    oleWord.Visible       := False;
    oleWord.DisplayAlerts := False;

    oleDocument := oleWord.Documents.Open(Worklist.Filename);
    oleDocument.SaveAs(Worklist.Filename, wdFormatDOSTextLineBreaks);

    oleDocument.Close;
    oleWord.Quit(False);
  finally
    oleDocument := Unassigned;
    oleWord     := Unassigned;

    Screen.Cursor := crDefault;
  end;
0
source

All Articles