Automating MS Word in Server 2012 R2

automationms-officems-wordoffice-interop

Firstly, please don't reply with the generic advice not to automate Word on a server or a link to the MS web page on "how to automate word on a server if you really must". I am aware of this.

I have a process which runs as a Windows service and uses .Net OLE interop to automate Office (mostly just Open and SaveAs). This code has worked reliably for 8 years on literally hundreds of servers using many combinations of Windows and Office versions, both 32 and 64 bit, so I am happy that the mechanism is reliable. So far…

With Server 2012 R2, it works with PowerPoint and Excel but fails trying to open a word document:

System.Runtime.InteropServices.COMException (0x800A16A0): 
  The file appears to be corrupted.
   at Microsoft.Office.Interop.Word.Documents.Open...

My observations so far which may or may not be relevant:

  • fails on all documents
  • works fine in Windows 8.1
  • the same problem has happened both on a customer site and in our test environment, so is unlikely to be purely environmental
  • my application is using .Net 3.5
  • the code is linked against the 2003 Interop assemblies (obviously later office versions are supported by assembly binding redirection)
  • we have tried it with office 2013 both 32 and 64 bit with the same results, but not tried earlier versions of office
  • it fails whether the service is running as LocalSystem or as a standard user account
  • if we run the service process in the foreground (i.e. literally double-clicking on the executable) the problem does not happen

Obviously I still have things to investigate but interested to hear if anyone else has seen this specific problem even if you haven't solved it. Please note there are many difficulties and problems with office automation so unless your symptoms are very similar to mine, you probably don't have the same problem.

Best Answer

Same issues here but got this fully resolved now.

I have a Word 2013 in combination with Windows 2012 R2 Server running in a service process which does everything I want without the need of a interactive session to be started. I use this to convert documents to PDF files. Inside the Windows service I host a WCF service.

Create folders: (replace System32 with Syswow64 depending of you use x86 or x64 bit edition)

C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCac‌he C:\Windows\System32\config\systemprofile\Desktop

Last and most important step!

Start - run - dcomcnfg.exe

Open properties -> Component Services - DCOM Config - Microsoft Word 97 - 2003 Document (Note that the version is not mentioned here but that does not matter Office 2013 will use this as DCOM config)

Open tab Identity. Configure the run as a the local Administrator account. I did some tests Word 2013 will work just fine even if no interactive session is started for the user.

Related Topic