Windows Server 2012在启动时运行服务失败

我有一个EC2实例与Windows Server 2012 R2所有最新的更新。

我首先做了一个服务,然后运行一个batch file来创build一个Microsoft Word报告(使用我自定义的C#程序)。 我将任务设置为以最高权限运行,并以pipe理员身份运行。 虽然我的batch file确实被调用,但是失败了。 我的batch file:

C:/WordGenerator.exe C:/report.docx > C:/word.log 2>&1 

它从exe的exception出错:

 Failure System.NullReferenceException: Object reference not set to an instance of an object. at InteropFunctions.Save(String opath) at Reporting.Report.generate() at Reporting.WordGenerator.run() 

如果我手动运行该batch file,它会很好地完成。

当C#Word interop函数试图打开一个制作的报表进行进一步处理时(如此,它实际上没有权限 – 找不到它),就会发生上述exception。

  1. 到目前为止,我学到了Windows可能仍然以LOCAL SYSTEM帐户运行所有服务,并且即时login给定的用户(如果有的话)。

  2. 我还了解到,服务可能会在常规pipe理员命令的不同会话/安全上下文中运行。

任何人都可以帮助find一个解决scheme吗? 我需要以pipe理员身份运行batch file(无需login)。 我愿意去模拟一个login。 我们正在经历其他问题,因为这不是以pipe理员身份运行(我给出的是一个简单的例子)。 图片设置:

在这里输入图像说明

这个失败的原因是因为Windows中的DCOM。 我把我的身份设置为pipe理员(身份)部分。

https://stackoverflow.com/a/11359745/234307