2010-12-10 550 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選項對我無效。

希望這可以節省某人在某一天狩獵這種麻煩的麻煩。