JanDeDobbeleer/oh-my-posh · critical
unable to delete font file after registry key open error
Error message
unable to delete font file after registry key open error
What it means
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.
Source
Thrown at src/cli/font/install_windows.go:70
if err != nil {
return fmt.Errorf("unable to write font file: %s", err.Error())
}
log.Debug("font file written successfully, proceeding with registry entry")
// Add registry entry
reg := registry.CURRENT_USER
regValue := fullPath
log.Debug("opening HKEY_CURRENT_USER for writing (SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts)")
k, _, err := registry.CreateKey(reg, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts`, registry.WRITE)
if err != nil {
log.Error(err)
// If this fails, remove the font file as well.
if nexterr := os.Remove(fullPath); nexterr != nil {
log.Error(nexterr)
return errors.New("unable to delete font file after registry key open error")
}
return errors.New("unable to open HKEY_CURRENT_USER")
}
defer func() {
err := k.Close()
if err != nil {
log.Error(err)
}
}()
fontName := fmt.Sprintf("%v (TrueType)", font.Name)
var alreadyInstalled, newFontType bool
log.Debugf("validating if font %s is already installed", fontName)
// check if we already had this key setView on GitHub (pinned to 0976794618)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// Windows, before install: check HKCU write access
k, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts`, registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
return errors.New("no write access to per-user font registry key; install blocked by policy?")
}
k.Close() Try / catch
if err := font.Install(env, name, report); err != nil {
if strings.Contains(err.Error(), "unable to delete font file") {
log.Printf("registry open failed AND cleanup failed; close apps using the font, delete the extracted file manually, check HKCU policy")
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- unable to open HKEY_CURRENT_USER
- unable to delete font file after registry key set error
- unable to create fonts directory: %s
- unable to write font file: %s
- unable to set registry value: %s
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/cec9db5d17f2309e.
Report an issue: GitHub.