2010-12-10 560 views
0

我尝试通过COM自动化将Excel文件转换为PDF。代码使用系统用户作为服务运行。不幸的是,我在ExportAsFixedFormat()函数中得到错误“0x800A03EC”。它在我在交互式会话中运行时起作用。ExportAsFixedFormat与Excel失败

我听说systemprofile需要一个Desktop文件夹,所以我添加了这些文件夹。

我听说过,这也可能与系统用户没有默认打印机做的,所以我增加值以下键:

HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Devices 
HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts 

但这只能使Excel中挂抛出,而不是立即例外。

我出于想法和感谢任何帮助。

+0

您在服务设置 - >登录选项卡“允许服务与桌面交互”中签入? – 2010-12-10 12:11:28

+0

是的,这是检查。 – 2010-12-10 12:31:53

回答

5

您必须为此用户选择默认打印机。尝试将以下代码导入注册表。注意:将这些打印机替换为您自己的(虚拟)打印机。

Windows Registry Editor Version 5.00 

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Devices] 
"Send To OneNote 2010"="winspool,nul:" 
"Microsoft XPS Document Writer"="winspool,Ne00:" 

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts] 
"Send To OneNote 2010"="winspool,nul:,15,45" 
"Microsoft XPS Document Writer"="winspool,Ne00:,15,45" 

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Windows] 
"UserSelectedDefault"=dword:00000000 
"Device"="Send To OneNote 2010,winspool,nul:" 

当然,你仍然有根据您的设置在

C:\Windows\SysWOW64\config\systemprofile 

C:\Windows\System32\config\systemprofile 

创建您的桌面文件夹。

完成这些步骤后,您应该能够使用常规的非交互式服务(例如Windows NT/SYSTEM用户)将Word,Powerpoint和Excel导出为PDF。你不需要任何改变你的组件服务

+0

我在此期间发现了这个消息,但既然你已经回复了,这里就是奖金。 – 2012-08-14 17:08:15

0

错误:

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Windows] "UserSelectedDefault"=dword:00000000 "Device"="Send To OneNote 2010,winspool,nul:"

正确:

[HKEY_USERS\S-1-5-18\Software\Microsoft\Windows NT\CurrentVersion\Windows] "UserSelectedDefault"=dword:00000000 "Device"="Microsoft XPS Document Writer,winspool,Ne00:"

0

我挣扎着这种强烈地和这个职位是如此接近。在尝试了许多其他的事情之后,我知道这篇文章很贴切,并且认为我会尝试一些东西。

有关记录,在运行Windows Server 2008 R2和Excel 2013自动化时,systemprofile中的“Desktop”文件夹修复了此问题。这只是我们升级到Windows Server 2012 R2和Excel 2016之后才出现的一个问题。为了消除Excel作为罪魁祸首,我尝试了使用Windows Server 2012 R2和Excel 2013的服务器,并且遇到了非常类似的问题。

网络服务下的所有自动化工作都很好,但理想情况下,我们想要在ApplicationPoolIdentity下运行我们的网站。

首先,ApplicationPoolIdentity运行的应用程序池需要加载用户配置文件。

Start Run -> inetmgr 
expand Server -> Application Pools 
right click on your App Pool -> Advanced Settings 
under Process Model -> Load User Profile <-- should be set to true 

所以现在我必须弄清楚这个身份是谁。也许有更好的方法来做到这一点,但因为我将用户添加到IIS_IUSRS,所以这是我找到信息的地方。现在

Windows -> Edit local users and groups 
Groups -> right click IIS_IUSRS -> Add to Group... 
Add... 
Locations... (choose local server), click OK 
In the Enter the object names to select box type IIS APPPOOL\<app pool name> 
    (note the space and the triple P) 
    also, <app pool name> is the name of your Application Pool in inetmgr 

你应该看到作为IIS_IUSRS IIS APPPOOL \会员(SID)其中SID是在Windows中的applicationpoolidentity安全标识符。这将是一个非常长的字母数字短划线,如“S-1-5 - ## - ######### - ######### - ######## ## - ######### - #########“

与上面的答案不同,这是我需要在注册表中编辑的用户。

因此,现在继上面的答案我不得不将以下添加到注册表。注意:向S-1-5-18添加密钥并不能解决问题,我不得不将它们添加到上面找到的ApplicationPoolIdentity的SID中。

[HKU]\SID\Software\Microsoft\Windows NT\CurrentVersion\Devices 
    "Send To OneNote 2010"="winspool,nul:" 
    "Microsoft XPS Document Writer"="winspool,Ne00:" 
[HKU]\SID\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts 
    "Send To OneNote 2010"="winspool,nul:,15,45" 
    "Microsoft XPS Document Writer"="winspool,Ne00:,15,45" 
[HKU]\SID\Software\Microsoft\Windows NT\CurrentVersion\Windows 
    "UserSelectedDefault"=dword:00000000 
    "Device"="Microsoft XPS Document Writer,winspool,Ne00:" 

请注意,我是如何使用eletre/Robert的“正确”响应。使用Device的OneNote选项对我无效。

希望这可以节省某人在某一天狩猎这种麻烦的麻烦。