问题描述
我已经开发了在Visual Studio 2010中开发的Windows服务,该服务执行Exchange 2007管理任务,并将其从32位开发服务器迁移到64位生产服务器.该服务接受参数,然后调用PowerShell在Exchange 2007管理单元中执行命令.
安装后,它可以在开发环境中的调试器中以及Windows服务本身中正常运行;不幸的是,当我将项目复制到新的Windows 2008 R2 64位服务器并进行构建时,我只能在VS2010调试器中使用该服务.当作为Windows服务安装在64位服务器上时,该服务始终失败,并显示来自代码的PowerShell组件的消息,内容为:
I’ve developed a windows service developed in Visual Studio 2010 which performs Exchange 2007 administrative tasks and I’m moving it from a 32-bit development server to a 64-bit production server. The service accepts arguments and then invokes PowerShell to execute commands in the Exchange 2007 snap in.
It works correctly in the development environment both in the debugger and in the windows service itself after it’s been installed; unfortunately, when I copied the project to the new Windows 2008 R2 64-bit server and built it I can only get the service to work in the VS2010 debugger. When installed as a windows service on the 64-bit server the service consistently fails with a message from the PowerShell component of the code which reads:
"No snap-ins have been registered for Windows PowerShell version 2"
调用PowerShell实例时,C#代码在特定行上失败:
The C# code fails on a specific line when the PowerShell instance is invoked:
RunspaceConfiguration rc;
PSSnapInInfo info = rc.AddPSSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out warning);
正如我提到的,只要我在VS2010调试器中运行代码,代码就可以正常工作.
为了解决这个问题,我尝试了Google搜索错误,并提出了许多其他人遇到此问题的方法,但是没有人能给出确切的答案.遵循其中一些帖子中留下的一些线索后,我尝试了以下方法:
- 我已经删除并重新安装了Exchange 2007管理工具
- I have removed and re-installed the Exchange 2007 management tools
- 我已经从Exchange命令行管理程序PowerShell PowerShell提示符中完成了"Get-PSSnapin"(然后返回了一个清单如下所示的Exchange管理工具清单-版本说明该清单适用于PSVersion 1.0而不是2.0,但是,因为在VS2010调试器中一切正常,所以我认为psversion并不是引起问题的原因):
- 名称:Microsoft.Exchange.Management.PowerShell.Admin
- PSVersion:1.0
- Name: Microsoft.Exchange.Management.PowerShell.Admin
- PSVersion: 1.0
- 说明:Exchange Server的管理任务
- 我尝试使用C:\ Windows \ Microsoft.NET \ Framework64 \ v2.0.50727下的INSTALLUTIL将管理单元注册为
- I’ve tried registering the snap-in using INSTALLUTIL under the C:\Windows\Microsoft.NET\Framework64\v2.0.50727 as
Installutil c:\program files\microsoft\exchange server\bin\microsoft.exchange.management.dll
As I mentioned, the code will work so long as I run it in the VS2010 debugger.
To try and fix this I’ve tried Googling the error and come up with many other people having this problem but no-one having a definitive answer to it. Following some of the leads left in some of these postings I’ve tried these things:
推荐答案
这篇关于Windows服务调用Powershell来执行Exchange 2007管理单元中的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!