Method of Program Startup Based on C

  • 2021-10-13 08:29:07
  • OfStack

This paper describes the method of C # to realize program startup. Share it for your reference, as follows:


// This method loads the startup key into the registry 
// Get the application path 
string strAssName = Application.StartupPath + @"\" + Application.ProductName + @".exe";
// Get the application name 
string ShortFileName = Application.ProductName;
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
{
  rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
rgkRun.SetValue(ShortFileName, strAssName);
// This deletes the startup key in the registry 
// Get the application name 
string ShortFileName = Application.ProductName;
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
{
  rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
rgkRun.DeleteValue(ShortFileName, false);

For more readers interested in C # related content, please check out the topics on this site: "C # Common Control Usage Tutorial", "C # Data Structure and Algorithm Tutorial", "C # Object-Oriented Programming Introduction Tutorial" and "C # Programming Thread Use Skills Summary"

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


Related articles: