private void SetAutoStart()
{
try
{
string regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
string path = Application.ExecutablePath.ToLower();
string name = System.IO.Path.GetFileName(path);
var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, true);
if (regKey == null) regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);
regKey.SetValue(name, path);
}
catch { }
}
原文:http://www.cnblogs.com/w519/p/4277396.html