简体   繁体   English

使用Interop.domino.dll的C#控制台应用程序 - 在作为计划任务运行时失败

[英]C# console app using Interop.domino.dll - failing when running as Scheduled Task

I have written a C# console application that uses the Interop.domino.dll assembly to interact with domino / notes to create, update and delete documents. 我编写了一个C#控制台应用程序,它使用Interop.domino.dll程序集与domino / notes交互以创建,更新和删除文档。 The application runs successfully when running it manually through a cmd prompt or through Visual Studio. 通过cmd提示符或Visual Studio手动运行应用程序时,应用程序成功运行。 However, when we try to set the application up as a scheduled task (running under a domain service account) it fails with the following error: 但是,当我们尝试将应用程序设置为计划任务(在域服务帐户下运行)时,它会失败,并显示以下错误:

  • System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {29131539-2EED-1069-BF5D-00DD011186B7} failed due to the following error: 80004005 Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)). System.Runtime.InteropServices.COMException:由于以下错误,检索具有CLSID {29131539-2EED-1069-BF5D-00DD011186B7}的组件的COM类工厂失败:80004005未指定错误(来自HRESULT的异常:0x80004005(E_FAIL))。

The error occurs as soon as we try to use an object from the Interop.domino.dll, specifically when try to create an instance of the NotesSession object as per the following: 一旦我们尝试使用Interop.domino.dll中的对象,就会发生错误,特别是在尝试按以下方式创建NotesSession对象的实例时:

  • ISession notesSession = new NotesSession(); ISession notesSession = new NotesSession();

After some investigation I found that the interop assembly requires a desktop to interact with and that if we ran the scheduled task with the service account logged into the machine that the scheduled was running on the scheduled task would run successfully. 经过一些调查后,我发现互操作程序集需要桌面进行交互,如果我们运行计划任务,并且登录到计划的服务帐户计划任务上运行的计划任务将成功运行。 While logged in as the service account you could see that the application would bring up a svchost.exe window while the application was running and that is the reason it requires the desktop. 以服务帐户登录后,您可以看到应用程序在应用程序运行时会显示svchost.exe窗口,这就是它需要桌面的原因。

However, having the service account logged into the machine all the time is not an acceptable solution as it means that the account has to be logged in again each time the server restarts. 但是,让服务帐户始终登录到计算机并不是一个可接受的解决方案,因为这意味着每次服务器重新启动时都必须再次登录该帐户。 There are also some security concerns around having about allowing a service account to login to machines. 关于允许服务帐户登录计算机还存在一些安全问题。

So, I was wondering if anyone had any suggestions on how to get around this issue? 所以,我想知道是否有人对如何解决这个问题有任何建议? Is there a way to suppress any UI that the assembly tries to show? 有没有办法抑制程序集试图显示的任何UI? Alternatively, can anyone suggest an alternate to a scheduled task which would achieve a similar result. 或者,任何人都可以建议替代计划任务,以达到类似的结果。 What we need to do is: 我们需要做的是:

  • Have the application run at a set interval (IE - once a day / once an hour) 让应用程序以设定的间隔运行(IE - 每天一次/每小时一次)
  • Ideally, have it run under a domain service account (as opposed to a local system account) 理想情况下,让它在域服务帐户下运行(而不是本地系统帐户)
  • Run without requiring the service account to be logged into the machine / UI elements from the Interop.domino.dll suppressed 运行时无需将服务帐户登录到Interop.domino.dll抑制的机器/ UI元素中

We have thought about writing a similar application making use of the notes web services rather than the Interop assmebly and will go down that path if we can't get the console app running as a scheduled task. 我们已经考虑过编写一个类似的应用程序,使用notes web服务而不是Interop,并且如果我们无法将控制台应用程序作为计划任务运行,那么它将沿着这条路走下去。 However, we would like to make use of what I have already written if possible. 但是,如果可能的话,我们想利用我已经写过的内容。

Update 01/05/12 更新01/05/12

I have tried etting the NOTESNTSERVICE OS environment variable as per @dna-man solution. 我已经尝试按照@ dna-man解决方案编写NOTESNTSERVICE OS环境变量。 However, this did not solve the issue. 但是,这并没有解决问题。

For now we have set the application up as a windows service running under the local system account and with interactivity with the desktop allowed. 目前,我们已将应用程序设置为在本地系统帐户下运行的Windows服务,并允许与桌面交互。 This is not ideal as it does not allow us to schedule it as easily and it is not running under a domain service account, but the application does work so we will go with this approach for now. 这并不理想,因为它不允许我们轻松地安排它并且它不在域服务帐户下运行,但应用程序确实有效,所以我们现在将采用这种方法。

There was an answer that suggested this approach, but it seems to have been removed so I can't mark it as correct. 有一个答案暗示了这种方法,但似乎已被删除,因此我无法将其标记为正确。 I might leave the question open a bit to see if anyone else has any suggestions. 我可以稍微打开这个问题,看看是否有其他人有任何建议。

If your code is running on a Domino server you must make sure the OS environment variable NOTESNTSERVICE=1 is set. 如果您的代码在Domino服务器上运行,则必须确保已设置OS环境变量NOTESNTSERVICE = 1。 You can find out more abou this environment variable in the Lotus C API documentation, but it applies to the COM API as well when running as a service. 您可以在Lotus C API文档中找到更多此环境变量,但它在作为服务运行时也适用于COM API。 I had created way back in 2003 a VB.NET application that had to run as a service, and setting this environment variable was the key. 我在2003年创建了一个必须作为服务运行的VB.NET应用程序,并设置此环境变量是关键。 If it wasn't set, the service would stop working as soon as I logged off the machine. 如果未设置,则一旦我注销机器,服务就会停止工作。 To make sure somebody didn't forget to set this environment variable when installing the service in the future I simply had my service manager start code set this environment variable directly on startup using the VB.NET call to SetEnvironmentVariable. 为了确保有人在将来安装服务时不忘记设置此环境变量,我只需让我的服务管理器启动代码在启动时使用对SetEnvironmentVariable的VB.NET调用直接设置此环境变量。 It had to be set before creation of the Domino session object. 必须在创建Domino会话对象之前设置它。

It's hard to say exactly why, but I believe it's failing to read the registry information for the Lotus interop classes. 很难确切地说出原因,但我认为它无法读取Lotus互操作类的注册表信息。 Obviously the entries are there, otherwise it would not work while running manually. 显然条目存在,否则在手动运行时不起作用。 So let's consider other possibilities. 所以让我们考虑其他可能性。

I don't even know if this is possible, but os your application running as 32 bit when run manually, but 64 bit when scheduled? 我甚至不知道这是否可行,但是你的应用程序在手动运行时以32位运行,但在计划时运行64位? IBM doesn't support the Domino COM classes on Win64, and I'm pretty sure that the first symptom of that is that the registry l IBM不支持Win64上的Domino COM类,我很确定第一个症状就是注册表l

A more mundane possibility is that the service account just doesn't have access to read the registry entries for the Notes/Domino install on the machine, possibly because the software was installed under a specific user account. 更普通的可能性是服务帐户无权读取计算机上Notes / Domino安装的注册表项,可能是因为该软件是在特定用户帐户下安装的。

I ended up modifying the application slightly to set it up as a windows service running under the local system account and with interactivity with the desktop allowed. 我最后稍微修改了应用程序,将其设置为在本地系统帐户下运行的Windows服务,并允许与桌面交互。 This is not ideal as it does not allow us to schedule it as easily and it is not running under a domain service account. 这并不理想,因为它不允许我们轻松地安排它并且它不在域服务帐户下运行。 However, this approach does allow the application to run without requiring an account to always be logged in and does allow for the interop UI elements to be shown (thus avoiding the error). 但是,此方法确实允许应用程序运行而无需始终登录帐户,并且允许显示互操作UI元素(从而避免错误)。

To schedule the windows service to perform the task at a set interval (which I set at once a day) I used the Timer solution proposed here . 为了安排Windows服务以设定的间隔(我每天设置一次)执行任务,我使用了此处提出的Timer解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 执行Excel Interop的C#控制台应用程序 - 按计划运行时失败任务-System.UnauthorizedAccessException - C# console app that does Excel Interop - failing when running as scheduled Task -System.UnauthorizedAccessException 使用 c# Interop.domino.dll 使用管理员帐户创建 NotesSession - Create NotesSession with Admin Account using c# Interop.domino.dll 如何使用“ Interop.Domino.dll”(C#)获取Lotus Notes密码(在本地计算机上)? - How to get Lotus Notes Password (on local machine) using “Interop.Domino.dll” (C#)? 使用 interop.domino.dll c# 在 .nsf 文件中创建新文档,特别是用户下的联系人 - Create new document in .nsf file using interop.domino.dll c# specially a contact under user 如何使用 interop.domino.dll c# 程序获取“Internet 域”和“地址名称格式”? - How to get the "Internet Domain" and "Address name format" using interop.domino.dll c# program? 如何使用c#和interop.domino.dll的用法在Domino服务器中插入新的注释文档? - how to insert a new notes document in the domino server with c# and the usage of interop.domino.dll? 使用Interop.Domino.dll读取Lotus Notes和Domino邮箱 - Reading Lotus Notes & Domino Mailbox using Interop.Domino.dll 使用“ Interop.Domino.dll”从Domino服务器访问“ mail \\ ServerMailFile.nsf”文件中的邮件 - Accessing mails from “mail\ServerMailFile.nsf” file from Domino Server using “Interop.Domino.dll” 如何使用INTEROP.DOMINO.DLL从Lotus Notes RichText字段获取链接,图像数据 - How to get link, image data from Lotus Notes RichText field using INTEROP.DOMINO.DLL 具有Excel Interop的C#控制台应用程序作为Windows计划程序/ ActiveBatch上的计划任务挂起 - C# Console App with Excel Interop hangs as a scheduled task on Windows scheduler/ActiveBatch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM