Excel自动化Windows服务 [英] Excel Automation Windows Service

查看:188
本文介绍了Excel自动化Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行 Excel Interop 的Windows服务,以便自动执行各种宏。但是,当我尝试使用Windows身份验证运行访问数据库的宏时,我遇到一个特殊问题...

I have a Windows Service that runs the Excel Interop in order to automate the execution of various macros. However, I am running in a peculiar issue when I try to run a macro which access a database using Windows Authentication...

如果宏通过Windows服务运行 ,打开工作簿,并启动宏执行,但应用程序挂起(大概在数据访问部分)。

If the macro is run through the Windows Service, the workbook is opened and the macro is execution is started but the application hangs (presumably at the data access portion).

但是,如果宏通过Visual Studio调试器运行,则使用与服务相同的实现(他们称为相同的类库),它执行,保存工作簿,并按预期关闭。

If, however, the macro is ran through the Visual Studio debugger, using the same implementation as the service (they call the same class library), it executes, saves the workbook, and closes as expected.

我确定这与模拟有关,但我似乎无法想象出。我的Windows服务在我的用户下运行,我还修改了组件服务中的默认COM属性为 Impersonate 而不是默认的标识

I'm sure this has something to do with impersonation, but I can't seem to figure it out. I have the windows service running under my user and I have also modified the default COM properties in the Component Services to Impersonate instead of the default Identify.

任何帮助将不胜感激,因为最好运行为Windows服务而不是控制台应用程序。

Any help would be greatly appreciated, as it would be preferred to run as a windows service and not a console application.

推荐答案

也许我有点迟了,但是这里我还是去:

Maybe I'm a bit late, but here I go anyway:

有一个类似的问题,并通过在 C:\Windows\SysWOW64\config\systemprofile Desktop $ c>和 C:\Windows\System32\config\systemprofile

I had a similar issue and solved it by creating a Desktop folder in C:\Windows\SysWOW64\config\systemprofile and C:\Windows\System32\config\systemprofile.

似乎在Windows服务中使用时,Excel无法在特定用户下运行。因此,它使用LocalSystem服务帐户运行,并且它需要一个Desktop文件夹才能与Excel interop进行交互。

It seems that Excel is not able to run under a specific user when used in a Windows service. Therefore, it runs with the LocalSystem service account, and it requires a Desktop folder in order to interact with Excel interop.

我没有进一步的解释,但它对我有用并没有造成任何其他问题。我搜索了很多的一个确定的答案,但我发现的一切描述了解决方案,而没有指定原因。

I have no further explanation, but it worked for me and it didn't cause any other know issue. I searched quite a lot for a definitive answer, but everything I found described the solution without specifying a reason.

这篇关于Excel自动化Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆