JanDeDobbeleer/oh-my-posh · error
unable to set registry value: %s
Error message
unable to set registry value: %s
What it means
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.
Source
Thrown at src/cli/font/install_windows.go:131
// remove the old font resource in case we have a new font type with the same name
if newFontType {
log.Debug("removing old font resource before adding new one")
fontPtr, err := syscall.UTF16PtrFromString(oldFullPath)
if err == nil {
removeFontResourceW := gdi32.NewProc("RemoveFontResourceW")
_, _, _ = removeFontResourceW.Call(uintptr(unsafe.Pointer(fontPtr)))
}
}
if err = k.SetStringValue(fontName, regValue); err != nil {
log.Error(err)
// If this fails, remove the font file as well.
if nexterr := os.Remove(fullPath); nexterr != nil {
return errors.New("unable to delete font file after registry key set error")
}
return fmt.Errorf("unable to set registry value: %s", err.Error())
}
fontPtr, err := syscall.UTF16PtrFromString(fullPath)
if err != nil {
return err
}
ret, _, _ := addFontResourceW.Call(uintptr(unsafe.Pointer(fontPtr)))
if ret == 0 {
return errors.New("unable to add font resource using AddFontResourceW")
}
log.Debug("font resource added successfully")
return nil
}
View on GitHub (pinned to 0976794618)
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
Example fix
// before oh-my-posh font install CascadiaCode // after (elevated shell) sudo oh-my-posh font install CascadiaCode # or run terminal as Administrator on Windows
Defensive patterns
Strategy: try-catch
Validate before calling
// Windows: check elevation before attempting font install
// (PowerShell)
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) { Write-Error 'Run as Administrator to install fonts'; exit 1 } Try / catch
err := env.FontInstall(name)
if err != nil {
if strings.Contains(err.Error(), "unable to set registry value") {
// advise elevation; check %TEMP% for leftover font files
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unable to delete font file after registry key open error
- unable to open HKEY_CURRENT_USER
- unable to delete font file after registry key set error
- Error, no formatter for type: %d
- unable to open window process
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/3c1be222799c0494.
Report an issue: GitHub.