private bool setAutoRunValue(bool autorun, string path) { const string AutoFileName = "Speech Recognition"; string ExePath = path; RegistryKey Reg; Reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"); try { if (autorun) { Reg.SetValue(AutoFileName, ExePath); } else { Reg.DeleteValue(AutoFileName); } Reg.Flush(); Reg.Close(); } catch (Exception) { return(false); } return(true); }