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

                }

            }

    推荐:Unity3D保护资源管理文件的AssetBundle包加密!

    。net交流
  • 相关阅读:
    &nbsp|&quot|&amp|&lt|&gt等html字符转义
    OpenSSL: 消息摘要算法
    Linux下tcp协议socket的recv函数返回时机分析(粘包)
    ipv6
    Electron 调用系统工具记事本、计算器等
    MySQL 导出函数与存储过程
    远程连接Ubuntu桌面配置
    当Activity继承AppCompatActivity如何实现隐藏标题栏与状态栏
    spring boot 1.5.2 操作mongodb3.4.0
    VScode-Go can't load package: package .: no buildable Go source files in
  • 原文地址:https://www.cnblogs.com/hcyblogs/p/4703790.html
Copyright © 2011-2022 走看看