diff --git a/internal/externalcmd/cmd_win.go b/internal/externalcmd/cmd_win.go index e424d49d806..5e4863be15d 100644 --- a/internal/externalcmd/cmd_win.go +++ b/internal/externalcmd/cmd_win.go @@ -44,13 +44,21 @@ func closeProcessGroup(h windows.Handle) error { } func addProcessToGroup(h windows.Handle, p *os.Process) error { - type process struct { - Pid int - Handle uintptr + + // Combine the required access rights + access := uint32(windows.PROCESS_SET_QUOTA | windows.PROCESS_TERMINATE) + + processHandle, err := windows.OpenProcess(access, false, uint32(p.Pid)) + if err != nil { + return fmt.Errorf("failed to open process: %v", err) } + defer windows.CloseHandle(processHandle) - return windows.AssignProcessToJobObject(h, - windows.Handle((*process)(unsafe.Pointer(p)).Handle)) + err = windows.AssignProcessToJobObject(h, processHandle) + if err != nil { + return fmt.Errorf("failed to assign process to job object: %v", err) + } + return nil } func (e *Cmd) runOSSpecific(env []string) error {