Error: An unhandled exception of type #39;System.UnauthorizedAccessException#39; occurred in mscorlib.dll(错误:mscorlib.dll 中出现“System.UnauthorizedAccessException类型的未处理异常)
问题描述
这是当我尝试将文件复制到某个位置时崩溃并给我这个错误的部分.
This is the part that crashes and gives me this error is when I try to copy a file to a certain location.
string startupDirectory = "C:\Users\Tyler\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup";
File.Copy(startupDirectory, "Startup.exe");
我已经在线阅读并尝试了管理员权限并创建了一个app.manifest"文件:
I have read online and tried administrator rights and have created an "app.manifest" file:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
我确认在设置中,应用清单设置为这个文件,但它仍然给我同样的错误.
I confirmed that in the settings, the app manifest is set to this file, but it still gives me the same error.
我也尝试过这个事件,但我认为它不会起作用,因为它是一个目录而不是文件:
I have also tried this event though I didn't think it would work because it is a directory not a file:
File.SetAttributes(startupDirectory, FileAttributes.Normal);
这是 WinForms,我使用的是 Windows 7,但也希望它适用于 Windows 8+.我该怎么做?
This is WinForms and I am on windows 7 but also want it to world for windows 8+. How do I do this?
提前致谢!
推荐答案
试试
public static void Copy(string sourceFileName, string destFileName);
第一个重载是源第二个重载是目标我认为原因可能是这个
First overload is source 2nd overload is destination i think reason might be this
File.Copy("Startup.exe",startupDirectory);
尝试将您正在读取/保存文件的 .Net 用户的访问权限设置为完全控制".
Try setting the access permissions to "Full control" for the .Net user from where you are reading/saving the files.
对于特定文件的 IIS 服务器中的访问被拒绝错误,请按照以下步骤操作
For Access Denied Error in IIS server for particular file , please follow the below steps
1- Goto to C:\Users\Tyler\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
2- Right click on your file -> Properties -> Pop Up of User properties appears -> click on Security tab-> click on Edit -> select Users-> tick on Allow Full Control -> Click Ok
这肯定会解决访问被拒绝的问题
This will surely solve the Access denied problem
UnauthorizedAccessException 意味着以下三件事之一:
An UnauthorizedAccessException means one of 3 things:
- 调用者没有所需的权限.
- path 是一个目录.
- path 指定了一个只读文件.
这篇关于错误:mscorlib.dll 中出现“System.UnauthorizedAccessException"类型的未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误:mscorlib.dll 中出现“System.UnauthorizedAccessException"类型的未处理异常
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01