简体   繁体   English

Windows启动时停止应用程序服务

[英]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. 通过此代码,我可以在Windows启动时自动启动我的应用程序。 (like Skype) But I want to stop auto-running my app through c# coding. (例如Skype),但我想停止通过c#编码自动运行我的应用程序。 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();
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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