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");
                }
            }
  • 相关阅读:
    html标签笔记
    C语言中的函数基础
    数组
    循环控制结构程序(goto、while、dowhile、 for)
    if语句+switch
    分支程序设计
    字符数据的输入与输出
    各类数值型数据之间的混合运算
    c语言概述及如何上机运行c程序
    [记录] Ubuntu 配置Apache虚拟站点
  • 原文地址:https://www.cnblogs.com/zhumeng1582/p/3425798.html
Copyright © 2011-2022 走看看