简体   繁体   中英

Stop service of Application When Windows Start

RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
reg.SetValue("MyApp", Application.ExecutablePath.ToString());
reg.Close();

From this code, I am able to auto-start my app at the start of windows. (like Skype) But I want to stop auto-running my app through c# coding. Anyone knows the code of it??

I give an optional setting in my application about auto run. If radio Button yes is checked then app should have run automatically but if radio button no is checked then it should not run automatically.

Below is my coding but through it I am not able to stop my app from auto-running.

    private void groupBox1_Enter(object sender, EventArgs e)
    {

    if (btnno.Checked == true)
        {
            DisposeStartup();
        }
        else if (btnyes.Checked == true)
        {
            ActivateStartup();
        }
    }

    private void ActivateStartup()
    {
        reg.SetValue("MyApp", Application.ExecutablePath.ToString());
        reg.Close();
    }
        private void DisposeStartup()
         {
        if (reg != null)
        {
            reg.DeleteValue("MyApp", true);
            reg.Close();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM