zoukankan      html  css  js  c++  java
  • 使程序开机自启

    实现效果:

         

    知识运用:

      注册表项:[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun] 下的键值对

    实现代码:

            private void button2_Click(object sender, EventArgs e)
            {
                if (textBox1.Text != "")
                {
                    string pro = textBox1.Text.Trim();
                    string proName = textBox1.Text.Substring(pro.LastIndexOf("\")+1);  //获取文件名
                    RegistryKey rk=Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun",true);
                    if (rk ==null)                                                      //如果指定项不存在
                        rk = Registry.LocalMachine.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
                    rk.SetValue(proName,pro);
                    if (MessageBox.Show("设置成功!") == DialogResult.OK)
                        RefreshSystem();                                               //刷新系统
                }
            }
            private void button3_Click(object sender, EventArgs e)
            {
                if (textBox1.Text != "")
                {
                    try
                    {
                        string pro = textBox1.Text.Trim();
                        string proName = textBox1.Text.Substring(pro.LastIndexOf("\") + 1);  //获取文件名
                        RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
                        if (rk == null)                                                      //如果指定项不存在
                            rk = Registry.LocalMachine.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
                        rk.DeleteValue(proName);
                        if (MessageBox.Show("设置成功!") == DialogResult.OK)
                            RefreshSystem(); 
                    }
                    catch{}                                              
                }
            }
    

      

  • 相关阅读:
    Numpy(0)
    C++(成员函数做友元)
    C++(类做友元)
    CUDA---Arrayfire---添加cuda kernel
    CUDA--Arrayfire--类型转换
    C++(友元)
    C++(const修饰成员函数)
    C++(空指针访问成员函数)
    第9章 整合前端
    第8章 离不开的数据库
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10328411.html
Copyright © 2011-2022 走看看