'How Can I add keys in Registry Editor whe the app is installed?

I need to add a key cause I need that my application starts at the same time as windows, this is what've done so far.

[RunInstaller(true)]
public partial class Installer1 : Installer
{
    public Installer1() : base()
    {
        InitializeComponent();
    }

    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
            RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            rkApp.SetValue("DNS", Application.ExecutablePath);
            rkApp.Close();

    }

    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
        RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        rkApp.DeleteValue("DNS");
        rkApp.Close();
    }
}

But it doesn't work, the keys are not registered, How can I registry/delete keys when the application is Installed/Unistalled?

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source