{"record":{"id":"3fa5108c6118a75a","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-open-window-process","errorCode":null,"errorMessage":"unable to open window process","messagePattern":"unable to open window process","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/runtime/win32_windows.go","lineNumber":65,"sourceCode":"\tr0, _, e1 := syscall.SyscallN(procGetWindowTextW.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(str)), uintptr(maxCount))\n\tlength = int32(r0)\n\tif length == 0 {\n\t\tif e1 != 0 {\n\t\t\terr = error(e1)\n\t\t} else {\n\t\t\terr = syscall.EINVAL\n\t\t}\n\t}\n\treturn\n}\n\nfunc getWindowFileName(handle syscall.Handle) (string, error) {\n\tvar pid int\n\t_, _, _ = procGetWindowThreadProcessID.Call(uintptr(handle), uintptr(unsafe.Pointer(&pid)))\n\tconst query = windows.PROCESS_QUERY_INFORMATION | windows.PROCESS_VM_READ\n\th, err := windows.OpenProcess(query, false, uint32(pid))\n\tif err != nil {\n\t\treturn \"\", errors.New(\"unable to open window process\")\n\t}\n\tbuf := [1024]byte{}\n\tlength, _, _ := getModuleBaseNameA.Call(uintptr(h), 0, uintptr(unsafe.Pointer(&buf)), 1024)\n\tfilename := string(buf[:length])\n\treturn strings.ToLower(filename), nil\n}\n\nfunc queryWindowTitles(processName, windowTitleRegex string) (string, error) {\n\tvar title string\n\t// callback for EnumWindows\n\tcb := syscall.NewCallback(func(handle syscall.Handle, _ uintptr) uintptr {\n\t\tfileName, err := getWindowFileName(handle)\n\t\tif err != nil {\n\t\t\t// ignore the error and continue enumeration\n\t\t\treturn 1\n\t\t}\n\t\tif processName != fileName {\n\t\t\t// ignore the error and continue enumeration","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/win32_windows.go#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run your shell (terminal) non-elevated vs elevated consistently, or run the terminal elevated so OpenProcess succeeds for elevated windows.","Ignore the error when possible - the caller (queryWindowTitles) skips windows whose filename cannot be resolved and simply continues enumeration.","Avoid tools that spawn windows from protected system processes when relying on window-title detection; the error is benign for enumeration purposes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// queryWindowTitles already skips windows whose process cannot be opened;\n// treat the error as non-fatal per-window\ntitle, err := getWindowFileName(handle)\nif err != nil {\n    return true // continue enumeration\n}","preventionTips":["Run the terminal at the same or higher integrity level than the apps whose windows you inspect","Accept that elevated/protected processes will always fail OpenProcess","Avoid depending on window titles of short-lived or system-owned windows"],"tags":["windows","win32","permissions"],"backgroundTag":"process-access-denied","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}