class AutoRun
{
const string name = "MyTestApplication";
public static bool SetAutorunValue(bool autorun)
{
string ExePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
RegistryKey reg;
reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\");
try
{
if (autorun)
reg.SetValue(name, ExePath);
else
reg.DeleteValue(name);
reg.Close();
}
catch
{
return false;
}
return true;
}
}
AutoRun.SetAutorunValue(true);
class AutoRun
{
const string name = "MyTestApplication";
public static bool SetAutorunValue(bool autorun)
{
string ExePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
RegistryKey reg;
reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\",true); // мы не создаем, а открываем и указываем что будем записывать
try
{
if (autorun)
reg.SetValue(name, ExePath);
else
reg.DeleteValue(name);
reg.Close();
}
catch
{
return false;
}
return true;
}
}