sys: Index | Files

package mgr

import ""

Package mgr can be used to manage Windows service programs. It can be used to install and remove them. It can also start, stop and pause them. The package can query / change current service state and config parameters.


Package Files

config.go mgr.go service.go


const (
    // Service start types.
    StartManual    = windows.SERVICE_DEMAND_START // the service must be started manually
    StartAutomatic = windows.SERVICE_AUTO_START   // the service will start by itself whenever the computer reboots
    StartDisabled  = windows.SERVICE_DISABLED     // the service cannot be started

    // The severity of the error, and action taken,
    // if this service fails to start.
    ErrorCritical = windows.SERVICE_ERROR_CRITICAL
    ErrorIgnore   = windows.SERVICE_ERROR_IGNORE
    ErrorNormal   = windows.SERVICE_ERROR_NORMAL
    ErrorSevere   = windows.SERVICE_ERROR_SEVERE

type Config Uses

type Config struct {
    ServiceType      uint32
    StartType        uint32
    ErrorControl     uint32
    BinaryPathName   string // fully qualified path to the service binary file, can also include arguments for an auto-start service
    LoadOrderGroup   string
    TagId            uint32
    Dependencies     []string
    ServiceStartName string // name of the account under which the service should run
    DisplayName      string
    Password         string
    Description      string

type Mgr Uses

type Mgr struct {
    Handle windows.Handle

Mgr is used to manage Windows service.

func Connect Uses

func Connect() (*Mgr, error)

Connect establishes a connection to the service control manager.

func ConnectRemote Uses

func ConnectRemote(host string) (*Mgr, error)

ConnectRemote establishes a connection to the service control manager on computer named host.

func (*Mgr) CreateService Uses

func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error)

CreateService installs new service name on the system. The service will be executed by running exepath binary. Use config c to specify service parameters. 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 (*Mgr) Disconnect Uses

func (m *Mgr) Disconnect() error

Disconnect closes connection to the service control manager m.

func (*Mgr) ListServices Uses

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.

func (*Mgr) OpenService Uses

func (m *Mgr) OpenService(name string) (*Service, error)

OpenService retrieves access to service name, so it can be interrogated and controlled.

type Service Uses

type Service struct {
    Name   string
    Handle windows.Handle

Service is used to access Windows service.

func (*Service) Close Uses

func (s *Service) Close() error

Close relinquish access to the service s.

func (*Service) Config Uses

func (s *Service) Config() (Config, error)

Config retrieves service s configuration paramteres.

func (*Service) Control Uses

func (s *Service) Control(c svc.Cmd) (svc.Status, error)

Control sends state change request c to the servce s.

func (*Service) Delete Uses

func (s *Service) Delete() error

Delete marks service s for deletion from the service control manager database.

func (*Service) Query Uses

func (s *Service) Query() (svc.Status, error)

Query returns current status of service s.

func (*Service) Start Uses

func (s *Service) Start(args ...string) error

Start starts service s. args will be passed to svc.Handler.Execute.

func (*Service) UpdateConfig Uses

func (s *Service) UpdateConfig(c Config) error

UpdateConfig updates service s configuration parameters.

Package mgr imports 5 packages (graph) and is imported by 15 packages. Updated 2017-11-18 with GOOS=windows. Refresh now. Tools for package owners.