2

可能重复:
为什么我收到 Documents and Settings 文件夹的访问被拒绝错误?

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

这抛出了一个“UnauthorizedAccessException was unhandled” {“Access to the path 'c:\Documents and Settings\' is denied.”}

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

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

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

我仍然是一个 C# 新手,但这里的所有谷歌搜索和相关主题都没有帮助我指明正确的方向。

我的程序运行的系统是禁用 UAC 的 Win7。.exe 启用了“以管理员身份运行”。

该程序只会从文件中读取,而不是写入文件。我需要做什么才能授予访问权限或以另一种方式避免此错误?

谢谢,

4

2 回答 2

3

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

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
于 2012-02-10T13:26:00.453 回答
0

这和我最近遇到的一个问题一样。请参阅这篇文章了解我使用的解决方案。

作为系统运行的 Windows 服务无法访问 C:\users\

于 2012-02-10T14:03:56.267 回答