Skip to content

Commit

Permalink
windows: add QueryServiceStatusEx function
Browse files Browse the repository at this point in the history
Fixes golang/go#25485

Change-Id: Ic00df1f86591c00fa88cddcb03c7ced0c6bdb0c1
Reviewed-on: https://go-review.googlesource.com/114215
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
  • Loading branch information
pytimer authored and alexbrainman committed May 24, 2018
1 parent 77b0e43 commit 56ad15c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions windows/service.go
Expand Up @@ -162,3 +162,4 @@ type ENUM_SERVICE_STATUS_PROCESS struct {
//sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W
//sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W
//sys EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) = advapi32.EnumServicesStatusExW
//sys QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceStatusEx
13 changes: 13 additions & 0 deletions windows/zsyscall_windows.go
Expand Up @@ -65,6 +65,7 @@ var (
procChangeServiceConfig2W = modadvapi32.NewProc("ChangeServiceConfig2W")
procQueryServiceConfig2W = modadvapi32.NewProc("QueryServiceConfig2W")
procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW")
procQueryServiceStatusEx = modadvapi32.NewProc("QueryServiceStatusEx")
procGetLastError = modkernel32.NewProc("GetLastError")
procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW")
Expand Down Expand Up @@ -472,6 +473,18 @@ func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serv
return
}

func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}

func GetLastError() (lasterr error) {
r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
if r0 != 0 {
Expand Down

0 comments on commit 56ad15c

Please sign in to comment.