访问路径'c:\ windows \ system32 \ inetsrv \ config \'被拒绝

时间:2012-09-07 05:06:16

标签: c# permission-denied

if (Fubrowse.HasFile)
{
  string path = Path.GetFullPath(Fubrowse.PostedFile.FileName);
  //string root = Path.GetPathRoot(path);
  GetFilesFromDirectory(path.Substring(0, path.LastIndexOf("\\")));
}
else
  GeneralClass.ShowMessageBox("Please Select File First.");
}

private void GetFilesFromDirectory(string DirPath)
{
  try
  { 
    DirectoryInfo Dir = new DirectoryInfo(DirPath);
    FileInfo[] FileList = Dir.GetFiles("*.cs", SearchOption.AllDirectories);
    foreach (FileInfo FI in FileList)

此处,路径为c:\windows\system32\inetsrv\config\。我想在FileList数组中获取所有子目录的文件名。

2 个答案:

答案 0 :(得分:0)

我有同样的问题。我无法从C:\Windows\system32\intesrv\config获取文件,因为我的系统是64位,我的请求重定向到C:\Windows\SysWOW64\system32\intesrv\config this answer给出了更多解释。

PS。我的答案留给了那些将来会搜索的人

答案 1 :(得分:-1)

运行代码的Windows帐户需要对该文件夹的读取权限(通常需要管理员权限)。

  • 如果您是从Visual Studio运行该程序,那就是您的帐户。以管理员身份运行VS,您的代码应该正常工作。
  • 如果是网络应用,则应用池帐户需要对该文件夹的读取权限。
  • 如果是Windows服务,则需要访问主机帐户。