diff --git a/core/remote_desktop.py b/core/remote_desktop.py index 6ddad51..6db42ca 100644 --- a/core/remote_desktop.py +++ b/core/remote_desktop.py @@ -397,7 +397,7 @@ class EmbeddedRDP: ) is_dialog = class_name == "#32770" - if pid_match or (title_match and (is_mstsc_class or is_dialog)): + if (pid_match or title_match) and (is_mstsc_class or is_dialog): found_windows.append((hwnd, class_name, title, win_pid)) return True @@ -524,12 +524,13 @@ class EmbeddedRDP: try: # Remove decorations, make child - style = user32.GetWindowLongW(hwnd, GWL_STYLE) + # Use unsigned 32-bit mask to avoid ctypes overflow + style = user32.GetWindowLongW(hwnd, GWL_STYLE) & 0xFFFFFFFF style = (style | WS_CHILD | WS_VISIBLE) & ~( WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX - ) - user32.SetWindowLongW(hwnd, GWL_STYLE, style) + ) & 0xFFFFFFFF + user32.SetWindowLongW(hwnd, GWL_STYLE, ctypes.c_long(style).value) # Reparent user32.SetParent(hwnd, parent_hwnd) @@ -657,31 +658,18 @@ class EmbeddedRDP: """Check if mstsc process is still running (parent or children).""" if not self._process: return False - # Parent still alive - if self._process.poll() is None: - return True - # Parent exited but child mstsc may be alive - if _HAS_PSUTIL: - try: - pids = _find_mstsc_pids(self._process.pid) - for pid in pids: - if pid == self._process.pid: - continue - try: - p = psutil.Process(pid) - if p.is_running(): - return True - except (psutil.NoSuchProcess, psutil.AccessDenied): - pass - except Exception: - pass - # Check if embedded window still exists + # Primary check: is the embedded window still valid? + # This is the most reliable indicator — works regardless of PID tracking if self._mstsc_hwnd: try: import ctypes - return bool(ctypes.windll.user32.IsWindow(self._mstsc_hwnd)) + if ctypes.windll.user32.IsWindow(self._mstsc_hwnd): + return True except Exception: pass + # Fallback: parent process still running + if self._process.poll() is None: + return True return False @property diff --git a/releases/ServerManager-v1.8.31-win-x64.exe b/releases/ServerManager-v1.8.31-win-x64.exe new file mode 100644 index 0000000..804843e Binary files /dev/null and b/releases/ServerManager-v1.8.31-win-x64.exe differ diff --git a/version.py b/version.py index dc8af66..66dc002 100644 --- a/version.py +++ b/version.py @@ -1,6 +1,6 @@ """Version info for ServerManager.""" -__version__ = "1.8.29" +__version__ = "1.8.31" __app_name__ = "ServerManager" __author__ = "aibot777" __description__ = "Desktop GUI for managing remote servers"