C# 开机自动启动

       if (ConfigurationManager.AppSettings["IsBoot"].ToString().Trim().ToUpper() == "TRUE")
            {
                //设置开机启动
                string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rk2.SetValue("JcShutdown", path);
                rk2.Close();
                rk.Close();

            }
            else
            {
                string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rk2.DeleteValue("JcShutdown", false);
                rk2.Close();
                rk.Close();
            }

App.Config:

  <!--是否开机启动 TRUE 启动 FALSE 禁止-->
  <add key="IsBoot" value="FALSE"/>


  

 

 

posted @ 2017-10-29 16:12  涂山吕吕  阅读(834)  评论(0编辑  收藏  举报