You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10虚拟机RDP环境下PyAutoGUI断开远程报错的解决办法求助

Fixing "OSError: screen grab failed" When Running PyAutoGUI on Windows 10 VM After RDP Disconnect

I’ve dealt with this exact frustration before—Windows immediately drops the session’s display output once you disconnect RDP, which breaks PyAutoGUI’s screen-grabbing functionality. Here are three reliable temporary solutions that should get your script running uninterrupted:

Solution 1: Use Group Policy to Force Persistent Session Display

This configures your VM to keep its active display even after you disconnect RDP:

  • Open the Local Group Policy Editor on your VM by running gpedit.msc from the Start menu or Run dialog.
  • Navigate to Computer Configuration > Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Session Time Limits.
  • Locate Set time limit for disconnected sessions and set it to Disabled.
  • Repeat this for Set time limit for active but idle Remote Desktop Services sessions and End disconnected sessions.
  • Apply changes immediately by running gpupdate /force in Command Prompt, then restart your VM if required.

Solution 2: Connect via the Admin/Console Session

Windows has a dedicated console session that doesn’t disable display on disconnect:

  • On your local machine, open Command Prompt and run mstsc /admin (older Windows versions use mstsc /console instead).
  • Use this RDP window to connect to your VM. When you close the RDP window, the VM’s session will stay active with its display intact, letting PyAutoGUI run without errors.

Solution 3: Add a Virtual Display Adapter

If you don’t have access to group policy settings, a virtual display tricks Windows into maintaining an active screen:

  1. First, install your VM’s guest tools (like VMware Tools or VirtualBox Guest Additions)—this enables virtual display support.
  2. For VirtualBox: Go to VM Settings > Display, check Enable VRDP, set the number of monitors to 2, then start the VM. Inside the VM, extend your desktop to the new virtual display.
  3. For VMware: Go to VM Settings > Display, increase the number of monitors, enable Accelerate 3D graphics if needed, then configure the virtual display in Windows’ display settings.
    Once set up, disconnecting RDP won’t disable this virtual display, so PyAutoGUI can continue grabbing screen content from it.

Why Your Previous Attempts Didn’t Work

  • The Terminals tool’s display-persist settings are often hidden or deprecated in newer versions, which is why you couldn’t locate them.
  • The X11 display code you tried is designed for Linux environments—PyAutoGUI on Windows relies on Win32 APIs instead, so that snippet won’t function here.

内容的提问来源于stack exchange,提问作者Lore

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:10:42