Winform设置开机启动-操作注册表

#region 设置开机运行
/// <summary>
/// 设置开机运行
/// </summary>
/// <param name="R_startPath">需要运行的程序.exe</param>
/// <returns></returns>
public static bool SetStartRun(string R_startPath)
{
     if (!File.Exists(R_startPath))
          return false;
     FileInfo fi = new FileInfo(R_startPath);
     string newName = fi.Name;
     RegistryKey Rkey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
     if (Rkey == null)
          Rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
     Rkey.SetValue(newName, R_startPath);
     Rkey.Close();
     return true;
}
#endregion

 说明:

1、需要给winform软件管理员权限

2、R_startPath为:winfrom软件exe文件的完整路径

原文地址:https://www.cnblogs.com/yuejin/p/3445657.html