zoukankan      html  css  js  c++  java
  • 设置程序开机启动

            public Boolean IsStartUp()
            {
                RegistryKey loca = Registry.LocalMachine;
                RegistryKey run = loca.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
                //未设置开机启动
                if (run.GetValue("Access Controller") != null)
                {
                    loca.Close();
                    run.Close();
                    return true;
                }
                else
                {
                    loca.Close();
                    run.Close();
                    return false;
                }
    
            }
            // 开机启动注册表检查
            public void StartWindows()
            {
                RegistryKey loca = Registry.LocalMachine;
                RegistryKey run = loca.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
                //未设置开机启动
                if (run.GetValue("Access Controller") == null)
                {
                    string starupPath = Application.ExecutablePath;
                    //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
                    //RegistryKey loca = Registry.LocalMachine;
                    //RegistryKey run = loca.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
                    try
                    {
                        run.SetValue("Access Controller", starupPath);
                        //MessageBox.Show("注册表添加成功!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        loca.Close();
                        run.Close();
                    }
                    catch (Exception ee)
                    {
                        PublicClass Publiclass = new PublicClass();
                        Publiclass.MessageBoxTextOk(ee.Message);
                    }
                }
            }
            //取消开机自启
            public void CancelStartUp()
            {
                RegistryKey loca = Registry.LocalMachine;
                RegistryKey run = loca.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
                //未设置开机启动
                if (run.GetValue("Access Controller") != null)
                {
                    string starupPath = Application.ExecutablePath;
                    run.DeleteValue("Access Controller");
                }
            }
  • 相关阅读:
    理解Cookie和Session的区别及使用
    数据库事务
    Mybatis和hibernate的优缺点比较
    MyBatis、JDBC相关知识
    JVM学习笔记(一,待整理)
    laravel运行url404错误
    电影TS、TC、SCR、R5、BD、HD等版本是什么意思
    mysql索引
    双系统更改启动顺序
    PHP Deprecated: Comments starting with '#' are deprecated in *.ini 警告解决办法
  • 原文地址:https://www.cnblogs.com/zhumeng1582/p/3425798.html
Copyright © 2011-2022 走看看