zoukankan      html  css  js  c++  java
  • WinForm开机启动 判断 设置



            /// <summary>
            /// 判断是否是开机启动
            /// </summary>
            private void CheckIsKJJD()
            {
                //声明注册表LocalMachine对象

                RegistryKey R_local = Registry.LocalMachine;
                //创建注册表项
                RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                //判断获取的值是否为空
                if (R_run.GetValue("AqiooWebQQ") == null)
                {
                    //为空,不勾选控件
                    checkBox1.Checked = false;
                }
                else
                {
                    //不为空,勾选
                    checkBox1.Checked = true;
                }
                //关闭注册表对象
                R_run.Close();
                //关闭注册表对象

                R_local.Close();
            }

            //CheckBox控件选择事件
            private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                //获得应用程序启动路径
                string R_startPath = Application.ExecutablePath;
                //判断checkBox1控件是否选中
                if (checkBox1.Checked == true)
                {
                    //声明注册表LocalMachine对象

                    RegistryKey R_local = Registry.LocalMachine;
                    //创建注册表项

                    RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                    //设置键AqiooWebQQ的值为变量R_startPath
                    R_run.SetValue("AqiooWebQQ", R_startPath);
                    //关闭注册表对象
                    R_run.Close();
                    //关闭注册表对象

                    R_local.Close();
                }
                else
                {
                    try
                    {
                        //声明注册表LocalMachine对象

                        RegistryKey R_local = Registry.LocalMachine;
                        //创建注册表项

                        RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                        //删除键BirthdayyTipF
                        R_run.DeleteValue("AqiooWebQQ", false);
                        //关闭注册表对象

                        R_run.Close();
                        //关闭注册表对象

                        R_local.Close();
                    }
                    catch (Exception ex)//捕捉错误
                    {
                        //弹出提示框
                        MessageBox.Show("您需要管理员权限修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw;
                    }

                }
            }

  • 相关阅读:
    inline必须在定义、实现都标记
    循环数组优化队列
    游程编码的优化
    新密码
    I Could Have Danced All Night
    strtok源码 bitset 空间压缩
    XOR Swap
    补码
    临时邮箱
    linux中find批量删除空文件夹
  • 原文地址:https://www.cnblogs.com/yonsy/p/2760398.html
Copyright © 2011-2022 走看看