title: How can I run a program on computer startup?
body: <p>I have a C# MVC program that I want to run when the computer starts regardless if a user has signed in or not. The program will be running on Windows 7 &amp; Windows 10 machines. This is the code I have written but I'm not sure if it's working correctly. This code runs if a checkbox is selected:</p>
  
  <pre><code>private void runOnStartup_Checked(object sender, RoutedEventArgs e)
  {
      Properties.Settings.Default.startup = true;          
      Properties.Settings.Default.Save();
  
      RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
      registryKey.SetValue("MyProgram", Assembly.GetExecutingAssembly());
  
  
  
      WshShell wshShell = new WshShell();
      IWshRuntimeLibrary.IWshShortcut shortcut;
      string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
      shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(startUpFolderPath + "\\Shortcutpath.something");
      shortcut.TargetPath = Assembly.GetExecutingAssembly().Location;
      shortcut.WorkingDirectory = Assembly.GetExecutingAssembly().Location; 
      shortcut.Description = "My program";
      shortcut.Save();
  }
  </code></pre>
  
  <p>If this isn't the proper way to get an application to run as soon as the machine starts, please let me know and I can change the code.</p>
  
  <p>EDIT: I should have noted that this is a WPF application, with an interface.</p>