设置程序开机启动
public Boolean IsStartUp() { RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); //未设置开机启动 if (run.GetValue("Access Controller") != null) { loca.Close(); run.Close(); return true; } else { loca.Close(); run.Close(); return false; } } // 开机启动注册表检查 public void StartWindows() { RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); //未设置开机启动 if (run.GetValue("Access Controller") == null) { string starupPath = Application.ExecutablePath; //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装. //RegistryKey loca = Registry.LocalMachine; //RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); try { run.SetValue("Access Controller", starupPath); //MessageBox.Show("注册表添加成功!", title, MessageBoxButtons.OK, MessageBoxIcon.Information); loca.Close(); run.Close(); } catch (Exception ee) { PublicClass Publiclass = new PublicClass(); Publiclass.MessageBoxTextOk(ee.Message); } } } //取消开机自启 public void CancelStartUp() { RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); //未设置开机启动 if (run.GetValue("Access Controller") != null) { string starupPath = Application.ExecutablePath; run.DeleteValue("Access Controller"); } }