zoukankan      html  css  js  c++  java
  • winform 程序开机启动

       private void Form1_Load(object sender, EventArgs e)

            {

                try

                {

                    //程序运行位置

                    string R_startPath = Application.ExecutablePath;

                    //对应于HKEY_LOCAL_MACHINE主键

                    RegistryKey R_local = Registry.LocalMachine;

                    //开机自动运行

                    RegistryKey R_run = R_local.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

                    R_run.SetValue("MyAuto", R_startPath);

                    R_run.Close();

                    R_local.Close();

                }

                catch (Exception ex)

                {

                    MessageBox.Show(ex.Message);

                }

                Console.WriteLine("开机自动运行!");

            }

            /// <summary>

            /// 开机启动    复选框

            /// </summary>

            /// <param name="sender"></param>

            /// <param name="e"></param>

            private void cb_kaiji_CheckedChanged(object sender, EventArgs e)

            {

                if (cb_kaiji.Checked)

                {

                    //程序运行位置

                    string R_startPath = Application.ExecutablePath;

                    //对应于HKEY_LOCAL_MACHINE主键

                    RegistryKey R_local = Registry.LocalMachine;

                    //开机自动运行

                    RegistryKey R_run = R_local.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

                    R_run.SetValue("MyAuto", R_startPath);

                    R_run.Close();

                    R_local.Close();

                }

                else {

                    //程序运行位置

                    string R_startPath = Application.ExecutablePath;

                    //对应于HKEY_LOCAL_MACHINE主键

                    RegistryKey R_local = Registry.LocalMachine;

                    //开机自动运行

                    RegistryKey R_run = R_local.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

                    R_run.SetValue("MyAuto", false);

                    R_run.Close();

                    R_local.Close();

                }

            }

  • 相关阅读:
    机器学习python实战----决策树
    机器学习python实战----手写数字识别
    机器学习python实战----k近邻算法
    斯坦福2014机器学习笔记八----机器学习系统的设计
    斯坦福2014机器学习笔记七----应用机器学习的建议
    斯坦福2014机器学习笔记六----神经网络(二)
    Global Game Jam 2019 深圳站 个人总结
    加法乘法线段树模板
    线段树模板题
    单调栈和单调队列入门
  • 原文地址:https://www.cnblogs.com/zhangjunwei87/p/4704872.html
Copyright © 2011-2022 走看看