翱翔.Net

释放.Net的力量
posts - 75, comments - 1131, trackbacks - 5, articles - 18
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

(小技巧九)设置开机运行功能

Posted on 2006-05-22 10:29 Hover 阅读(1232) 评论(0) 编辑 收藏
开机运行有种方式实现其功能。这里用的是使用注册表的方式实现此功能
using Microsoft.Win32; //注册表需要引用此命名空间
 1  RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"true);
 2
 3            if (CBAutoRun.Checked)
 4            {
 5                key.SetValue("EventAgent", Application.ExecutablePath);
 6            }

 7            else
 8            {
 9                 key.SetValue("EventAgent""");
10               }
CheckBox选中写注册表。否清空EventAgent键值