From 95d888ea4446da92be3f1cf9a2bdd0ce08ebfec3 Mon Sep 17 00:00:00 2001 From: Takuto Ikuta Date: Thu, 30 May 2019 18:10:03 +0900 Subject: [PATCH] windows: add GenerateConsoleCtrlEvent function ref: https://docs.microsoft.com/en-us/windows/console/generateconsolectrlevent Change-Id: Id5db1d4c7d73a142405061353f578b1be93dbbb9 Reviewed-on: https://go-review.googlesource.com/c/sys/+/179538 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- windows/syscall_windows.go | 1 + windows/zsyscall_windows.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index b98b9454..c698da33 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -261,6 +261,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys SetPriorityClass(process Handle, priorityClass uint32) (err error) = kernel32.SetPriorityClass //sys GetPriorityClass(process Handle) (ret uint32, err error) = kernel32.GetPriorityClass //sys SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobObjectInformation uintptr, JobObjectInformationLength uint32) (ret int, err error) +//sys GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error) // Volume Management Functions //sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 96377a8e..dcd10e06 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -199,6 +199,7 @@ var ( procSetPriorityClass = modkernel32.NewProc("SetPriorityClass") procGetPriorityClass = modkernel32.NewProc("GetPriorityClass") procSetInformationJobObject = modkernel32.NewProc("SetInformationJobObject") + procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent") procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW") procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW") procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW") @@ -2146,6 +2147,18 @@ func SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobOb return } +func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error) { + r1, _, e1 := syscall.Syscall(procGenerateConsoleCtrlEvent.Addr(), 2, uintptr(ctrlEvent), uintptr(processGroupID), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) { r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath))) if r1 == 0 {