C#/WPF let the program boot automatically

Source: Internet
Author: User

Recently a C/s project customer requirements Start-up function, online find some methods, not useful; Finally, I went to the book, found this code, pro-Test available, WPF environment needs to change the way to get the program directory, WinForm directly available.

1             #regionSet power-on self-boot2             stringStrName = AppDomain.CurrentDomain.BaseDirectory +"AutoRunPro.exe";//get the name of the application to run automatically3             if(! System.IO.File.Exists (StrName))//determine if an application file to run automatically exists4                 return;5             stringstrNewName = strname.substring (Strname.lastindexof ("\\") +1);//get application file name, not including path6RegistryKey Registry = Registry.LocalMachine.OpenSubKey ("Software\\microsoft\\windows\\currentversion\\run",true);//retrieves the specified subkey7             if(Registry = =NULL)//If the specified subkey does not exist8Registry = Registry.LocalMachine.CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run");//The specified subkey is created9Registry. SetValue (strNewName, strName);//set a new "key-value pair" for this subkeyTen  One             if(MessageBox.Show ("Setup Complete") ==DialogResult.OK) A             { -Refreshsystem ();//Refresh the System -             } the             #endregion
1             #regionCancel power-on self-boot2             stringStrName = AppDomain.CurrentDomain.BaseDirectory +"AutoRunPro.exe";//get the name of the application to run automatically3             if(! System.IO.File.Exists (StrName))//determine if the application file to be canceled exists4                 return;5             stringstrNewName = strname.substring (Strname.lastindexof ("\\") +1);///get application file name, not including path6RegistryKey Registry = Registry.LocalMachine.OpenSubKey ("Software\\microsoft\\windows\\currentversion\\run",true);//reads the specified subkey7             if(Registry = =NULL)//If the specified subkey does not exist8Registry = Registry.LocalMachine.CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run");//The specified subkey is created9Registry. DeleteValue (strNewName,false);//Remove key/value pairs for the specified key nameTen             if(MessageBox.Show ("Setup Complete") ==DialogResult.OK) One             { A Refreshsystem (); -             } -             #endregion

C#/WPF let the program boot automatically

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.