{"record":{"id":"3c1be222799c0494","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-set-registry-value-s","errorCode":null,"errorMessage":"unable to set registry value: %s","messagePattern":"unable to set registry value: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/font/install_windows.go","lineNumber":131,"sourceCode":"\n\t// remove the old font resource in case we have a new font type with the same name\n\tif newFontType {\n\t\tlog.Debug(\"removing old font resource before adding new one\")\n\t\tfontPtr, err := syscall.UTF16PtrFromString(oldFullPath)\n\t\tif err == nil {\n\t\t\tremoveFontResourceW := gdi32.NewProc(\"RemoveFontResourceW\")\n\t\t\t_, _, _ = removeFontResourceW.Call(uintptr(unsafe.Pointer(fontPtr)))\n\t\t}\n\t}\n\n\tif err = k.SetStringValue(fontName, regValue); 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\treturn errors.New(\"unable to delete font file after registry key set error\")\n\t\t}\n\n\t\treturn fmt.Errorf(\"unable to set registry value: %s\", err.Error())\n\t}\n\n\tfontPtr, err := syscall.UTF16PtrFromString(fullPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tret, _, _ := addFontResourceW.Call(uintptr(unsafe.Pointer(fontPtr)))\n\tif ret == 0 {\n\t\treturn errors.New(\"unable to add font resource using AddFontResourceW\")\n\t}\n\n\tlog.Debug(\"font resource added successfully\")\n\n\treturn nil\n}\n","sourceCodeStart":113,"sourceCodeEnd":148,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/font/install_windows.go#L113-L148","documentation":"During Windows font installation, after the font file is copied, oh-my-posh registers the font under HKLM's registry key for fonts. If the registry write fails, the install cannot complete, so the code attempts to delete the copied font file and returns this wrapped error containing the underlying registry failure. It only occurs on Windows with admin/HKLM write context.","triggerScenarios":"Running `oh-my-posh font install` on Windows when the registry write to the fonts key fails — typically due to insufficient privileges, registry key locked by policy, or antivirus blocking writes.","commonSituations":"Installing a font without running the terminal as Administrator; corporate GPO restricting HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts writes; security software intercepting registry modifications.","solutions":["Re-run the command from an elevated (Administrator) terminal","Check registry permissions / group policy on the Fonts key","Temporarily exclude the font file from antivirus/EDR blocking and retry","Install the font manually (double-click the TTF and use Windows' own installer) if automation is not required"],"exampleFix":"// before\noh-my-posh font install CascadiaCode\n// after (elevated shell)\nsudo oh-my-posh font install CascadiaCode  # or run terminal as Administrator on Windows","handlingStrategy":"try-catch","validationCode":"// Windows: check elevation before attempting font install\n// (PowerShell)\n$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)\nif (-not $isAdmin) { Write-Error 'Run as Administrator to install fonts'; exit 1 }","typeGuard":null,"tryCatchPattern":"err := env.FontInstall(name)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to set registry value\") {\n        // advise elevation; check %TEMP% for leftover font files\n    }\n}","preventionTips":["Always run font installs from an elevated shell on Windows","Check corporate GPO restrictions on the Fonts registry key beforehand","Look for leftover font files in the temp dir after a failure and clean them up"],"tags":["windows","registry","font-install","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"}