//调用方法:设置开机启动
SetAutoRun(Process.GetCurrentProcess().ProcessName, true, Application.StartupPath + @"" + Process.GetCurrentProcess().ProcessName + ".exe");
/// <summary>
/// 设置为开机启动
/// </summary>
private void SetAutoRun(string keyName, bool isAutoRun, string filePath = "")
{
RegistryKey runKey = Registry.CurrentUser.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
if (runKey == null)
runKey = Registry.CurrentUser.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
if (isAutoRun)
runKey.SetValue(keyName, filePath);
else
runKey.DeleteValue(keyName, false);
runKey.Close();
}