2

I have following code which opens visio file:

Microsoft.Office.Interop.Visio.Document vXfuncStencil = null;
var app = new Microsoft.Office.Interop.Visio.Application();
vXfuncStencil = app.Documents.OpenEx(@"C:\Program Files\Microsoft Office\Office16\Visio Content\1033\XFUNC_U.VSSX", 4);
app.Quit();

It works fine in console app but gives following error when I run through windows service:

System.Runtime.InteropServices.COMException (0x86DB03E7): An exception occurred. at Microsoft.Office.Interop.Visio.DocumentsClass.OpenEx(String FileName, Int16 Flags) 

Some notes:

  1. We run our job as Windows Service under a specific service account (also added as Local Administrator on the server)
  2. We can't find any information about the error: 0x86DB03E7.
  3. We are running code in Azure VM - windows server 2019 (64 bit), visio 2016 64 bit
  4. The same application working fine on our on-premise server. We are migrating to Azure server and it's not working. We compared all the setting on both the server.

Does anyone know what the error 0x86DB03E7 is about? Why it's not working from windows service?

Prakash
  • 789
  • 6
  • 9
  • Try opening a .vss or .vsx format stencil (there are plenty of free examples around the interwebs). Then copy the .vssx stencil into the My Documents/My Shapes folder and try from there. – Paul Herber Jun 30 '20 at 16:07
  • Have you tried to open Visio under the service account (i.e. login under the service account you are using) and see what happens? The easiest way could be, "run as different user" => select your service's account. – Nikolay Jun 30 '20 at 20:20
  • I already tried copying .vssx file to specific folder on D drive. It did not work. I am able to open visio and tried same account (have admin rights) to run the windows service. But no luck. – Prakash Jul 01 '20 at 04:26

3 Answers3

2

It worked on Windows server 2012 after doing DCOM configuration changes:

  • Install visio on the server
  • Start > Run > dcomcnfg
  • Navigate to Component Services > Computers > My Computer > DCOM Config
  • Locate Microsoft Visio 2003-2010 Drawing
  • Right click > Properties
  • On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
  • Add [Your User] and assign Local Launch & Local Activation permissions
  • On the identity tab make sure the process is set to run as "This User:" and put in the [Your User] account and password.

For Windows server 2019: We consulted Microsoft support and they said: "All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.".

Visit https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office for more detail.

They suggested to use Open XML SDK to create and manipulate visio files. Visit https://learn.microsoft.com/en-us/office/client-developer/visio/visio-file-format-reference for more detail.

Prakash
  • 789
  • 6
  • 9
  • So have you been unable to get it working in Server 2019? We are seeing the error on Server 2019 but have previously got it working on Server 2016 but the above config doesn't seem to be enough for 2019 – Doogal Jun 23 '22 at 09:11
  • For us it did not work on Windows Server 2019. So we continued using Windows server 2012. – Prakash Jun 24 '22 at 10:20
1

As described in this article, Microsoft Office applications may encounter problems when run in the context of a Windows Service. Many operations simply won't work.

To have any hope of launching Visio, you must run your service in a "regular" Windows account — one where you have installed Visio and can start it normally/interactively. A specific service account won't be sufficient if you have never installed Visio there.

CoreTech
  • 2,345
  • 2
  • 17
  • 24
0

For Visio to run as a Windows Service (in the background), make sure the folders "Desktop" and "Documents" exist under:

C:\Windows\sysWOW64\config\systemprofile

C:\Windows\system32\config\systemprofile

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
David
  • 1