Skip to content

Commit 2bb5cc2

Browse files
committed
Merge remote-tracking branch 'origin/pr/88' into HEAD
2 parents 62ab636 + ef1bc54 commit 2bb5cc2

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

internal/runtime/native_windows.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,25 @@ func (r *NativeRuntime) launchViaSchtasks(name string, command []string, logPath
4444
return 0, fmt.Errorf("write launcher script: %w", err)
4545
}
4646

47+
// Wrap the bat in a hidden-window VBS launcher so no cmd.exe console flashes
48+
// on the interactive desktop. The bat's cmd is the engine process's parent
49+
// and would otherwise stay visible for the whole life of the deployment.
50+
// WScript.Shell.Run(cmd, 0, False) => window style 0 = hidden, no wait.
51+
vbsPath := filepath.Join(r.logDir, name+"-launcher.vbs")
52+
vbs := fmt.Sprintf("CreateObject(\"WScript.Shell\").Run \"\"\"%s\"\"\", 0, False\r\n", batPath)
53+
if err := os.WriteFile(vbsPath, []byte(vbs), 0o644); err != nil {
54+
os.Remove(batPath)
55+
return 0, fmt.Errorf("write launcher vbs: %w", err)
56+
}
57+
4758
// Create a one-time scheduled task with /it (interactive token).
4859
taskName := "AIMA-deploy-" + name
60+
trCmd := fmt.Sprintf("wscript.exe //B //Nologo \"%s\"", vbsPath)
4961
createOut, err := exec.Command("schtasks", "/create", "/tn", taskName,
50-
"/tr", batPath, "/sc", "once", "/st", "00:00", "/it", "/f").CombinedOutput()
62+
"/tr", trCmd, "/sc", "once", "/st", "00:00", "/it", "/f").CombinedOutput()
5163
if err != nil {
5264
os.Remove(batPath)
65+
os.Remove(vbsPath)
5366
return 0, fmt.Errorf("schtasks create: %w (output: %s)", err, string(createOut))
5467
}
5568

@@ -58,6 +71,7 @@ func (r *NativeRuntime) launchViaSchtasks(name string, command []string, logPath
5871
if err != nil {
5972
exec.Command("schtasks", "/delete", "/tn", taskName, "/f").Run()
6073
os.Remove(batPath)
74+
os.Remove(vbsPath)
6175
return 0, fmt.Errorf("schtasks run: %w (output: %s)", err, string(runOut))
6276
}
6377

@@ -92,6 +106,7 @@ func (r *NativeRuntime) launchViaSchtasks(name string, command []string, logPath
92106
// Clean up scheduled task definition (engine process continues running).
93107
exec.Command("schtasks", "/delete", "/tn", taskName, "/f").Run()
94108
os.Remove(batPath)
109+
os.Remove(vbsPath)
95110

96111
if pid == 0 {
97112
return 0, fmt.Errorf("discover PID after schtasks launch: binary=%s port=%d", binaryName, port)

0 commit comments

Comments
 (0)