package deploy import ( "fmt" "os" "os/exec" "path/filepath" "golang.org/x/sys/windows/registry" ) func ConfigureAutoStart(exePath string, enabled bool) error { if !enabled { return removeAutoStart() } k, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.SET_VALUE) if err != nil { return err } defer k.Close() return k.SetStringValue("CryptoMinerAgent", exePath) } func removeAutoStart() error { k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.SET_VALUE) if err != nil { return nil } defer k.Close() _ = k.DeleteValue("CryptoMinerAgent") return nil } func SetProcessPriority(priority string) error { // Best-effort on Windows using PowerShell for the current process. class := "BelowNormal" switch priority { case "idle": class = "Idle" case "below_normal": class = "BelowNormal" case "normal": class = "Normal" case "above_normal": class = "AboveNormal" case "high": class = "High" } pid := os.Getpid() cmd := exec.Command("powershell", "-NoProfile", "-Command", fmt.Sprintf("(Get-Process -Id %d).PriorityClass = '%s'", pid, class)) return cmd.Run() } func CurrentExecutable() (string, error) { return filepath.Abs(os.Args[0]) }