Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

startup c# class winform

using System;
using System.Windows.Forms;
using Microsoft.Win32;

public class StartupManager : Form
{
    // The path to the key where Windows looks for startup applications
	static RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun", true);
	/// <summary>
    /// Checking if the startup is already enabled or not
    /// </summary>
    /// <returns>Returns the state of the startup</returns>
	public static bool IsStartupInitialized()
	{
		return rkApp.GetValue(Application.ProductName) != null;
    }
    /// <summary>
    /// Changing the app startup state
    /// </summary>
    /// <param name="to">Set startup state to</param>
    public void SetStartupState(bool to)
    {
        if (to)
        {
            // Add the value in the registry so that the application runs at startup
            rkApp.SetValue(Application.ProductName, Application.ExecutablePath);
        }
        else
        {
            // Remove the value from the registry so that the application doesn't start
            rkApp.DeleteValue(Application.ProductName, false);
        }
     }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #startup #class #winform
ADD COMMENT
Topic
Name
1+1 =