使程序开机自启
程序 开机 自启
2023-09-14 08:58:58 时间
实现效果:
知识运用:
注册表项:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] 下的键值对
实现代码:
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(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true); if (rk ==null) //如果指定项不存在 rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); 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(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); if (rk == null) //如果指定项不存在 rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); rk.DeleteValue(proName); if (MessageBox.Show("设置成功!") == DialogResult.OK) RefreshSystem(); } catch{} } }
相关文章
- itop4412开发板添加开机启动程序
- IIS配置Asp.net时,出现“未能加载文件或程序集“System.Web.Extensions.Design, Version=1.0.61025.0”
- Linux 设置程序开机自启动 (命令systemctl 和 chkconfig用法区别比较)
- 编写高质量代码改善java程序的151个建议——[52-57]String !about String How to use them?
- Linux中程序开机自启
- glassfish3 读不到web程序的jar包
- 会员管理小程序实战开发教程-会员信息编辑
- C程序-蓝桥-简单加法
- 汇编学习(六)——代码转换程序
- 遇到的C++ cli 转 C++ native 为C# 程序提供接口。
- 【小程序】微信小程序开发流程
- ZYNQ - 无DDR固化程序(代码运行在OCM上)
- 仅三行代码的按键扫描程序,绝对够经典(转载学习)
- 在Linux环境下运行你的第一个C语言程序
- Python:4-2月份格式转换程序