错误:mscorlib.dll 中出现“System.UnauthorizedAccessException"类型的未处理异常 [英] Error: An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

查看:102
本文介绍了错误: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"类型的未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆