开机运行有种方式实现其功能。这里用的是使用注册表的方式实现此功能
using Microsoft.Win32; //注册表需要引用此命名空间
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键值
2
3 if (CBAutoRun.Checked)
4 {
5 key.SetValue("EventAgent", Application.ExecutablePath);
6 }
7 else
8 {
9 key.SetValue("EventAgent", "");
10 }