System.UnauthorizedAccessException: Access to the path denied

I am trying to launch automatically my application when I turn on the computer. I’ve wrote this program into my code :

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);
}

The key is indeed in the folder : “SoftwareMicrosoftWindowsCurrentVersionRun”.
But I have a this message which appears in my log :

System.UnauthorizedAccessException: access to the path ‘C:WINDOWSSystem32config_borne.ini’ denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
(….)

I’ve tried to grant autorization to the user in the folder of my application but it doesn’t work. In addition, the “config-borne.ini” is a file which doesn’t exist.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Finnaly I got a solution but it’s a little different. I didn’t create a key in the registry due to the lack of autorization. To overcome this problem, I choose to create a shortcut directly in the startup folder (CTRL+R and shell:startup if you want to see it).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x