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

                }

            }

  • 相关阅读:
    MSIL实用指南-数据类型转换
    MSIL实用指南-类相关生成
    MSIL实用指南-方法的调用
    MSIL实用指南-struct的生成和操作
    MSIL实用指南-闭包的生成和调用
    Jenkins+maven+gitlab自动化部署之用户权限管理(八)
    Jenkins+maven+gitlab自动化部署之docker发布sprint boot项目(七)
    Centos7部署node
    Jenkins+maven+gitlab自动化部署之前端构建发布(六)
    Jenkins+maven+gitlab自动化部署之构建Java应用(五)
  • 原文地址:https://www.cnblogs.com/zhangjunwei87/p/4704872.html
Copyright © 2011-2022 走看看