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();

                }

            }

  • 相关阅读:
    班服 状压DP NOIP模拟赛
    记录奥林比克/课程录制 洛谷P2255 [USACO14JAN]
    字符串的展开 vijos1379 NOIP2007 字符串 模拟
    树网的核 Vijos1362 NOIP2007 树结构 直径 暴搜
    浏览器(Web Navigation) codevs 5373 POJ 1028 简单模拟
    FPS集合 Codgic1351 动态规划 DP NOIP模拟赛
    基于VBA的Excel抽奖软件
    【CodeForces】Round #436
    【NOI OpenJudge】【1.3】编程基础之算术表达式与顺序执行
    【NOI OpenJudge】【1.2】编程基础之变量定义、赋值及转换
  • 原文地址:https://www.cnblogs.com/zhangjunwei87/p/4704872.html
Copyright © 2011-2022 走看看