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

      

  • 相关阅读:
    socket通信原理
    socket通信基础内容
    内核中断过程
    爬虫基础模块
    关于多个运算符的问题
    前戏
    js扩展
    加密
    django之form
    Django
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10328411.html
Copyright © 2011-2022 走看看