Add a --vnc option to run-windows11.py

Serves the guest screen over VNC instead of opening a display window.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
guofangandClaude Sonnet 5.5 committed 2026-10-28 14:50:14 +08:00
1 parent 72af276309
commit d2fe47c911
1 file changed
+16 -3
+16 -3
View File
@@ -84,11 +84,12 @@ download_only = False
seed_only = False
extra_args = []
arch_option = None
vnc_listen = None
def usage(stream=sys.stdout):
stream.write(f"""\
Usage: {Path(sys.argv[0]).name} [--daemon] [--download-only] [--seed-only] [--install-from-iso | --install-from-img]
Usage: {Path(sys.argv[0]).name} [--daemon] [--download-only] [--seed-only] [--vnc[=ADDR:N]] [--install-from-iso | --install-from-img]
[--arch ARCH] [--state-dir DIR] [--rdp-port PORT] [--ssh-port PORT] [-- QEMU_ARGUMENT ...]
If the system disk (DIR/disk.qcow2, see --state-dir) is missing, create it from
@@ -115,6 +116,9 @@ Options:
is the ISO path ending in .img instead of .iso.
It is attached as an NVMe disk, much faster than the
emulated USB CD-ROM, and is never modified
--vnc[=ADDR:N] Serve the screen over VNC instead of opening a window, on
ADDR (default: 127.0.0.1) at TCP port 5900+N (default N: 0).
Overrides WIN11_VM_DISPLAY
--arch ARCH Guest architecture: arm64 or amd64 (default: the host's;
overrides VM_IMAGE_ARCH). A guest that differs from the
host runs under slow TCG emulation
@@ -155,6 +159,10 @@ while args:
download_only = True
elif arg == "--seed-only":
seed_only = True
elif arg == "--vnc" or arg.startswith("--vnc="):
vnc_listen = arg.partition("=")[2] or "127.0.0.1:0"
if ":" not in vnc_listen:
vnc_listen += ":0"
elif arg == "--install-from-iso":
install_from_iso = True
elif arg == "--install-from-img":
@@ -391,8 +399,13 @@ if installing:
# cocoa shows the guest at its own resolution. Append ,zoom-to-fit=on (via
# WIN11_VM_DISPLAY) to stretch a low-resolution screen to the window.
display_backend = env("WIN11_VM_DISPLAY") or (
"cocoa" if platform.system() == "Darwin" else "gtk")
display_backend = (f"vnc={vnc_listen}" if vnc_listen else env("WIN11_VM_DISPLAY") or (
"cocoa" if platform.system() == "Darwin" else "gtk"))
if vnc_listen:
vnc_host, _, vnc_display = vnc_listen.rpartition(":")
if not vnc_display.isdigit():
die(f"--vnc display number must be an integer: {vnc_listen}", 2)
print(f"VNC: connect to {vnc_host or '127.0.0.1'}:{5900 + int(vnc_display)}")
# Most of the VM definition lives in the QEMU config template; fill in the
# file paths and hand the rendered file to QEMU with -readconfig.