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

问题描述 投票:0回答:2
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数组中获取所有子目录的文件名。

c# permission-denied
2个回答
0
投票

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

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


-1
投票

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

  • 如果您从Visual Studio运行该程序,那就是您的帐户。以管理员身份运行VS,您的代码应该正常工作。
  • 如果它是一个Web应用程序,则应用程序池帐户需要对该文件夹的读取权限。
  • 如果是Windows服务,则主机帐户需要访问权限。
© www.soinside.com 2019 - 2024. All rights reserved.