1.程序运行时调用下面方法即可。
/// <summary> /// 设置开机自动启用 /// </summary> private void SetAutoStart() { try { string regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";//注册表 string path = Application.ExecutablePath.ToLower(); //获取.exe当前程序路径 //MessageBox.Show(path); string name = Path.GetFileName(path); //获得应用程序名称 //MessageBox.Show(name); var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, true); if (regKey == null) regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath); regKey.SetValue(name, path); } catch { } }