C#用注册表开机自动启动某某软件
2016-01-06 10:10
309 查看
代码如下:
public static void chkAutoRun(bool isRun) { if (isRun)//开机自动启动 { try { RegistryKey runKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); runKey.SetValue("AutoRun.exe", System.Windows.Forms.Application.ExecutablePath); runKey.Close(); this.Text = "注册表修改自启(已开启)"; } catch (IOException ie) { MessageBox.Show(ie.Message); } } else //不开机自动启动注册表信息删除 { RegistryKey software = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); string[] aimnames = software.GetValueNames(); foreach (string aimKey in aimnames) { if (aimKey.Equals("AutoRun.exe")) { software.DeleteValue("AutoRun.exe"); software.Close(); break; } } this.Text = "注册表修改自启(已关闭)"; } }
相关文章推荐
- C#递归算法详解
- c# mdi子窗体简单教程
- C# 将MDI窗口嵌入普通窗口
- C#工厂模式代码实例
- C# 中的委托和事件
- C#学习笔记——MDI窗体(多文档界面)
- C#隐藏Tabcontrol标签
- WINCE平台下C#应用程序中使用看门狗
- C# WinForm中工具栏上如何既显示文字又显示图片
- C#MDI窗体制作;标签大小和屏幕相同
- C#中设置状态栏(statusStrip)的布局
- c#中listview控件如何添加信息
- C#创建Windows Service Windows 服务
- C#实现WinForm禁止最大化、最小化、双击标题栏、双击图标等操作的方法
- 大化设计模式
- C# MD5加密
- C#中Base64之编码,解码方法
- C# 检查进程是否已经启动
- C# 程序等待延迟执行
- c#中使用状态栏