fix(gateway): eliminate blank console window on Windows login - #37037
fix(gateway): eliminate blank console window on Windows login#37037Weidows wants to merge 1 commit into
Conversation
|
Hourly commander review note: this looks like the right direction for suppressing the login console flash ( Suggested shape: tr_command = _quote_schtasks_arg(
subprocess.list2cmdline(["wscript.exe", "//B", "//Nologo", str(vbs_path)])
)I verified in an isolated worktree that |
Replace cmd.exe batch file with VBScript launcher for the Scheduled Task action so the gateway never creates a Console Window Host (conhost.exe) at login. Root cause: schtasks runs .cmd files through cmd.exe, which is a console-subsystem executable. Creating cmd.exe forces Windows to allocate a console (conhost.exe blank terminal window) even though the .cmd wrapper immediately delegates to pythonw.exe. Fix: add _build_vbs_launcher() and _write_vbs_launcher() that generate a .vbs file using wscript.exe (GUI-subsystem, built into every Windows install since Win98). The VBS launcher sets env vars via WshShell.Environment(PROCESS) and calls pythonw.exe with SW_HIDE (0) and async (False). Changes: - Add _build_vbs_launcher() - generates CRLF-terminated VBS content - Add _write_vbs_launcher() - writes <HERMES_HOME>/gateway-service/<name>.vbs - Refactor _install_scheduled_task(task_name, script_path: Path) to _install_scheduled_task(task_name, tr_command: str) - Update install() to write .vbs and use wscript.exe for /TR - Update uninstall() to clean up .vbs alongside .cmd
b6c2ef9 to
db23487
Compare
|
Good catch on the space-in-path edge case. Fixed in db23487 — now uses |
|
Confirmed fixed in practice. Closing as the blank terminal window no longer appears on session start. |
|
User confirmed the blank terminal no longer appears. The fix from this PR was incorporated upstream in #40909 (commit |
Problem
When the Hermes gateway starts via Scheduled Task at Windows login, a blank terminal window flashes on screen. This happens because schtasks runs
.cmdfiles through cmd.exe, which is a console-subsystem executable -- Windows must create a Console Window Host (conhost.exe) before it ever reaches pythonw.exe inside the script.Root cause
cmd.exe is a console-subsystem binary. Windows allocates a new console (conhost.exe) for every console-mode process that doesn't inherit one. The
.cmdwrapper launches pythonw.exe (GUI-subsystem, no console) almost immediately, but the console window is already created and visible before the child even starts.Fix
Replace the cmd.exe -> .cmd -> pythonw.exe chain with wscript.exe -> .vbs -> pythonw.exe for the Scheduled Task
/TRaction.wscript.exe is a GUI-subsystem executable built into every Windows install since Windows 98. It never creates a console, so no blank terminal window ever appears.
Changes
_build_vbs_launcher()-- New function that generates CRLF-terminated VBScript content. The VBS script:_write_vbs_launcher()-- Writes the.vbsfile to<HERMES_HOME>/gateway-service/<task_name>.vbs, alongside the existing .cmd wrapper_install_scheduled_task()-- Signature changed from(task_name, script_path: Path)to(task_name, tr_command: str)so the caller passes the full already-quoted/TRcommand string (e.g. wscript.exe //B //Nologo "C:...\Hermes_Gateway.vbs")install()-- Now writes the .vbs launcher and builds the wscript.exe command for /TR. The .cmd wrapper is still written for manual use and the Startup-folder fallback.uninstall()-- Also removes the .vbs file during cleanup.Testing
Notes
hermes gateway start, debugging).start /min cmd.exe-- that path is less common and users who hit it likely chose it intentionally. A follow-up could apply the same VBS approach there too.