错误:mscorlib.dll中发生了类型为'System.UnauthorizedAccessException'的未处理异常

Nullone

这是崩溃的部分,当我尝试将文件复制到特定位置时,出现此错误。

string startupDirectory = "C:\\Users\\Tyler\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
File.Copy(startupDirectory, "Startup.exe");

我已在线阅读并尝试了管理员权限,并创建了一个“ app.manifest”文件:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

我确认在设置中,应用程序清单已设置为此文件,但仍然给我同样的错误。

我也尝试过此事件,但我认为它不会起作用,因为它是目录而不是文件:

File.SetAttributes(startupDirectory, FileAttributes.Normal);

这是WinForms,我在Windows 7上运行,但也希望它在Windows 8+上获得成功。我该怎么做呢?

提前致谢!

Midhun Mundayadan

尝试

public static void Copy(string sourceFileName, string destFileName);

第一个超载是源,第二个超载是目的地,我认为原因可能是这样

File.Copy("Startup.exe",startupDirectory);

尝试将您要从中读取/保存文件的.Net用户的访问权限设置为“完全控制”。

对于特定文件的IIS服务器中的“访问拒绝错误”,请按照以下步骤操作

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

这肯定会解决访问被拒绝的问题

UnauthorizedAccessException表示三件事之一:

  • 呼叫者没有所需的权限。
  • path是目录。
  • 路径指定了一个只读文件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

SetAccessControl提供错误,因为mscorlib.dll中发生类型为'System.UnauthorizedAccessException'的未处理异常

错误消息:C#中的mscorlib.dll中发生了'System.FormatException'类型的未处理异常

mscorlib.dll中发生了'System.ComponentModel.Win32Exception'类型的未处理异常

错误:System.Windows.Forms.dll中发生了类型为'System.BadImageFormatException'的未处理异常

VisualStudio错误:System.Data.dll中发生了类型为'System.Data.SqlClient.SqlException'的未处理的异常

错误:System.Data.dll中发生了类型为'System.Data.SqlClient.SqlException'的未处理的异常

BundleConfig类中的MVC错误:mscorlib.dll中发生了类型为'System.NullReferenceException'的异常

在C#中从十进制到十六进制的错误“在mscorlib.dll中发生了'System.FormatException'类型的未处理的异常”

File.Copy,mscorlib.dll 中发生类型为“System.IO.IOException”的未处理异常

Microsoft.WindowsAzure.Storage.dll中发生了类型为'System.StackOverflowException'的未处理异常

VB中的错误:language.exe中发生了类型为'System.IndexOutOfRangeException'的未处理异常

System.Data.Linq.dll中发生了类型为'System.Data.SqlServerCe.SqlCeException'的未处理异常

在System.Drawing.dll中发生了'System.ArgumentException'类型的未处理异常,用于灰度

System.Data.dll中发生了'System.ArgumentException'类型的未处理异常

mscorlib.dll 中发生类型为“System.FormatException”的未处理异常附加信息:输入字符串的格式不正确

mscorlib.dll 中发生了“System.Data.SqlClient.SqlException”类型的异常,但未在用户代码中处理

BLL.dll中发生了'System.ArgumentException'类型的未处理异常

Windows 窗体“System.Data.dll 中发生类型为‘System.ArgumentException’的未处理异常”

MySql - System.Data.dll 中发生类型为“System.InvalidOperationException”的未处理异常

System.Data.dll 中发生类型为“System.AccessViolationException”的未处理异常

从文本框写入sql server 2012时,System.Data.dll中发生了类型为'System.InvalidOperationException'的未处理异常

我该如何解决?“ mscorlib.dll中发生了'System.IO.IOException'类型的首次机会异常”

VimService55.XmlSerializers.dll中发生类型为'System.StackOverflowException'的未处理异常

WebDriver.dll中发生类型为'System.InvalidOperationException'的未处理异常

mscorlib.dll中的System.UnauthorizedAccessException

未处理System.UnauthorizedAccessException

在application.exe中发生了'System.StackOverflowException'类型的未处理异常

为什么我在System.Core.dll中发生类型为'System.ArgumentNullException'的未处理异常

生成报告会导致在system.windows.forms.dll中发生类型为'system.stackoverflowexception'的未处理异常