JanDeDobbeleer/oh-my-posh · warning

unable to open window process

Error message

unable to open window process

What it means

getWindowFileName resolves which process owns a top-level window by calling Win32 OpenProcess with PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, then GetModuleFileNameA. If OpenProcess fails (access denied or the PID is gone), the function cannot determine the window's executable and returns this error.

Source

Thrown at src/runtime/win32_windows.go:65

	r0, _, e1 := syscall.SyscallN(procGetWindowTextW.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(str)), uintptr(maxCount))
	length = int32(r0)
	if length == 0 {
		if e1 != 0 {
			err = error(e1)
		} else {
			err = syscall.EINVAL
		}
	}
	return
}

func getWindowFileName(handle syscall.Handle) (string, error) {
	var pid int
	_, _, _ = procGetWindowThreadProcessID.Call(uintptr(handle), uintptr(unsafe.Pointer(&pid)))
	const query = windows.PROCESS_QUERY_INFORMATION | windows.PROCESS_VM_READ
	h, err := windows.OpenProcess(query, false, uint32(pid))
	if err != nil {
		return "", errors.New("unable to open window process")
	}
	buf := [1024]byte{}
	length, _, _ := getModuleBaseNameA.Call(uintptr(h), 0, uintptr(unsafe.Pointer(&buf)), 1024)
	filename := string(buf[:length])
	return strings.ToLower(filename), nil
}

func queryWindowTitles(processName, windowTitleRegex string) (string, error) {
	var title string
	// callback for EnumWindows
	cb := syscall.NewCallback(func(handle syscall.Handle, _ uintptr) uintptr {
		fileName, err := getWindowFileName(handle)
		if err != nil {
			// ignore the error and continue enumeration
			return 1
		}
		if processName != fileName {
			// ignore the error and continue enumeration

View on GitHub (pinned to 0976794618)

Solutions

  1. Run your shell (terminal) non-elevated vs elevated consistently, or run the terminal elevated so OpenProcess succeeds for elevated windows.
  2. Ignore the error when possible - the caller (queryWindowTitles) skips windows whose filename cannot be resolved and simply continues enumeration.
  3. Avoid tools that spawn windows from protected system processes when relying on window-title detection; the error is benign for enumeration purposes.
Defensive patterns

Strategy: try-catch

Try / catch

// queryWindowTitles already skips windows whose process cannot be opened;
// treat the error as non-fatal per-window
title, err := getWindowFileName(handle)
if err != nil {
    return true // continue enumeration
}

Prevention

When it happens

Trigger: Calling QueryWindowTitles when a visible window's process cannot be opened: system/elevated processes running as another user or as admin while the shell is not elevated, or a window whose owner process has exited between enumeration and OpenProcess.

Common situations: Prompt window detection (used for transient/transcript logic) while an admin Task Manager, UAC dialog, or other elevated app owns the foreground window; protected OS processes; short-lived windows disappearing mid-enumeration.

Related errors


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