Задать вопрос
Ответы пользователя по тегу C#
  • Почему код не работает?

    @MiMitin
    class AutoRun
        {
    
            const string name = "MyTestApplication";
            public static bool SetAutorunValue(bool autorun)
            {
    
                string ExePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                RegistryKey reg;
                reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\",true); // мы не создаем, а открываем и указываем что будем записывать
                try
                {
                    if (autorun)
                        reg.SetValue(name, ExePath);
                    else
                        reg.DeleteValue(name);
    
                    reg.Close();
                }
                catch
                {
                    return false;
                }
                return true;
            }
        }
    Ответ написан