Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

directoryinfo - C# Access to the path 'C:Documents and Settings' is denied

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.

Edit

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 "Documents and Settings" C:Documents and Settings Everyone:(DENY)(special access:)

                               FILE_READ_DATA

                      Everyone:R
                      NT AUTHORITYSYSTEM:F
                      BUILTINAdministrators:F

C:>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...