0

I am trying to add a Value into this path but It is giving an Exception:

UnauthorizedAccessException was unhandled.

My snippet

    private void btnStart_Click(object sender, EventArgs e)
    {
     RegistryKey Localuser= Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
     Localuser.SetValue("DefaultPassword","Password35");
    }
Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191
Onur CAN
  • 81
  • 11

1 Answers1

1

You are trying to set the registry value of the local machine's key. You need administrator's right to do that. You should compile the program and run it as administrator.

If you need to make it run in debug mode, try the solution from this post.

Another thing to take note: Make sure you call the function specifying it writable

RegistryKey Localuser= Registry.LocalMachine.OpenSubKey(
    "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
    true);
Yuan Shing Kong
  • 674
  • 5
  • 15