func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error) {
	if c.StartType == 0 {
		c.StartType = StartManual
	}
	if c.ErrorControl == 0 {
		c.ErrorControl = ErrorNormal
	}
	if c.ServiceType == 0 {
		c.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
	}
	s := syscall.EscapeArg(exepath)
	for _, v := range args {
		s += " " + syscall.EscapeArg(v)
	}
	h, err := windows.CreateService(m.Handle, toPtr(name), toPtr(c.DisplayName),
		windows.SERVICE_ALL_ACCESS, c.ServiceType,
		c.StartType, c.ErrorControl, toPtr(s), toPtr(c.LoadOrderGroup),
		nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), toPtr(c.Password))
	if err != nil {
		return nil, err
	}
	if c.SidType != windows.SERVICE_SID_TYPE_NONE {
		err = updateSidType(h, c.SidType)
		if err != nil {
			windows.DeleteService(h)
			windows.CloseServiceHandle(h)
			return nil, err
		}
	}
	if c.Description != "" {
		err = updateDescription(h, c.Description)
		if err != nil {
			windows.DeleteService(h)
			windows.CloseServiceHandle(h)
			return nil, err
		}
	}
	if c.DelayedAutoStart {
		err = updateStartUp(h, c.DelayedAutoStart)
		if err != nil {
			windows.DeleteService(h)
			windows.CloseServiceHandle(h)
			return nil, err
		}
	}
	return &Service{Name: name, Handle: h}, nil
}
// 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.
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.
// 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 (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error) {
	if c.StartType == 0 {
		c.StartType = StartManual
	}
	if c.ErrorControl == 0 {
		c.ErrorControl = ErrorNormal
	}
	if c.ServiceType == 0 {
		c.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
	}
	s := syscall.EscapeArg(exepath)
	for _, v := range args {
		s += " " + syscall.EscapeArg(v)
	}
	h, err := windows.CreateService(m.Handle, toPtr(name), toPtr(c.DisplayName),
		windows.SERVICE_ALL_ACCESS, c.ServiceType,
		c.StartType, c.ErrorControl, toPtr(s), toPtr(c.LoadOrderGroup),
		nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), toPtr(c.Password))
	if err != nil {
		return nil, err
	}
	if c.SidType != windows.SERVICE_SID_TYPE_NONE {
		err = updateSidType(h, c.SidType)
		if err != nil {
			windows.DeleteService(h)
			windows.CloseServiceHandle(h)
			return nil, err
		}
	}
	if c.Description != "" {
		err = updateDescription(h, c.Description)
		if err != nil {
			windows.DeleteService(h)
			windows.CloseServiceHandle(h)
			return nil, err
		}
	}
	if c.DelayedAutoStart {
		err = updateStartUp(h, c.DelayedAutoStart)
		if err != nil {
			windows.DeleteService(h)
			windows.CloseServiceHandle(h)
			return nil, err
		}
	}
	return &Service{Name: name, Handle: h}, nil
}
func ( m * Mgr ) CreateService ( name , exepath string , c Config , args ... string ) ( * Service , error ) { if c . StartType == 0 { c . StartType = StartManual } if c . ErrorControl == 0 { c . ErrorControl = ErrorNormal } if c . ServiceType == 0 { c . ServiceType = windows . SERVICE_WIN32_OWN_PROCESS } s := syscall . EscapeArg ( exepath ) for _ , v := range args { s += " " + syscall . EscapeArg ( v ) } h , err := windows . CreateService ( m . Handle , toPtr ( name ) , toPtr ( c . DisplayName ) , windows . SERVICE_ALL_ACCESS , c . ServiceType , c . StartType , c . ErrorControl , toPtr ( s ) , toPtr ( c . LoadOrderGroup ) , nil , toStringBlock ( c . Dependencies ) , toPtr ( c . ServiceStartName ) , toPtr ( c . Password ) ) if err != nil { return nil , err } if c . SidType != windows . SERVICE_SID_TYPE_NONE { err = updateSidType ( h , c . SidType ) if err != nil { windows . DeleteService ( h ) windows . CloseServiceHandle ( h ) return nil , err } } if c . Description != " " { err = updateDescription ( h , c . Description ) if err != nil { windows . DeleteService ( h ) windows . CloseServiceHandle ( h ) return nil , err } } if c . DelayedAutoStart { err = updateStartUp ( h , c . DelayedAutoStart ) if err != nil { windows . DeleteService ( h ) windows . CloseServiceHandle ( h ) return nil , err } } return & Service { Name : name , Handle : h } , nil }
CreateService installs new service name on the system.
CreateService installs new service name on the system .