string KJLJ = Application.ExecutablePath;
if (!System.IO.File.Exists(KJLJ))//判断指定文件是否存在
return;
string newKJLJ = KJLJ.Substring(KJLJ.LastIndexOf("\\") + 1);
RegistryKey Rkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (Rkey == null) {
Rkey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
Rkey.SetValue(newKJLJ, KJLJ);
MessageBox.Show("程序设置完毕,请重新启动计算机后即可生效!");
此代码并非原创,我在代码中使用的时候觉得不错,就记录一下,方便以后使用的查找,如有侵权,请联系我删除!因为原文我找不到了,谢谢!