C#文件修改访问即使在自有环境上的管理员

发布于 2025-01-31 20:51:47 字数 1673 浏览 2 评论 0原文

我的计算机有一个奇怪的问题。

我无法使用C#应用程序在桌面上和计算机上的其他特定目录上重命名或删除文件。 没有真实的模式,信息如下:

using System;
using System.IO;

namespace justATest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            string path = @"C:\Users\USERNAME\Desktop\";
            string nameBefore = Path.Combine(path, "test.txt");
            string nameAfter = Path.Combine(path, "something.txt");

            File.Move(nameBefore, nameAfter); // Fails
        }
    }
}

例外:

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access to the path is denied.
  Source=System.IO.FileSystem
  StackTrace:
   at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
   at System.IO.File.Move(String sourceFileName, String destFileName, Boolean overwrite)
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at justATest.Program.Main(String[] args) in C:\Users\USERNAME\source\repos\justATest\justATest\Program.cs:line 16

我尝试的内容:

  1. 我将窗口更新为最新版本
  2. ,我检查了文件的所有者
  3. 我检查了文件的权限,
  4. 我作为管理员运行了我的应用程序
  5. 作为管理员
  6. ,我将视觉工作室运行,我 运行了sfc /scannow
  7. 我对Windows安装进行了某种维修(通过Microsoft支持)
  8. 我创建了多个文件,并在我创建的nested文件夹的旧文件和新文件上尝试了它
  9. 文件夹中
  10. ,并尝试在上述文件夹中重命名我在其他目录中重命名文件的 (可行)
  11. 我尝试了将文件复制到新文件(带有新名称)的方法,然后删除旧文件。这起作用,直到我尝试删除旧文件为止,
  12. 我尝试手动执行相同的任务,但
  13. 我尝试关闭
  14. 我尝试修复Visual Studio的

抗病毒,我主要想重命名文件,但是同样的是,删除文件等。

OS:Windows 10 Pro 21H2 IDE:Visual Studio 2019 16.11.15 机器上的用户数量:1(只是我),

如果您需要更多信息,请告诉我。

I have a weird issue with my computer.

I cannot use my C# apps to rename or delete files on my desktop and in other specific directories on my computer.
There's no real pattern and the information is below:

using System;
using System.IO;

namespace justATest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            string path = @"C:\Users\USERNAME\Desktop\";
            string nameBefore = Path.Combine(path, "test.txt");
            string nameAfter = Path.Combine(path, "something.txt");

            File.Move(nameBefore, nameAfter); // Fails
        }
    }
}

The exception:

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access to the path is denied.
  Source=System.IO.FileSystem
  StackTrace:
   at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
   at System.IO.File.Move(String sourceFileName, String destFileName, Boolean overwrite)
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at justATest.Program.Main(String[] args) in C:\Users\USERNAME\source\repos\justATest\justATest\Program.cs:line 16

What I tried:

  1. I updated Windows to the latest version
  2. I checked the file's owner
  3. I checked the file's permissions
  4. I ran my app as an administrator
  5. I ran Visual Studio as an administrator
  6. I ran SFC /ScanNow
  7. I did some kind of a repair to my Windows installation (through Microsoft Support)
  8. I created multiple files and tried it on old and new files
  9. I created nested folders and tried to rename files within said folders
  10. I tried renaming files in other directories (that works)
  11. I tried the method of copying the file into a new file (with the new name) and then deleting the old file. This works until I try to delete the old file, which fails
  12. I tried doing the same tasks manually and it works just fine
  13. I tried turning off my anti virus
  14. I tried to repair Visual Studio

I mainly want to rename files, but the same goes for deleting files and the like.

OS: Windows 10 Pro 21H2
IDE: Visual Studio 2019 16.11.15
Number of users on machine: 1 (just me)

If you need any more information, let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文