C#文件修改访问即使在自有环境上的管理员
我的计算机有一个奇怪的问题。
我无法使用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
我尝试的内容:
- 我将窗口更新为最新版本
- ,我检查了文件的所有者
- 我检查了文件的权限,
- 我作为管理员运行了我的应用程序
- 作为管理员
- ,我将视觉工作室运行,我 运行了sfc /scannow
- 我对Windows安装进行了某种维修(通过Microsoft支持)
- 我创建了多个文件,并在我创建的nested文件夹的旧文件和新文件上尝试了它
- 文件夹中
- ,并尝试在上述文件夹中重命名我在其他目录中重命名文件的 (可行)
- 我尝试了将文件复制到新文件(带有新名称)的方法,然后删除旧文件。这起作用,直到我尝试删除旧文件为止,
- 我尝试手动执行相同的任务,但
- 我尝试关闭
- 我尝试修复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:
- I updated Windows to the latest version
- I checked the file's owner
- I checked the file's permissions
- I ran my app as an administrator
- I ran Visual Studio as an administrator
- I ran SFC /ScanNow
- I did some kind of a repair to my Windows installation (through Microsoft Support)
- I created multiple files and tried it on old and new files
- I created nested folders and tried to rename files within said folders
- I tried renaming files in other directories (that works)
- 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
- I tried doing the same tasks manually and it works just fine
- I tried turning off my anti virus
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论