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";
///
/// Enables auto start
///
public static void EnableAutoStart()
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(REG_ENTRY);
key.SetValue(APP_NAME, Assembly.GetExecutingAssembly().Location);
}
///
/// Disables autostart.
///
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);
}
}
///
/// Checks if auto start is enabled.
///
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);
}
}}
Comments are closed.