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()); } }