JanDeDobbeleer/oh-my-posh · error

unable to open HKEY_CURRENT_USER

Error message

unable to open HKEY_CURRENT_USER

What it means

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.

Source

Thrown at src/cli/font/install_windows.go:73

	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 set
	oldFullPath, _, err := k.GetStringValue(fontName)
	if err == nil {
		log.Debugf("font %s is already installed with path %s", fontName, oldFullPath)

View on GitHub (pinned to 0976794618)

Solutions

  1. Verify you can write to HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts (e.g. with regedit or `reg add`).
  2. Ask IT to lift group-policy restrictions on HKCU\SOFTWARE for font registration.
  3. Run the install in a normal interactive user session rather than a service or restricted context.
  4. Install the font system-wide for all users instead (requires admin) if per-user registration is blocked.
Defensive patterns

Strategy: try-catch

Validate before calling

k, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts`, registry.SET_VALUE)
if err != nil {
    return errors.New("HKCU font registry key is not writable in this environment")
}
k.Close()

Try / catch

if err := font.Install(env, name, report); err != nil {
    if strings.Contains(err.Error(), "unable to open HKEY_CURRENT_USER") {
        // per-user install blocked; fall back to admin/system-wide font install
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Locked-down corporate Windows images restricting HKCU\SOFTWARE writes; running inside sandboxes/containers without a real user hive; roaming profile or hive load failures.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/2160fd83479b7fd8. Report an issue: GitHub.