自启动注册

   public void RunWhenStart(bool Started, string name, string path)
        {
            RegistryKey HKLM = Registry.LocalMachine;
            RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");
            if (Started == true)
            {
                try
                {
                    Run.SetValue(name, path);
                    HKLM.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("注册表修改错误(开机自启未实现)");
                }
            }
            else
            {
                try
                {
                    if (Run.GetValue(name) != null)
                    {
                        Run.DeleteValue(name);
                        HKLM.Close();
                    }
                    else
                        return;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    // 
                }
            }
作者:KKcat
    
个人博客:http://jinzhao.me/
    
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/jinzhao/p/1582563.html