{"record":{"id":"e124ce7edcb2e1f6","repo":"TGSAN/CMWTAT_Digital_Edition","slug":"cannot-create-registry-key-subkey","errorCode":null,"errorMessage":"Cannot create registry key: \" + subKey","messagePattern":"Cannot create registry key: \" \\+ subKey","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CMWTAT_DIGITAL/MainWindow.xaml.cs","lineNumber":906,"sourceCode":"                    WriteDword(hklm, HotpatchPolicyKey, AllowRebootlessUpdates, 1);\n                }\n                else\n                {\n                    DeleteDword(hklm, HotpatchEnvKey, AllowRebootlessUpdates);\n                    DeleteDword(hklm, HotpatchPolicyKey, AllowRebootlessUpdatesProviderSet);\n                    DeleteDword(hklm, HotpatchPolicyKey, AllowRebootlessUpdates);\n                }\n            }\n        }\n\n        private static void WriteDword(RegistryKey baseKey, string subKey, string name, int value)\n        {\n            // 没装过热补丁的机器上这些键可能压根不存在，CreateSubKey 会顺手建出来\n            using (RegistryKey key = baseKey.CreateSubKey(subKey))\n            {\n                if (key == null)\n                {\n                    throw new Exception(\"Cannot create registry key: \" + subKey);\n                }\n                key.SetValue(name, value, RegistryValueKind.DWord);\n            }\n        }\n\n        private static void DeleteDword(RegistryKey baseKey, string subKey, string name)\n        {\n            using (RegistryKey key = baseKey.OpenSubKey(subKey, true))\n            {\n                if (key != null)\n                {\n                    key.DeleteValue(name, false); // 值本来就没有 = 已经是默认状态，不算失败\n                }\n            }\n        }\n\n        private void rebootlessupdatebtn_Click(object sender, RoutedEventArgs e)\n        {","sourceCodeStart":888,"sourceCodeEnd":924,"githubUrl":"https://github.com/TGSAN/CMWTAT_Digital_Edition/blob/efd9a7617af7afed58a2191df056763137a43f87/CMWTAT_DIGITAL/MainWindow.xaml.cs#L888-L924","documentation":"Error \"Cannot create registry key: \" + subKey\" thrown in TGSAN/CMWTAT_Digital_Edition.","triggerScenarios":"Thrown at CMWTAT_DIGITAL/MainWindow.xaml.cs:906 when the library encounters an invalid state.","commonSituations":"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.","solutions":["Run the application elevated (as administrator) so it has write access to HKLM\\SOFTWARE where the hotpatch keys live.","Verify the subKey path is well-formed (no illegal characters, correct hive separators) before calling CreateSubKey.","Check that the registry is not corrupted and the Windows Modules Installer / registry service is running; a corrupt hive can make CreateSubKey return null.","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."],"exampleFix":"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.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"efd9a7617af7afed58a2191df056763137a43f87","analyzedAt":"2026-08-13T13:39:51.543Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}