C#:访问路径<'filepath'>被拒绝 [英] C#: Access to path <'filepath'> is denied

查看:167
本文介绍了C#:访问路径<'filepath'>被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
为什么我要凭证和设置文件夹的访问被拒绝错误?

Possible Duplicate:
Why am I getting an access denied error for the Documents and Settings folder?

我有一个程序可以从用户指定的文件夹及其子目录中读取所有.exe文件.在测试时,我尝试使用C:\作为根目录进行扫描.

I have a program that will read all .exe files from a user specified folder and its sub-directories. While testing I tried to scan using C:\ as root.

这抛出了一个未处理UnauthorizedAccessException" {{拒绝访问路径'c:\ Documents and Settings \'.}

This threw out an "UnauthorizedAccessException was unhandled" {"Access to the path 'c:\Documents and Settings\' is denied."}

执行此操作的代码段如下:

The code snippet doing this is as follows:

 string customScanFolder = Console.ReadLine();
    Console.WriteLine("");

    if (Directory.Exists(customScanFolder) == true)
    {
        string[] customScanResults = Directory.GetFiles(customScanFolder, "*.EXE", SearchOption.AllDirectories);

我仍然是C#的新手,但是此处的所有Google搜索和相关主题都无法帮助我指明正确的方向.

I am still very much a C# novice, but all Googling and related topics on here have not helped point me in the right direction.

我的程序正在运行的系统是Win7,并且禁用了UAC. .exe已启用以管理员身份运行".

The system my program is running on is Win7 with UAC disabled. The .exe has 'Run as Administrator' enabled.

该程序将仅从文件中读取,而不会写入文件.我该怎么做才能授予访问权限或以其他方式避免此错误?

The program will only ever read from files, not write to them. What do I need to do to either grant access rights or avoid this error another way?

谢谢

推荐答案

C:\Documents and Settings在Windows 7中不是文件夹.它是C:\ Users的连接点(或链接).您应该忽略它.

C:\Documents and Settings is not a folder in Windows 7. It's a Junction (or link) to C:\Users. You should be ignoring it.

C:\>dir /a:s C:
 Volume in drive C has no label.
 Volume Serial Number is 86F5-8CF5

 Directory of C:\

03/04/2011  10:19 AM    <DIR>          $Recycle.Bin
02/03/2012  03:00 PM    <DIR>          Config.Msi
07/14/2009  12:08 AM    <JUNCTION>     Documents and Settings [C:\Users]
12/30/2011  01:19 PM    12,882,337,792 pagefile.sys
10/23/2009  03:07 PM    <DIR>          Recovery
01/11/2011  10:24 AM    <DIR>          System Volume Information
               1 File(s) 12,882,337,792 bytes
               5 Dir(s)  64,772,997,120 bytes free

这篇关于C#:访问路径&lt;'filepath'&gt;被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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