注册表设置开机启动

   Registry下可以选择LocalMachine,CurrentUser分别对应不同的注册表路径:    

             1.HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

             2.HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\

 /// <summary>
        /// 写入注册表开机自动启动
        /// </summary>
        /// <param name="IsAtuoRun">true:设置开机启动;false:不开机启动</param>
        /// <returns></returns>
        public static bool SetAutoStart(bool IsAtuoRun)
        {
            bool bOk = false;
            try
            {
                //注册表路径
                RegistryKey runItem = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
                if (IsAtuoRun)
                {
                    //开机启动项名称和启动项(exe,快捷方式或其他)的路径
                    runItem.SetValue("NeoLink_AirPlaneDispatch", Application.ExecutablePath);
                }
                else
                {
                    runItem.SetValue("NeoLink_AirPlaneDispatch", "");
                }
                bOk = true;
            }
            catch (Exception ex) { Utility.LogToTxt("", "SetAutoStart()>>" + ex.Message.ToString()); }
            return bOk;
        }
原文地址:https://www.cnblogs.com/luofuxian/p/2575066.html