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");
                }
            }
  • 相关阅读:
    全选+批量删除
    ssm异步上传图片
    抽象类与接口区别
    请求转发和重定向区别
    switch
    一道有点绕弯,考察的知识也是最基础的题
    线程安全之集合
    会话跟踪技术
    关于异常说明
    mybatis总结(三)之多表查询
  • 原文地址:https://www.cnblogs.com/zhumeng1582/p/3425798.html
Copyright © 2011-2022 走看看