System.UnauthorizedAccessException: 访问路径被拒绝
System.UnauthorizedAccessException: Access to the path denied
我试图在打开计算机时自动启动我的应用程序。我已将此程序写入我的代码中:
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: access to the path 'C:\WINDOWS\System32\config_borne.ini' denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
(....)
我试图在我的应用程序文件夹中向用户授予授权,但它不起作用。另外,“config-borne.ini”是一个不存在的文件。
最后我得到了一个解决方案,但它有点不同。由于缺乏授权,我没有在注册表中创建密钥。为了克服这个问题,我选择直接在启动文件夹中创建一个快捷方式(CTRL+R和shell:startup如果你想看的话)。
我试图在打开计算机时自动启动我的应用程序。我已将此程序写入我的代码中:
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: access to the path 'C:\WINDOWS\System32\config_borne.ini' denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) (....)
我试图在我的应用程序文件夹中向用户授予授权,但它不起作用。另外,“config-borne.ini”是一个不存在的文件。
最后我得到了一个解决方案,但它有点不同。由于缺乏授权,我没有在注册表中创建密钥。为了克服这个问题,我选择直接在启动文件夹中创建一个快捷方式(CTRL+R和shell:startup如果你想看的话)。