{"record":{"id":"cec9db5d17f2309e","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-delete-font-file-after-registry-key-open","errorCode":null,"errorMessage":"unable to delete font file after registry key open error","messagePattern":"unable to delete font file after registry key open error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/cli/font/install_windows.go","lineNumber":70,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to write font file: %s\", err.Error())\n\t}\n\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","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/font/install_windows.go#L52-L88","documentation":"On Windows, font install first creates the registry key HKCU\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts. If CreateKey fails, install attempts to roll back by deleting the already-extracted font file; if that cleanup delete also fails, it returns this combined-failure error. Both the registry open and the file cleanup failed.","triggerScenarios":"Running `oh-my-posh font install` on Windows when registry.CreateKey on HKEY_CURRENT_USER fails (registry access blocked by policy/ACLs, sandboxed process) AND the subsequent os.Remove(fullPath) on the extracted font file fails (file locked by a viewer, permission denied, AV holding the file).","commonSituations":"Corporate machines with registry virtualization or restricted HKCU write access; font file still open in the Windows Font Preview app; antivirus scanning the freshly extracted file; running in a restricted service account context.","solutions":["Close any application holding the extracted font file open (font viewer/explorer preview), then retry.","Check that the process has write access to HKCU\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts (group policy may block it).","Run from a normal user session (not a heavily restricted service/sandbox context).","Manually delete the extracted font file from the temp/target directory and retry the install.","Exclude the font directory from antivirus scanning or wait for the scan to release the file."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Windows, before install: check HKCU write access\nk, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts`, registry.QUERY_VALUE|registry.SET_VALUE)\nif err != nil {\n    return errors.New(\"no write access to per-user font registry key; install blocked by policy?\")\n}\nk.Close()","typeGuard":null,"tryCatchPattern":"if err := font.Install(env, name, report); err != nil {\n    if strings.Contains(err.Error(), \"unable to delete font file\") {\n        log.Printf(\"registry open failed AND cleanup failed; close apps using the font, delete the extracted file manually, check HKCU policy\")\n    }\n    return err\n}","preventionTips":["Verify HKCU\\SOFTWARE write access isn't restricted by group policy before automated installs","Close font viewers/preview panes that can lock the extracted file","Exclude temp/extract directories from antivirus real-time locking during installs"],"tags":["windows","registry","font","filesystem","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"}