private void AutoMenu_Click(object sender, EventArgs e)
        {
            
string strName = Application.ExecutablePath;
            
string strnewName = strName.Substring(strName.LastIndexOf("\\"+ 1);
            
if (AutoMenu.Checked)
            {
                
//修改注册表,使程序开机时不自动执行。  
                this.AutoMenu.Checked = false;
                Microsoft.Win32.RegistryKey Rkey 
= Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                Rkey.DeleteValue(strnewName, 
false);
                MessageBox.Show(
"程序设置完成!""提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            
else
            {
                
this.AutoMenu.Checked = true;
                
if (!File.Exists(strName))//指定文件是否存在  
                    return;
                Microsoft.Win32.RegistryKey Rkey 
= Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"true);
                
if (Rkey == null)
                    Rkey 
= Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                Rkey.SetValue(strnewName, strName);
//修改注册表,使程序开机时自动执行。  
                MessageBox.Show("程序设置完成,重新启动计算机后即可生效!""提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

相关文章:

  • 2021-07-26
  • 2021-11-24
  • 2021-12-29
  • 2021-08-08
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2021-12-19
  • 2021-12-04
相关资源
相似解决方案