.net应用程序通过计划任务触发时失败 [英] .net application failing when fired via scheduled task

查看:144
本文介绍了.net应用程序通过计划任务触发时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用c#编写的.net控制台应用程序,该应用程序在Visual Studio中运行时以及在文件系统中单击.exe文件时,完全可以实现它的功能。它像魅力一样运转。但是,当我在Windows 7开发机或Windows 2008 R2生产机中创建计划的Windows任务时,它无法执行应用程序中的最后一步。此步骤是在后台打开.doc并将其隐蔽(只需运行另存为)到.docx。

I have a .net console application written in c# which does exactly what it should when run inside visual studio and when clicking the .exe file in the file system. It runs like a charm. BUT when I create a scheduled windows task either in my Windows 7 dev machine or the Windows 2008 R2 prod machine it fails to carry out the last step in the application. This step is to open a .doc in the background and covert it (simply running a save as) to a .docx.

该应用程序旨在访问网络路径,创建一个没有问题的〜Converted目录,然后发现每个.doc在后台打开,执行另存为,然后将do的.docx版本保存在〜Converted目录中。我相信代码没有错,因为它可以在计划任务之外生成和运行而不会出现问题。我已经探索了任务中的每个设置,进行了更改并重新测试均未成功。我正在与属于管理员组的用户一起运行它,IMO权限不是问题。我已经用NETWORK SERVICE帐户尝试过,结果还是一样。

The application is designed to visita network path, create a dir called ~Converted which it does not problem and then for each .doc it finds it opens in background, performs a save as and them saves a .docx version of the do in the ~Converted dir. I believe there is nothing wrong with the code since it builds and runs without issue outside of the scheduled task. I have explored every setting inside the task, made alterations and re-tested with no success. I am running it wit a user who is part of the administrators group, IMO permissions is not the issue. I have tried it with the NETWORK SERVICE account, same result.

仅在通过计划任务运行时才生成的实际堆栈跟踪错误是:

The actual stack trace error which is only being generated when run through the scheduled task is:


System.UnauthorizedAccessException:由于以下错误,检索具有CLSID {000209FF-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED)。)

System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

执行此操作的代码行是:

The line of code which is doing this is:

Application oWord = new Application();

我在此搜索了数小时,没有发现任何帮助。当代码打开/初始化单词doc时,似乎似乎通过任务运行代码会导致COM访问问题。拥有完整的管理员特权,以最高特权运行以及无论用户是否登录都可以使任务变得有趣。正如我说过的,所有这些设置都已发挥作用,但并没有改变。

I have search for hours on this and found nothing helpful. It seems like running the code via the task is causing a COM access issue when the code is opening/initializing the word doc. The task is being fun with full admim privileges, running with highest privileges and when the user is logged on or not. As I said all these setting have been played with, it has not made a difference.

现在已经到了必须重新编写此控制台的阶段应用程序即服务如果我不能解决此问题。希望有人可以为我节省一整天的额外工作,并帮助我解决这个问题?

It has got to the stage now where I will have to re-write this console application as a service If I cant solve this issue. Hopefully somebody can save me a full days extra work and help me with the issue??

添加-根据下面的@Dmitry Martovoi帖子,我为每个用户添加了滴答声并且堆栈跟踪已更改为:

Adding - Based on @Dmitry Martovoi post below I have added ticks for the EVERYONE user and the stack trace has changed to:


System.NullReferenceException:对象引用未设置为对象的实例。

System.NullReferenceException: Object reference not set to an instance of an object.

指向同一saveAs函数中的该行:

which is pointing to this line inside the same saveAs function:

oDoc.Close(false, Type.Missing, Type.Missing);

添加-我一直在更改拥有此路径的用户,非常不确定是哪个用户在运行它这是生成的。这是一个应用程序事件日志erorr。注意-仅在通过任务计划程序运行应用程序时会发生这种情况:

Adding - I have been changing users who own this path that much im not sure which user was running it this was generated. here is an application event log erorr. NOTE - This only happens when running the application via task scheduler:

Faulting application name: WINWORD.EXE, version: 14.0.6129.5000, time stamp: 0x5082f340
Faulting module name: btmofficea.dll, version: 3.0.2.280, time stamp: 0x4cc57919
Exception code: 0xc0000005
Fault offset: 0x0000000000005e1f
Faulting process id: 0x2a6c
Faulting application start time: 0x01ce8bec64ccf85d
Faulting application path: C:\Program Files\Microsoft Office\Office14\WINWORD.EXE
Faulting module path: C:\Program Files\Motorola\Bluetooth\btmofficea.dll
Report Id: a393403d-f7df-11e2-b68c-74de2b9ca154

确定的问题已解决。从链接中可以看到,@ dmay粘贴的MS不建议在服务器端无人看管的情况下运行Office应用程序,并说这不受支持。但是,解决方案却步履维艰@Dmitry前进了:

OK problem is fixed. As can be seen in the link @dmay pasted MS do not recommend running office applications unattended on the server side and says this is unsupported. However the solution was down the track @Dmitry was headed:

1)开始->运行-> dcomcnfg

1) Start->Run->dcomcnfg

2)组件服务->计算机->我的电脑

2) Component Services->Computers->My Computer

3)右键单击我的电脑,属性

3) Right-click My Computer, Properties

4)COM安全选项卡,启动和激活权限,编辑默认值

4) COM Security tab, Launch and Activation Permissions, Edit Default

5)添加网络服务的所有访问权限(这显然是最好的帐户),正在用于运行计划任务

5) Add all access rights for NETWORK SERVICE (which is the best account to use apparently), you are using to run scheduled task

6)右键单击我的电脑> DCOM配置> Microsoft Word 97-2003文档>属性

6) Right-click My Computer > DCOM Config > Microsoft Word 97 - 2003 Document > Properties

7)转到身份选项卡,然后选中交互式用户

7) Go to identity Tab and tick the interactive user

8)转到安全性选项卡,然后检查所有三个部分的自定义设置。确保显示网络服务并勾选了选项。这应该是步骤5的结果。

8) Go to Security tab and check the customize settings for all three sections. Make sure NETWORK SERVICE shows and has options ticked. This should be as a result of step 5.

9)对其他Office文档类型,从步骤6开始重复。我已经为xls和mdb做到了这一点

9) Repeat from step 6 for other office document types. I have done so for xls and mdb

10)重新启动...。现在一切正常

10) restart....All are working well now

抱歉,我应该添加此内容。如果在步骤7中看不到这些内容:

Sorry I should have added this. If you can not see these at step 7:

               'Microsoft Word 97 - 2003 Document'

               'Microsoft Excel Application'

               'Microsoft Access Application

然后可能是在64位计算机上安装32位Office,此处为解决方案,以使其可见:

Then it probably a 32bit office installation on a 64 bit machine, here is the solution to make them visible:

感谢大家的宝贵时间

推荐答案

您应授予指定用户对COM自动化工厂的访问权限:

You should grant to the specified user access to COM automation factory:


  • 1)开始->运行-> dcomcnfg

  • 2)组件服务->计算机->我的电脑

  • 3)右键单击我的电脑,属性

  • 4)COM安全选项卡,启动和激活权限,编辑默认值

  • 5)添加一个ll指定用户的访问权限,您正在运行
    计划任务。

  • 1) Start->Run->dcomcnfg
  • 2) Component Services->Computers->My Computer
  • 3) Right-click My Computer, Properties
  • 4) COM Security tab, Launch and Activation Permissions, Edit Default
  • 5) Add all access rights for the specified user, you are using to run scheduled task.

这篇关于.net应用程序通过计划任务触发时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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