My plan with CommonRSS was to have it run as a regular application (not a service, just did not want to be bothered yet). So one of the first problems that occurred to me was how you go about starting an application when the OS started. I also wanted to enable\disable that functionality through the registry so this is the class I came up with to support that. 

using Microsoft.Win32;
using System.Reflection;

static class UtilityFuncs
{
    private const string APP_NAME = "CommonRSS"; //replace this with the name of your application
    private const string REG_ENTRY = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";

    /// <summary>
    /// Enables auto start
    /// </summary>
    public static void EnableAutoStart()
    {
        RegistryKey key = Registry.CurrentUser.CreateSubKey(REG_ENTRY);
        key.SetValue(APP_NAME, Assembly.GetExecutingAssembly().Location);
    }

 

    /// <summary>
    /// Disables autostart.
    /// </summary>
    public static void DisableAutoStart()
    {
        RegistryKey key = Registry.CurrentUser.OpenSubKey(REG_ENTRY);
        if (key != null)
        {
            string val = (string)key.GetValue(APP_NAME);
            if (val != null)
                key.DeleteValue(APP_NAME);
        }
    }

 

    /// <summary>
    /// Checks if auto start is enabled.
    /// </summary>
    public static bool IsAutoStartEnabled
    {
        get
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(REG_ENTRY);
            if (key == null)
            {
                return false;
            }

            string val = (string)key.GetValue(APP_NAME);
            if (val == null)
                return false;

 

            return (val == Assembly.GetExecutingAssembly().Location);
        }
    }

}

Technorati Tags: ,