5

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?

Mike
  • 63
  • 1
  • 8

4 Answers4

1

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.

Fabricio Araujo
  • 3,810
  • 3
  • 28
  • 43
  • The rason it works with the local administrator account, seems to be that Word starts twice as fast with this account. Not sure why dough – Mike Oct 28 '10 at 07:42
1

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.

Community
  • 1
  • 1
The_Fox
  • 6,992
  • 2
  • 43
  • 69
  • This worked perfectly for me, in a tool that worked fine against 2007, but not against 2010. Well, expect for the user who's accessing template files, on start, that exist on a network share (out of the office, so connection is extremely slow). +1 – James Skemp May 17 '11 at 20:30
  • 1
    @James Skemp: you might want to check out my stackoverflow answer here: http://stackoverflow.com/questions/5913665/word-2010-automation-goto-bookmark/5922158#5922158 – The_Fox May 18 '11 at 06:43
  • Excellent idea, so +1 (for comment and your other answer). – James Skemp May 18 '11 at 18:01
0

I realize this thread is quite old, but I solved this issue by making sure to close the document before quitting (oleDocument.Close). By doing so there is no need for any type of delays, etc. See 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;
klbass68
  • 33
  • 1
  • 8
0

The administrator account working wihtout delay, seems not to have anything with rights to do, but that Word happens to start much faster with this account than the normal domain user accounts.

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

Mike
  • 63
  • 1
  • 8
  • 1
    For a better workaround: http://stackoverflow.com/questions/5913665/word-2010-automation-goto-bookmark/5922158#5922158 – The_Fox May 18 '11 at 06:44