0

我创建了一个写作测试来检查写作权限。测试是

  try
        {
            string filePath = String.Format(Path.Combine(path, Path.GetRandomFileName()));
            File.WriteAllText(filePath, @"0");
            File.Delete(filePath);
            return true;
        }
        catch (IOException uex)
        {
         //SomeErrorMessage
        } 
         catch (SecurityException uex)
        {
        }
        catch (UnauthorizedAccessException uex)
        {
        }

当我尝试以普通用户身份在 C:\Windows\System32 上写入时(我无法在此处写入),文件 writeAllText 似乎能够写入该目录但如果我评论删除行,我看不到该目录中的文件(我也以管理员身份使用提示符),如果我写了 File.ReadAllText(filePath),我可以读取该文件。为什么我可以在 C:\Windows\System32 中创建一个文件,为什么我只能通过 File.ReadAllText(filePath) 看到该文件?

4

0 回答 0