C# 访问被拒绝。(来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17187871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)
提问by smitha
code:
代码:
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
Above code throws the following exception please Help..i read in some article that this error are thrown due to WMI corruption?Is this the case?do i have to rebuild WMI or is there any alternate?or a better solution
上面的代码抛出以下异常请帮助..我在一些文章中读到这个错误是由于 WMI 损坏而引发的?是这种情况吗?我必须重建 WMI 还是有任何替代方案?或更好的解决方案
Error:
错误:
Access is denied. (Exception from 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.ManagementScope.Initialize() at System.Management.ManagementScope.Connect() at WebApplication3.lanusers.Button1_Click1(Object sender, EventArgs e) in C:\Users\user\documents\visual studio 2010\Projects\WebApplication3\WebApplication3\lanusers.aspx.cs:line 120 IpAddress192.168.1.55HostNamenkn-PC
访问被拒绝。(来自 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
回答by RRUZ
The Error code 0x80070005is related to the WMI permissions.
错误代码0x80070005与 WMI 权限相关。
0x8007xxx : Errors originating in the core operating system. WMI may return this type of error because of an external failure, for example, DCOM security failure.
0x8007xxx:源自核心操作系统的错误。由于外部故障,例如 DCOM 安全故障,WMI 可能会返回此类错误。
In order to fix this error you must set the proper permissions in the client and server machines. Try these links
为了修复此错误,您必须在客户端和服务器计算机中设置适当的权限。试试这些链接
回答by ali hesham
Did you try enabling Anonymous access for the site in IIS?
您是否尝试在 IIS 中为站点启用匿名访问?
Edit:
编辑:
The error message clearly says what you need to do.
错误消息清楚地说明了您需要做什么。
Use a separate limited account for the site if you want or enable anonymous access for the site in IIS.
如果您希望或在 IIS 中启用对站点的匿名访问,请为站点使用单独的受限帐户。
回答by Somnath
Also Please allow the app "windows management instrumentation (wmi)" to communicate through windows firewall. Please refer this link for more info. https://social.msdn.microsoft.com/Forums/vstudio/en-US/6229334e-d5ef-4016-9e7e-1c8718be8d43/access-is-denied-exception-from-hresult-0x80070005-eaccessdenied-in-vbnet?forum=netfxbcl
另外请允许应用程序“windows management instrumentation (wmi)”通过windows防火墙进行通信。请参阅此链接以获取更多信息。 https://social.msdn.microsoft.com/Forums/vstudio/en-US/6229334e-d5ef-4016-9e7e-1c8718be8d43/access-is-denied-exception-from-hresult-0x80070005-eaccessdenied-in-vbnet?论坛=netfxbcl
回答by kenorb
The error 0x80070005usually relates to permission denied to the cache files, so make sure they've the right permissions.
该错误0x80070005通常与缓存文件的权限被拒绝有关,因此请确保它们具有正确的权限。
For example go to /Users/Public/Application Data/Package Cachefolder (or other folder) and make sure that the folders and files there has the right permissions. Otherwise find out which temporary/cache files are causing the issue and remove them.
例如转到/Users/Public/Application Data/Package Cache文件夹(或其他文件夹)并确保那里的文件夹和文件具有正确的权限。否则找出导致问题的临时/缓存文件并删除它们。
回答by Neelam Prajapati
tick checkbox of capabilities in appxmanifest in case of UWP app.
在 UWP 应用的情况下,勾选 appxmanifest 中的功能复选框。

