Automating Office via Windows Service on Server 2008

本小妞迷上赌 提交于 2019-11-26 17:43:27

I've had problems automating Office from a Windows Service under Windows Server 2008, even though that works fine under Windows Server 2003. The problem also occurs at the Open call, so it may be the same problem.

I tried following the advice given by H Ogawa in this MSDN thread, and it seemed to work. It's bizarre, but kudos to Mr. Ogawa for discovering it.

Summary of the 'Ogawa Hack': create a desktop folder for the system profile, as:

 C:\Windows\System32\config\systemprofile\Desktop

and, if running on a 64-bit machine, create another one, as:

 C:\Windows\SysWOW64\config\systemprofile\Desktop

Also, the folder(s) need write permission for whatever user is "driving" Office.


[Edit: corrected link URL]

[Edit 2: clarified that on 64-bit Windows, you need both folders, not just the WOW64 one]

If you are using Apache, you might also need to follow these steps to get MS Word working properly (along with everything outlined in other answers):

Below is a screenshot showing the two dialogs you'll need to bring up:

For Apache:

Services->Apache->Right Click (Properties)->Log On Tab

MS Word:

Launch dcomcnfg.exe->Console Root->Component Services->Computers->My Computer->DCOM Config->Find Microsoft Application->Right Click(Properties)->Identity Tab

**if you can't find the MS Word, make sure you are launching the correct DCOM Config (64 bit vs 32 bit) depending on what version of Office you have installed.

There are two options here, you can set Apache to use Local System Account and check the checkbox to ALLOW desktop interaction. If you do this then you need to set the Identity for MS Word to Interactive User.

Otherwise, you need to set both to the same user (Ideally the user that is logged in) like shown in the picture.

Well, you will need to run "MMC -32" (command prompt) to launch 32-bit MMC and then add Component Services (File > Add / Remove Snap-ins' menu)

then follow one of these instruction:

http://theether.net/download/Microsoft/kb/288366.html

This also happens on Vista with UAC enabled. You might want to try setting the DCOM identity to be an administrator account and test it again.

I also recently started having this problem on an XP box trying to open workbooks in Excel through interop services, but have not yet found a workaround. I myself would like any other insights the community might be able to throw out there...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!