类型的未处理的异常

类型的未处理的异常

本文介绍了错误:类型的未处理的异常“System.UnauthorizedAccessException的'发生在mscorlib.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是死机,给我这个错误的部分是,当我尝试将文件复制到一个特定的位置。

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中,还希望它世界的窗口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);



首先过载源第2个过载的目标,我认为原因可能是这个

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:


  • 调用方没有所要求的权限

  • 路径是一个目录。

  • 路径指定的只读文件。

这篇关于错误:类型的未处理的异常“System.UnauthorizedAccessException的'发生在mscorlib.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:37