问题:使用 Windows 7,运行我的应用程序时出现未经授权的访问异常
我的应用程序引发未经授权的访问错误。运行我的应用程序时,我尝试访问以下位置的目录:Application.UserAppDataPath。
问题:它说我没有访问 Application.UserAppDataPath 目录的权限
有没有办法在我的应用程序源代码中设置权限?
像这样的东西:
Application.UserAppDataPath.SetPermissions()
My application is raising an unauthorized access error. While running my application, I try to access a directory in the following location: Application.UserAppDataPath.
The Problem: It says I do not have permission to access the Application.UserAppDataPath directory
Is there a way to set permissions within my application source code?
Something like:
Application.UserAppDataPath.SetPermissions()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看您的评论,您说这是您的代码:
Application.UserAppDataPath
是一个目录,而不是文件。如果您尝试直接打开该文件,则与尝试打开 AppData 文件夹下一层的文件相同,而您实际上没有权限这样做。使用 Path.Combine 构造 AppData 文件夹内的文件的路径,即
当然这只是一个示例 - 实际上您可能应该使用子文件夹在特定于您的应用程序的 AppData 中。
Looking at your comment, you say this is your code:
Application.UserAppDataPath
is a directory, not a file. If you try to open that directly, it's the same as trying to open a file one level below the AppData folder, which you really don't have permission to do.Use
Path.Combine
to construct a path to a file inside the AppData folder, i.e.Of course this is just an example - in reality you should probably be using a sub-folder inside AppData specific to your application.
这可能是 UAC 问题,尝试将应用程序作为提升的进程运行,然后查看错误是否仍然存在
Its probably a UAC issue, Try running your application as an elevated process, and see if the error persists