C#应用程序获取访问被拒绝。 HRESULT:0x80070005(E_ACCESSDENIED)

时间:2014-07-31 22:40:08

标签: c# iis wmi impersonation access-denied

我在c#代码上有以下内容:

ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
//connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope("\\\\" + remoteMachine + "\\ROOT\\CIMV2"), connOptions);
manScope.Connect();

我还授予了我对应用程序的应用程序池标识访问权限(读取,写入),并遵循Microsoft在http://msdn.microsoft.com/en-us/library/windows/desktop/aa394603%28v=vs.85%29.aspx提供的说明

  

可能的问题:用户无法通过DCOM远程访问计算机。通常,连接到具有不同操作系统版本的远程计算机时会发生DCOM错误。

     

解决方案:在dcomcnfg中为用户提供远程启动和远程激活权限。右键单击我的电脑 - >属性在COM安全性下,单击两个部分的“编辑限制”。为您希望远程访问,远程启动和远程激活的用户提供服务。然后转到DCOM Config,找到“Windows Management Instrumentation”,并为用户提供远程启动和远程激活。有关更多信息,请参阅在不同操作系统之间进行连接

运行我的应用程序时,仍然会收到“拒绝访问”错误消息。

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Stack Trace: [UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))]
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
System.Management.ManagementScope.InitializeGuts(Object o) +657
System.Management.ManagementScope.Initialize() +359
Tool.WebForm1.Page_Load(Object sender, EventArgs e) +3647
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178

我还应该做些什么/改变?感谢。

0 个答案:

没有答案