1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static bool SetAutoRun(bool enable = true)
{
try
{
Assembly current = Assembly.GetExecutingAssembly();
var key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
if(enable)
key.SetValue(current.GetName().Name, $"\"{current.Location}\"");
else
key.DeleteValue(current.GetName().Name);
return true;
}
catch
{
return false;
}
}