{"record":{"id":"2160fd83479b7fd8","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-open-hkey-current-user","errorCode":null,"errorMessage":"unable to open HKEY_CURRENT_USER","messagePattern":"unable to open HKEY_CURRENT_USER","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/font/install_windows.go","lineNumber":73,"sourceCode":"\n\tlog.Debug(\"font file written successfully, proceeding with registry entry\")\n\n\t// Add registry entry\n\treg := registry.CURRENT_USER\n\tregValue := fullPath\n\n\tlog.Debug(\"opening HKEY_CURRENT_USER for writing (SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Fonts)\")\n\n\tk, _, err := registry.CreateKey(reg, `SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts`, registry.WRITE)\n\tif err != nil {\n\t\tlog.Error(err)\n\t\t// If this fails, remove the font file as well.\n\t\tif nexterr := os.Remove(fullPath); nexterr != nil {\n\t\t\tlog.Error(nexterr)\n\t\t\treturn errors.New(\"unable to delete font file after registry key open error\")\n\t\t}\n\n\t\treturn errors.New(\"unable to open HKEY_CURRENT_USER\")\n\t}\n\n\tdefer func() {\n\t\terr := k.Close()\n\t\tif err != nil {\n\t\t\tlog.Error(err)\n\t\t}\n\t}()\n\n\tfontName := fmt.Sprintf(\"%v (TrueType)\", font.Name)\n\tvar alreadyInstalled, newFontType bool\n\n\tlog.Debugf(\"validating if font %s is already installed\", fontName)\n\n\t// check if we already had this key set\n\toldFullPath, _, err := k.GetStringValue(fontName)\n\tif err == nil {\n\t\tlog.Debugf(\"font %s is already installed with path %s\", fontName, oldFullPath)","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/font/install_windows.go#L55-L91","documentation":"Font install on Windows failed to create/open the per-user fonts registry key (HKCU\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts) via registry.CreateKey with WRITE access. When the rollback deletion of the font file succeeded, this is the error surfaced. The font was not registered and the extracted file was removed.","triggerScenarios":"Calling install (from the fonts CLI) on Windows where registry.CreateKey returns a non-nil error — registry access denied by policy/ACL, corrupted user hive, or running in an environment without HKCU write permission — while os.Remove of the font file succeeds.","commonSituations":"Locked-down corporate Windows images restricting HKCU\\SOFTWARE writes; running inside sandboxes/containers without a real user hive; roaming profile or hive load failures.","solutions":["Verify you can write to HKCU\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts (e.g. with regedit or `reg add`).","Ask IT to lift group-policy restrictions on HKCU\\SOFTWARE for font registration.","Run the install in a normal interactive user session rather than a service or restricted context.","Install the font system-wide for all users instead (requires admin) if per-user registration is blocked."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"k, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts`, registry.SET_VALUE)\nif err != nil {\n    return errors.New(\"HKCU font registry key is not writable in this environment\")\n}\nk.Close()","typeGuard":null,"tryCatchPattern":"if err := font.Install(env, name, report); err != nil {\n    if strings.Contains(err.Error(), \"unable to open HKEY_CURRENT_USER\") {\n        // per-user install blocked; fall back to admin/system-wide font install\n    }\n    return err\n}","preventionTips":["Run installs from a normal interactive user session with a loaded profile hive","Confirm group policy allows HKCU\\SOFTWARE writes on managed machines","Use system-wide (all users) font installation when per-user registration is restricted"],"tags":["windows","registry","font","permissions"],"backgroundTag":"registry-access-denied","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}