如何访问被拒绝的位置 [英] How Can I Access Location That Is Denied

查看:73
本文介绍了如何访问被拒绝的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们。我正在开发一个程序,用户可以选择他/她的计算机中的每个驱动器并添加一个文件。之后可以使用它。我可以将文件添加到每个位置,当我想使用该文件时,会发生错误,表示拒绝访问此位置。我不能限制用户在访问被拒绝的位置恢复文件。但是我想用户可以访问那些位置。

我怎样才能用C#编程执行此操作。



谢谢。

hi friends. i am developing a program that user can select every drive in his\her computer and add a file to it.after that can use it. i can add file to every location and when i want to use that files a error occur that say access to this location denied. i can not limit user for restore files in access denied location. but i want to user can access to that locations.
how can i do this programatically in C#.

thanks.

推荐答案

错误的方法。它就像是这个论坛上问题的一个重要子类:我收到错误信息:'不允许做ABC';我的问题是:如何做ABC。 :-)

你能在这里感受到荒谬吗?



正确的方法是:如何使用未被拒绝的地点?如果您面临被拒绝的位置,则可能意味着您执行的操作不太合法,通常使用一些硬编码的文件路径。在任何情况下,这些硬编码路径都不会有用。应在运行时根据用户输入,某些配置文件或其他数据,或基于软件产品位置,或每个用户帐户的系统设置或所有用户(特殊文件夹)计算所有路径。后者在我过去的答案中有解释:

如何查找我的程序目录可执行目录),

如何查找我的程序目录当前目录,特殊文件夹)。



您无法解决文件系统的权限问题对象访问,无论您想在某些应用程序中使用什么编程技巧。从逻辑上思考:如果有可能,谁会需要这样的保护?您只能使用具有管理权限的帐户执行一些系统管理工作(完全无关紧要),但这不是软件产品的解决方案。真正的软件解决方案将尊重系统和帐户设置,如上所述。



-SA
Wrong approach. It is like a big subclass of the questions on this forum: "I got error message: 'Doing ABC is not allowed'; my question is: how to do ABC". :-)
Can you feel the absurdity here?

Right approach would be: how to use the locations which are not denied? If you face denied location, it may mean that you do something not quite legitimate, typically, use some hard-coded file paths. There are no situations where those hard-coded paths can be useful. All paths should be calculated during runtime based on user input, some configuration file or other data, or, based software product location, or on system settings per user accounts or "all users" ("special folders"). The latter is explained in my past answers:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

You cannot work around permissions on file system object access, no matter what programming tricks you want to use in some application programs. Think logically: if it was possible, who would ever need such "protection"? You can only do some system administration work (totally trivial stuff) using an account with administrative permissions, but this is not a solution for a software product. Real software solution would be respecting the system and account settings, as explained above.

—SA


这篇关于如何访问被拒绝的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆