From f058f3f578036e4950d1820227a91def7b09e718 Mon Sep 17 00:00:00 2001 From: helloJetBase-tech Date: Thu, 13 Nov 2025 22:10:02 +0200 Subject: [PATCH] Update WindowUtils.java --- .../src/com/sun/jna/platform/WindowUtils.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/WindowUtils.java b/contrib/platform/src/com/sun/jna/platform/WindowUtils.java index 78ea1fa2d..4c7f44904 100644 --- a/contrib/platform/src/com/sun/jna/platform/WindowUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/WindowUtils.java @@ -1298,22 +1298,24 @@ public String getProcessFilePath(final HWND hwnd) { pid.getValue()); if (process == null) { - if(Kernel32.INSTANCE.GetLastError() != WinNT.ERROR_ACCESS_DENIED) { - throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); - } else { - process = Kernel32.INSTANCE.OpenProcess( - WinNT.PROCESS_QUERY_LIMITED_INFORMATION, - false, - pid.getValue()); - - if (process == null) { - if (Kernel32.INSTANCE.GetLastError() != WinNT.ERROR_ACCESS_DENIED) { - throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); - } else { - // Ignore windows, that can't be accessed - return ""; + switch (Kernel32.INSTANCE.GetLastError()) { + case WinNT.ERROR_ACCESS_DENIED: + case WinError.ERROR_INVALID_PARAMETER: + process = Kernel32.INSTANCE.OpenProcess( + WinNT.PROCESS_QUERY_LIMITED_INFORMATION, + false, + pid.getValue()); + if (process != null) { + break; } - } + switch (Kernel32.INSTANCE.GetLastError()) { + case WinNT.ERROR_ACCESS_DENIED: + case WinError.ERROR_INVALID_PARAMETER: + return ""; + } + /* if above didn't already break or return, fall through to default */ + default: + throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } }