• c# 开机自动启动


     /// <summary>
           ///  自动启动设置
           /// </summary>
           /// <param name="started">标记是否自动启动</param>
           /// <param name="name">程序名称</param>
           /// <param name="path">程序所在路径</param>
            public void AutoRunWhenStart(bool started, string name, string path)
            {
                RegistryKey HKLM = Registry.LocalMachine;
                RegistryKey run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\");
                if (started)
                {
                    try
                    {
                        run.SetValue(name, path);

                        MessageBox.Show("已设为开机自动启动");

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString(), "程序异常");
                    }
                    finally
                    {
                        run.Close();
                        HKLM.Close();

                    }
                }
                else
                {
                    try
                    {
                        run.DeleteValue(name);

                        MessageBox.Show("已关闭开机自动启动");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString(), "程序异常");
                    }
                    finally
                    {
                        run.Close();
                        HKLM.Close();

                    }
                }
            }
           /// <summary>
            /// 检测软件当前是否为开机自动启动状态
           /// </summary>
           /// <param name="name">注册项名称</param>
           /// <returns></returns>
            public bool checkIsAutoRun(string name)
            {
                bool istrue = false;
                RegistryKey HKLM = Registry.LocalMachine;
                RegistryKey run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\");
                if (run.GetValue(name) != null)
                {
                    istrue = true;
                }
                else
                {
                    istrue = false;
                }
                run.Close();
                HKLM.Close();
                return istrue;
            }

  • 相关阅读:
    Swing 顶层容器
    创建第一个界面程序
    SWING
    通俗解释高中生能听懂的SVM本质和原理
    [初学者入门]任何机器学习套路?逻辑回归是什么?要有哪些未知参数待求解?如何优化?梯度下降是什么?如何用梯度下降
    贝叶斯公式在机器学习中有什么用,实例讲解Python实现朴素贝叶斯分类器
    通俗易懂适合初学者的机器学习实战(1):k- Nearest Neighbor (k个最近的邻居)KNN算法
    Python从0开始实现Numpy矩阵库,拒绝掉包侠,学习造轮子
    99%的人都会忽略的Python易错点总结
    遇到问题,有哪些有效的分析方法?
  • 原文地址:https://www.cnblogs.com/xuchi/p/2288668.html
Copyright © 2020-2023  润新知