Home > Software design >  Can change registry value to 1, but not 0 in C sharp WPF
Can change registry value to 1, but not 0 in C sharp WPF

Time:03-25

My code can correctly access and set the value for enabling window "tips", but I can't disable it for some reason. I should point out that the tool is already running as admin and there are no other processes or code that runs against this.

        // For no reason I can find, this one doesn't work
        private void NoIdontWantEdgeNowOrEver()
        {
            using (RegistryKey hku = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64))
            {
                RegistryKey subKey = hku.CreateSubKey(loggedInSIDStr   @"\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager",true);
                subKey.SetValue("SubscribedContent-338382Enabled", 0, RegistryValueKind.DWord);
            }
        }

        // This one works fine. 
        private void ILikeNaggingHurtMeWindows()
        {
            using (RegistryKey hku = RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64))
            {
                RegistryKey subKey = hku.CreateSubKey(loggedInSIDStr   @"\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager",true);
                subKey.SetValue("SubscribedContent-338382Enabled", 1, RegistryValueKind.DWord);
            }
        }

CodePudding user response:

The code is 100% correct, but I had a typo in the switch that called the disable function so it never executed. This wasn't the case of a magic registry key as I originally thought.

  • Related