zoukankan      html  css  js  c++  java
  • 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;
            }

  • 相关阅读:
    Selenium环境搭建
    系统测试用例评审checklist
    软件测试入门
    App测试方法总结
    好东西并查集
    自己编写一个数组去掉重复元素的函数
    杭电OJ BestCoder28期1001Missing number问题(小技巧偏移法)
    介绍一个二次排序的小技巧(best coder27期1001jump jump jump)
    ntohs的一个简单实现(将网络流中用两个字节16进制表示的资源数(如DNS)和长度转换为整形)
    一个节省空间的小技巧
  • 原文地址:https://www.cnblogs.com/xuchi/p/2288668.html
Copyright © 2011-2022 走看看