Service 由域帐户运行的Windows服务在完全控制时无法访问文件

Service 由域帐户运行的Windows服务在完全控制时无法访问文件,service,excel-interop,windowsdomainaccount,Service,Excel Interop,Windowsdomainaccount,我创建了一个C#服务,它: - Picks up and opens a local text file - Opens an Excel-file used as template (saved locally) - Fills in the data from the text file in the excel file - Saves the Excel file to a network folder. 该服务使用域帐户运行(我无法从网络管理员处授予本地系统帐户在网络上的权限…)。当

我创建了一个C#服务,它:

- Picks up and opens a local text file
- Opens an Excel-file used as template (saved locally)
- Fills in the data from the text file in the excel file
- Saves the Excel file to a network folder.
该服务使用域帐户运行(我无法从网络管理员处授予本地系统帐户在网络上的权限…)。当服务尝试打开模板时,我收到一个拒绝访问错误:

Microsoft Excel cannot access the file 'C:\BloxVacation\Template\BloxTemplate.xlsm'. There are several possible reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
文件确实存在且路径正确。 该文件未被其他用户或程序使用。 我尝试打开工作簿(没有其他工作簿打开),而不是保存它

我使用系统帐户收到了相同的错误。原因是,在使用interopservices时,系统帐户需要一个桌面文件夹(Windows 7中的错误:)

创建这两个文件,系统帐户的错误就会消失

我已经授予了这些文件夹的域用户权限,错误也消失了,但是,服务挂起在我打开excel文件的代码行上。当我使用系统帐户执行完全相同的代码时,代码执行得很好(注意:我将文件保存在本地)


有人知道如何解决这个问题而不必用OpenXML重写整个服务吗?提前非常感谢。

如果您已经完成了问题中描述的所有事情,但仍然无法正常工作(就像我一样),那么答案很简单:

在运行服务的计算机上使域用户成为本地管理员。它解决了这个问题

C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
 objXL.Workbooks.Open(BloxVacationService.ExcelTemplateFilePath)