2

How can I get the list of currently installed services in golang under Windows?

I need something like:

List of currently running process in golang

but for services and not process.

Community
  • 1
  • 1
gaurav46
  • 87
  • 1
  • 7
  • 1
    possible duplicate of [How to get all Windows service names starting with a common word?](http://stackoverflow.com/questions/13878921/how-to-get-all-windows-service-names-starting-with-a-common-word) – xmojmr Mar 24 '15 at 17:56
  • 1
    I am looking for implementation in go programming language – gaurav46 Mar 24 '15 at 18:00
  • I'm aware of that requirement, but I guess you can [call shell command](http://stackoverflow.com/a/7786922/2626313) from `go` and the shell command would look like shown in the linked answer, so I (wearing your shoes) would walk this way and considered the problem solved. You can of course wait until someone else shows up providing some better hint – xmojmr Mar 24 '15 at 18:05
  • 1
    Check if the [`syscall`](https://golang.org/pkg/syscall/) or `golang.org/x/sys/windows` packages has anything to help you, otherwise you'll likely need/want to `os.exec` as previously mentioned. – Dave C Mar 24 '15 at 19:53
  • @xmojmr looks like will need to use os.exec - thanks for your help – gaurav46 Mar 24 '15 at 21:21
  • @DaveC looks like will need to use os.exec - thanks for your help – gaurav46 Mar 24 '15 at 21:22

2 Answers2

5

There is no such function in the standard library and there will likely never be.

Consider using one of the functions in os/exec to launch a Windows program that will list the available services and parse its output (e.g. "sc query state=all").

Community
  • 1
  • 1
maerics
  • 133,300
  • 39
  • 246
  • 273
0

This is an old post, but figured I would share this link anyways. https://godoc.org/golang.org/x/sys/windows/svc/mgr

This package provides an API for creating, controlling and listing windows services on both the local and remote systems.

I copied the following text from the above link:

func (m *Mgr) ListServices() ([]string, error)

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.

Shree
  • 18,997
  • 28
  • 86
  • 133
Zack
  • 1
  • 1