summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/sys/windows/svc/mgr/mgr.go')
-rw-r--r--vendor/golang.org/x/sys/windows/svc/mgr/mgr.go47
1 files changed, 45 insertions, 2 deletions
diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go b/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
index da8ceb6ed..76965b560 100644
--- a/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
+++ b/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
@@ -14,6 +14,7 @@ package mgr
import (
"syscall"
"unicode/utf16"
+ "unsafe"
"golang.org/x/sys/windows"
)
@@ -76,8 +77,10 @@ func toStringBlock(ss []string) *uint16 {
// CreateService installs new service name on the system.
// The service will be executed by running exepath binary.
// Use config c to specify service parameters.
-// If service StartType is set to StartAutomatic,
-// args will be passed to svc.Handle.Execute.
+// Any args will be passed as command-line arguments when
+// the service is started; these arguments are distinct from
+// the arguments passed to Service.Start or via the "Start
+// parameters" field in the service's Properties dialog box.
func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error) {
if c.StartType == 0 {
c.StartType = StartManual
@@ -117,3 +120,43 @@ func (m *Mgr) OpenService(name string) (*Service, error) {
}
return &Service{Name: name, Handle: h}, nil
}
+
+// ListServices enumerates services in the specified
+// service control manager database m.
+// If the caller does not have the SERVICE_QUERY_STATUS
+// access right to a service, the service is silently
+// omitted from the list of services returned.
+func (m *Mgr) ListServices() ([]string, error) {
+ var err error
+ var bytesNeeded, servicesReturned uint32
+ var buf []byte
+ for {
+ var p *byte
+ if len(buf) > 0 {
+ p = &buf[0]
+ }
+ err = windows.EnumServicesStatusEx(m.Handle, windows.SC_ENUM_PROCESS_INFO,
+ windows.SERVICE_WIN32, windows.SERVICE_STATE_ALL,
+ p, uint32(len(buf)), &bytesNeeded, &servicesReturned, nil, nil)
+ if err == nil {
+ break
+ }
+ if err != syscall.ERROR_MORE_DATA {
+ return nil, err
+ }
+ if bytesNeeded <= uint32(len(buf)) {
+ return nil, err
+ }
+ buf = make([]byte, bytesNeeded)
+ }
+ if servicesReturned == 0 {
+ return nil, nil
+ }
+ services := (*[1 << 20]windows.ENUM_SERVICE_STATUS_PROCESS)(unsafe.Pointer(&buf[0]))[:servicesReturned]
+ var names []string
+ for _, s := range services {
+ name := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(s.ServiceName))[:])
+ names = append(names, name)
+ }
+ return names, nil
+}