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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index b98b945..c698da3 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -261,6 +261,7 @@
//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 96377a8..dcd10e0 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -199,6 +199,7 @@
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 @@
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 {