可能的重复:
为什么我会收到“文档和设置”文件夹出现访问被拒绝错误?
我有一个程序可以从用户指定的文件夹及其子目录中读取所有 .exe 文件。在测试时,我尝试使用 C:\ 作为 root 进行扫描。
这抛出了一个“UnauthorizedAccessException was unhandled” {“Access to the path 'c:\Documents and Settings\' is returned.”}
执行此操作的代码片段如下:
string customScanFolder = Console.ReadLine();
Console.WriteLine("");
if (Directory.Exists(customScanFolder) == true)
{
string[] customScanResults = Directory.GetFiles(customScanFolder, "*.EXE", SearchOption.AllDirectories);
我仍然是一个 C# 新手,但所有 Google 搜索这里的相关主题并没有帮助我指明正确的方向。
我的程序运行的系统是Win7,禁用了UAC。 .exe 已启用“以管理员身份运行”。
该程序只会从文件中读取,而不会写入文件。我需要做什么才能授予访问权限或以其他方式避免此错误?
谢谢,
本
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
发布评论
评论(2)
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.这和我最近遇到的一个问题是一样的。请参阅这篇文章了解我使用的解决方案。
作为系统运行的 Windows 服务无法访问 C:\users\
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\