我正在使用一个简单的DirectoryInfo来获取C驱动器根目录上的所有目录.但是,我在管理员下运行,并且遇到路径访问被拒绝的错误,下面是我正在运行的代码.如何解决路径访问问题?
I'm using a simple DirectoryInfo to grab all directories on the root on the C drive. However, I'm running under administrator and i'm getting the error of path access denied, below is the code that I am running. How do I resolve the issue of path access?
DirectoryInfo Dinfo = new DirectoryInfo(@"C:\"); DirectoryInfo[] directories = Dinfo.GetDirectories("*.*", SearchOption.AllDirectories);推荐答案
在Windows的较新版本中,C:\Document and Settings是连接点,是一种文件系统快捷方式.它不是普通目录,这意味着它实际上不能用作普通目录.
On newer versions of Windows C:\Document and Settings is a junction point, kind of a file system shortcut. It is not a normal directory, which means that it doesn't really work as a normal directory.
如果在开始"->运行"框中键入C:\Document and Settings,也会收到拒绝访问错误,因此它与您的程序无关.
If you type in C:\Document and Settings in the start->run box you will also get an access denied error, so it is nothing specific to your program.
但是我对它的工作方式有些困惑.我以为接合点将是指向新位置c:\users的透明链接,但显然不是.
I'm a bit confused by how this works however. I thought that the junction point would be a transparent link to the new location which is c:\users but obviously not.
看完重复的问题后,我就不那么困惑了.交界点实际上链接到新位置c:\users.但是,在连接点上有一个明确的拒绝ACL来读取,以防止任何人使用它来读取内容:
After looking at the duplicate question I'm less confused. The junction point really links to the new location which is c:\users. However, there is an explicit deny acl for reading on the junction point to prevent anyone from using it to read things:
C:> cacls文档和设置" C:\ Documents and Settings 所有人:(DENY)(特殊访问权限:)
C:>cacls "Documents and Settings" C:\Documents and Settings Everyone:(DENY)(special access:) FILE_READ_DATA Everyone:R NT AUTHORITY\SYSTEM:F BUILTIN\Administrators:F
C:>
更多推荐
C#拒绝访问路径"C:\ Documents and Settings \"
发布评论