Files

40 lines
813 B
Go
Raw Permalink Normal View History

//go:build windows
package instance
import (
"os"
"os/exec"
2026-09-01 23:25:06 +03:00
"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
2026-09-01 23:25:06 +03:00
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)
}