C Setting Software Auto running Method of Modifying Registry

  • 2021-10-24 23:32:48
  • OfStack

This paper describes the method of setting the software to start up and run automatically by C #. Share it for your reference, as follows:


#region
/// <summary>
///  Startup entry 
/// </summary>
/// <param name="Started"> Whether to start </param>
/// <param name="name"> Name of startup value </param>
/// <param name="path"> Path to start the program  Application.ExecutablePath</param>
public static void RunWhenStart(bool Started, string name, string path)
{
  Microsoft.Win32.RegistryKey HKLM = Microsoft.Win32.Registry.LocalMachine;
  Microsoft.Win32.RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
  if (Started == true)
  {
    try
    {
      Run.SetValue(name, path);
      HKLM.Close();
    }
    catch { }
  }
  else
  {
    try
    {
      Run.DeleteValue(name);
      HKLM.Close();
    }
    catch { }
  }
}
#endregion

More readers interested in C # can check the topic of this site: "C # Traversal Algorithms and Skills Summary", "C # Programming Thread Use Skills Summary", "C # Operating Excel Skills Summary", "C # Common Control Usage Tutorial", "WinForm Control Usage Summary", "C # Data Structure and Algorithm Tutorial", "C # Array Operation Skills Summary" and "C # Object-Oriented Programming Introduction Tutorial"

I hope this article is helpful to everyone's C # programming.


Related articles: