Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 131,917 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,688 people online right now. Registration is fast and FREE... Join Now!





Run your Program on Startup

Run your Program on your System Startup.

Submitted By: gbertoli3
Actions:
Rating:
Views: 577

Language: C#

Last Modified: October 11, 2008
Instructions: Use:
//Method 1
RunStartup(true);
//Method 2
Startup = true;

Snippet


  1. /// <summary>
  2. /// Runs the Program on Startup.
  3. /// </summary>
  4. /// <param name="RunOnStartup">True to Run on Startup, False to NOT Run on Startup.</param>
  5. private void RunStartup(Boolean RunOnStartup)
  6. {
  7.     Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  8.     if (RunOnStartup == true)
  9.     {
  10.         key.SetValue("Application Name", Application.ExecutablePath.ToString());
  11.     }
  12.     else
  13.     {
  14.         key.DeleteValue("Application Name", false);
  15.     }
  16. }
  17.  
  18. /// <summary>
  19. /// Gets or Sets if the Program will Run on Startup.
  20. /// </summary>
  21. private bool Startup
  22. {
  23.     get
  24.     {
  25.         return Startup;
  26.     }
  27.     set
  28.     {
  29.         Startup = value;
  30.         Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  31.         if (Startup == true)
  32.         {
  33.             key.SetValue("Application Name", Application.ExecutablePath.ToString());
  34.         }
  35.         if (Startup == false)
  36.         {
  37.             key.DeleteValue("Application Name", false);
  38.         }
  39.     }
  40. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month