• 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;
                    }

                }
            }

  • 相关阅读:
    FAQs: 当在Outlook Explorer中右击邮件时,如何向上下文菜单添加按钮?(VSTO技术)
    C#设置系统日期和时间
    控制带有滚动条的控件(ListView,TreeView等)的滚动条显示
    HTML Clipboard Format [MSDN资料]
    Control.ProcessDialogKey 方法 ——用以处理对话框按键(TAB ESC 箭头键 等)
    span 标记的可编辑与不可编辑
    教训:System.TypeInitializationException 类型初始值设定项引发异常
    firefox 插件制作
    base64编码
    找工作了,应聘简历
  • 原文地址:https://www.cnblogs.com/yonsy/p/2760398.html
Copyright © 2020-2023  润新知