TGSAN/CMWTAT_Digital_Edition · error · Exception

Cannot create registry key: " + subKey

Error message

Cannot create registry key: " + subKey

What it means

Error "Cannot create registry key: " + subKey" thrown in TGSAN/CMWTAT_Digital_Edition.

Source

Thrown at CMWTAT_DIGITAL/MainWindow.xaml.cs:906

                    WriteDword(hklm, HotpatchPolicyKey, AllowRebootlessUpdates, 1);
                }
                else
                {
                    DeleteDword(hklm, HotpatchEnvKey, AllowRebootlessUpdates);
                    DeleteDword(hklm, HotpatchPolicyKey, AllowRebootlessUpdatesProviderSet);
                    DeleteDword(hklm, HotpatchPolicyKey, AllowRebootlessUpdates);
                }
            }
        }

        private static void WriteDword(RegistryKey baseKey, string subKey, string name, int value)
        {
            // 没装过热补丁的机器上这些键可能压根不存在,CreateSubKey 会顺手建出来
            using (RegistryKey key = baseKey.CreateSubKey(subKey))
            {
                if (key == null)
                {
                    throw new Exception("Cannot create registry key: " + subKey);
                }
                key.SetValue(name, value, RegistryValueKind.DWord);
            }
        }

        private static void DeleteDword(RegistryKey baseKey, string subKey, string name)
        {
            using (RegistryKey key = baseKey.OpenSubKey(subKey, true))
            {
                if (key != null)
                {
                    key.DeleteValue(name, false); // 值本来就没有 = 已经是默认状态,不算失败
                }
            }
        }

        private void rebootlessupdatebtn_Click(object sender, RoutedEventArgs e)
        {

View on GitHub (pinned to efd9a7617a)

Solutions

  1. Run the application elevated (as administrator) so it has write access to HKLM\SOFTWARE where the hotpatch keys live.
  2. Verify the subKey path is well-formed (no illegal characters, correct hive separators) before calling CreateSubKey.
  3. Check that the registry is not corrupted and the Windows Modules Installer / registry service is running; a corrupt hive can make CreateSubKey return null.
  4. On machines where the hotpatch keys are absent, let CreateSubKey create them (as the code does) rather than requiring pre-existing keys; if it still returns null, inspect antivirus/EDR registry filtering that may silently block key creation.

Example fix

Start CMWTAT_DIGITAL from an elevated context (right-click → Run as administrator) before toggling the rebootless-update feature. Elevation grants the HKLM write rights needed by RegistryKey.CreateSubKey(subKey), so WriteDword no longer gets a null key and the exception is not thrown. If elevation is not acceptable, pre-create the subKey under HKLM with an installer that has the required rights.

When it happens

Trigger: Thrown at CMWTAT_DIGITAL/MainWindow.xaml.cs:906 when the library encounters an invalid state.

Common situations: Occurs when RegistryKey.CreateSubKey returns null while toggling rebootless (hotpatch) update keys under HKLM. Typical causes: the app is not running elevated (administrator rights are required to write under HKEY_LOCAL_MACHINE), registry access is blocked by group policy or antivirus/EDR software, the 64-bit registry view is unavailable, or the subkey path is malformed. Run the application as administrator and verify no policy denies writes to HKLM\SOFTWARE keys used by the hotpatch feature.


AI-assisted analysis of TGSAN/CMWTAT_Digital_Edition@efd9a7617a (2026-08-13). Data as JSON: /api/errors/e124ce7edcb2e1f6. Report an issue: GitHub.