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{}                                              
                }
            }
    

      

  • 相关阅读:
    STM8s在利用库配置端口的小问题
    ABAP调试
    READ TABLE 的用法
    人在低谷
    力扣 两数之和
    未来选择
    选择
    室友问题该如何解决呢?
    力扣 两数之和
    谈谈自己
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10328411.html
Copyright © 2011-2022 走看看