Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.UnauthorizedAccessException:对路径的访问被拒绝_C#_Asp.net_Wpf_Registry - Fatal编程技术网

C# System.UnauthorizedAccessException:对路径的访问被拒绝

C# System.UnauthorizedAccessException:对路径的访问被拒绝,c#,asp.net,wpf,registry,C#,Asp.net,Wpf,Registry,我试图在打开电脑时自动启动我的应用程序。我已将此程序写入我的代码: if (Convert.ToInt32(_param.AUTOMATIC_LAUNCH) == 1) { registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true); registryKey.SetValue("Quick",

我试图在打开电脑时自动启动我的应用程序。我已将此程序写入我的代码:

if (Convert.ToInt32(_param.AUTOMATIC_LAUNCH) == 1)
{
    registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
    registryKey.SetValue("Quick", Process.GetCurrentProcess().MainModule.FileName.ToString());
}
if (Convert.ToInt32(_param.AUTOMATIC_LAUNCH) == 0 && registryKey != null)
{
    registryKey.DeleteValue("Quick", true);
}
密钥确实在文件夹中:“Software\Microsoft\Windows\CurrentVersion\Run”。 但我的日志中显示了一条消息:

System.UnauthorizedAccessException:对路径“C:\WINDOWS\System32\config\u borne.ini”的访问被拒绝。
在System.IO.\uuu Error.WinIOError(Int32 errorCode,字符串maybeFullPath) (……)


我试图在我的应用程序的文件夹中向用户授予自动化,但它不起作用。此外,“config borne.ini”是一个不存在的文件。

最后我得到了一个解决方案,但有点不同。由于缺乏自动化,我没有在注册表中创建密钥。为了解决这个问题,我选择直接在启动文件夹中创建一个快捷方式(CTRL+R和shell:startup,如果您想查看它)。

您是否以管理员身份运行应用程序?您好,是的,我以管理员身份运行它administrator@harili,根据我的测试,我可以成功设置该值。那么,您在哪里看到错误,是抛出异常还是其他异常?我建议你可以把你的应用程序放在D盘上试试。@JackJJun MSFT你好,我也可以成功设置密钥。当我打开电脑(测试应用程序是否将单独启动)时,会出现异常中止。是的,我抛出了一个异常,我试图弹出一个广告,建议您使用管理员权限运行应用程序,但没有成功。然后我要试着把它放到我的D:。