Skip to content

Commit f4b1b0c

Browse files
fix: set CREATE_NO_WINDOW on tzutil exec to prevent console flash
When the calling process has no console (e.g. spawned with DETACHED_PROCESS), tzutil.exe allocates a fresh conhost on first stdio access, producing a visible window flash. Setting CREATE_NO_WINDOW gives tzutil a non-visible console, preventing the flash while still allowing cmd.Output() to capture the result via pipes. golang.org/x/sys is already in the module graph via golang.org/x/sys/windows/registry, so no new dependency is added. Co-authored-by: Copilot <[email protected]>
1 parent 9af4692 commit f4b1b0c

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎tzlocal/tz_windows_tzutil.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ package tzlocal
66
import (
77
"os/exec"
88
"strings"
9+
"syscall"
10+
11+
"golang.org/x/sys/windows"
912
)
1013

1114
// localTZfromTzutil executes command `tzutil /g` to get the name of the time zone Windows is configured to use.
1215
func localTZfromTzutil() (string, error) {
1316
cmd := exec.Command("tzutil", "/g")
17+
cmd.SysProcAttr = &syscall.SysProcAttr{
18+
CreationFlags: windows.CREATE_NO_WINDOW,
19+
}
1420
data, err := cmd.Output()
1521
if err != nil {
1622
return "", err

‎tzlocal/tz_windows_tzutil_go1.18.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ package tzlocal
55

66
import (
77
"strings"
8+
"syscall"
89

910
"golang.org/x/sys/execabs"
11+
"golang.org/x/sys/windows"
1012
)
1113

1214
// localTZfromTzutil executes command `tzutil /g` to get the name of the time zone Windows is configured to use.
1315
func localTZfromTzutil() (string, error) {
1416
cmd := execabs.Command("tzutil", "/g")
17+
cmd.SysProcAttr = &syscall.SysProcAttr{
18+
CreationFlags: windows.CREATE_NO_WINDOW,
19+
}
1520
data, err := cmd.Output()
1621
if err != nil {
1722
return "", err

0 commit comments

Comments
 (0)