Exemple #1
0
        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);
        }
Exemple #2
0
 public void ChangeAutoRun()
 {
     try
     {
         if (_autoRun == ChBAutoRun.Checked)
         {
             return;
         }
         var ans = MessageBox.Show(
             $@"Está seguro de que quiere {(ChBAutoRun.Checked ? "Activar" : "Desactivar")} el inicio automático", @"Confirmación cambio de inicio automático", MessageBoxButtons.OKCancel);
         if (ans == DialogResult.Cancel)
         {
             return;
         }
         if (ChBAutoRun.Checked)
         {
             Reg.SetValue(AppName, $"{ApplicationPath} auto");
         }
         else
         {
             Reg?.DeleteValue(AppName);
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.Message, @"Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #3
0
        /// <summary>
        /// 注册表操作,删除注册表中启动项
        /// </summary>
        public static bool DeleteRegisterApp(string name)
        {
            try
            {
                if (!CheckExistRegisterApp(name))
                {
                    return(true);
                }

                Microsoft.Win32.RegistryKey Reg;
                Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (Reg == null)
                {
                    Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
                }
                Reg.DeleteValue(name, false);
                Reg.Close();
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// 注册表操作,删除注册表中启动项
        /// </summary>
        public static bool DeleteRegisterApp()
        {
            string ShortFileName = Application.ProductName;           //获得应用程序名

            try
            {
                Microsoft.Win32.RegistryKey Reg;
                Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (Reg == null)
                {
                    Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
                }
                Reg.DeleteValue(ShortFileName, false);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
 public void DeleteValue(string key, string reg)
 {
     Reg.DeleteValue(Registry.LocalMachine, _key + "\\" + key, reg);
 }