I want to run a C# application at startup. I used this code, which I found here:
private void SetStartup(bool enable)
{
string runKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
RegistryKey startupKey = Registry.CurrentUser.OpenSubKey(runKey);
if (enable)
{
if (startupKey.GetValue("ZanNews") == null)
{
startupKey.Close();
startupKey = Registry.CurrentUser.OpenSubKey(runKey, true);
startupKey.SetValue("ZanNews", "\"" + Application.ExecutablePath + "\"");
startupKey.Close();
}
}
else
{
startupKey = Registry.CurrentUser.OpenSubKey(runKey, true);
startupKey.DeleteValue("ZanNews", false);
startupKey.Close();
}
}
Although the entry appears in the registry and the Task Manager, the program doesn't start with Windows.
Before asking this question, I did prior research on StackOverflow and none of the solutions and code snippets proposed here and here worked. Either I got security and access error messages or the registry was written, but the program refused to start with the operating system. I see, however, that the questions above were asked in 2010 and 2011 and I am thinking that things changed since then.
Is there a way to make a program run at startup? I have Windows 10, Home Edition, version 1803 and .NET Framework 4.7.2 installed on Windows 10 April 2018 Update.
Later edit: other information: