加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

使程序开机自启

发布时间:2020-12-14 02:35:14 所属栏目:Windows 来源:网络整理
导读:实现效果: ? ? 知识运用: 注册表项:[ HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun ] ? 下的键值对 实现代码: private void button2_Click(object sender,EventArgs e) { if (textBox1.Text != "") { string pro = textBox1.Text.

实现效果:

  ? ?

知识运用:

  注册表项:[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{}                                              
            }
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读