访问被拒绝。(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED)

smi*_*tha 4 c# wmi

代码:

ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
Run Code Online (Sandbox Code Playgroud)

上面的代码抛出以下异常请帮助..我在一些文章中读到这个错误是由于 WMI 损坏而引发的?是这种情况吗?我必须重建 WMI 还是有任何替代方案?或更好的解决方案

错误:

访问被拒绝。(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED)

System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) at System.Management.ManagementScope.InitializeGuts(Object o) at System.Management.InitializeManagement () 在 System.Management.ManagementScope.Connect() 在 WebApplication3.lanusers.Button1_Click1(Object sender, EventArgs e) 在 C:\Users\user\documents\visual studio 2010\Projects\WebApplication3\WebApplication3\lanusers.aspx.cs :line 120 IpAddress192.168.1.55HostNamenkn-PC

RRU*_*RUZ 5

错误代码0x80070005与 WMI 权限相关。

0x8007xxx:源自核心操作系统的错误。由于外部故障,例如 DCOM 安全故障,WMI 可能会返回此类错误。

为了修复此错误,您必须在客户端和服务器计算机中设置适当的权限。试试这些链接