vb.net 错误描述:来自 HRESULT 的异常:0x800A0046 (CTL_E_PERMISSIONDENIED)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14918630/
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
Error Desc: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED)
提问by user2054334
Hi can any one advice how I can sort out this error
嗨,任何人都可以建议我如何解决这个错误
**Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED)**
Note that this error is not comming for all of the file rarely it is throwing, while writing string data in the file.
请注意,在将字符串数据写入文件时,此错误不会出现在很少抛出的所有文件中。
please find the below code which i am using in VB.net
请找到我在 VB.net 中使用的以下代码
Dim fso, file
strResult = "this is the sample string data"
strPath = it is local path only.
fso = CreateObject("Scripting.FileSystemObject")
file = fso.opentextfile(strPath, ForWriting, True)
file.write(strResult)
file.Close()
回答by ???ěxě?
The error is being thrown because either, you don't have permission to edit the file or because the file is in use by another process or another user. Also using the legacy FileSystemObject isn't a good idea. Use the managed libraries from the .NET framework because it will provide you with better error support. See example below as how you can accomplish the same thing below...
抛出错误是因为您没有编辑文件的权限,或者因为另一个进程或另一个用户正在使用该文件。使用旧的 FileSystemObject 也不是一个好主意。使用 .NET 框架中的托管库,因为它将为您提供更好的错误支持。请参阅下面的示例,了解如何在下面完成相同的事情...
Try
File.WriteAllText("Your data", "FILE")
Catch ex As Exception
MsgBox (ex.Message) 'Or however you want to handle this...
End Try
Thanks!
谢谢!
回答by Fandango68
Without more information about what your file system is like, what permissions you have, and what exactly are you trying to do and use in your program, there is little to no way of knowing how to help you.
如果没有更多关于您的文件系统是什么样的、您拥有什么权限以及您在程序中尝试做什么和使用什么的更多信息,几乎没有办法知道如何帮助您。
However, I've encountered this problem in the past due to legacy DLLs mixed in with more recent technologies - such as .Net 1 vs .Net 4.5.
但是,由于旧版 DLL 与更新的技术(例如 .Net 1 与 .Net 4.5)混合在一起,我过去曾遇到过这个问题。
Old DLLs under .Net 4.5 and above are a pain in the backside to manage and make sure they run properly. They cause memory leaks, they don't respect memory properly and they are hardcoded in many ways to do things that .Net 4.5 and above would do better these days.
.Net 4.5 及更高版本下的旧 DLL 在后台管理和确保它们正常运行是一个痛苦。它们会导致内存泄漏,它们没有正确尊重内存,并且它们以多种方式进行了硬编码,以执行 .Net 4.5 及更高版本现在可以做得更好的事情。
I suggest you provide us with your project settings, and your COM references, because one of them is most likely the reason you're getting this error.
我建议您向我们提供您的项目设置和 COM 引用,因为其中之一很可能是您收到此错误的原因。
It's a process of elimination. Eliminate one Reference at a time, comment out code, debug, etc until you find the culprit DLL that gives you the problem. AND THEN you need to decide whether to use another DLL, another Reference or better yet, do without that offending DLL in the first place.
这是一个淘汰的过程。一次消除一个引用、注释掉代码、调试等,直到找到导致问题的罪魁祸首 DLL。然后您需要决定是否使用另一个 DLL、另一个引用或更好的方法,首先不要使用那个有问题的 DLL。
Good luck,
祝你好运,

