質問

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

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.

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);

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.

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?

Thanks,

Ben

役に立ちましたか?

解決

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

他のヒント

This is the same as an issue I encountered recently. See this post for the solution I used.

Windows service running as system cannot access C:\users\

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top