public static void SetRegistryIsStart(bool IsStart)
{
if (IsStart)
{
try
{
string strAssName = Application.StartupPath + @"\" + Application.ProductName + @".exe";
string ShortFileName = Application.ProductName;
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
{
rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
rgkRun.SetValue(ShortFileName, strAssName);
}
else
{
rgkRun.SetValue(ShortFileName, strAssName);
}
}
catch
{
}
}
else
{
try
{
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true).DeleteValue(Application.ProductName, false);
}
catch
{
}
}
}