C# 设置开机自动启动

 1  string KJQD = WebConfigurationManager.AppSettings["address"].ToString().Trim();
 2  //string KJQD = Application.ExecutablePath;  //两种方式
 3                 if (!System.IO.File.Exists(KJQD))//判断指定文件是否存在
 4                 {
 5                     MessageBox.Show("呼叫管理员!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
 6 
 7                     return;
 8                 }
 9 
10                 string newKJLJ = KJQD.Substring(KJQD.LastIndexOf("\\") + 1);
11 
12                 RegistryKey Rkey =
13 
14                     Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
15 
16                 if (Rkey == null)
17 
18                     Rkey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
19 
20                 Rkey.SetValue(newKJLJ, KJQD); 
21                 MessageBox.Show("开机启动设置完毕!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

 

posted @ 2014-01-07 14:36  bk.lling  阅读(478)  评论(0)    收藏  举报