diff --git a/windows/svc/mgr/config.go b/windows/svc/mgr/config.go index d804e31f..61447a58 100644 --- a/windows/svc/mgr/config.go +++ b/windows/svc/mgr/config.go @@ -42,6 +42,7 @@ type Config struct { DisplayName string Password string Description string + SidType uint32 // one of SERVICE_SID_TYPE, the type of sid to use for the service } func toString(p *uint16) string { @@ -114,6 +115,10 @@ func updateDescription(handle windows.Handle, desc string) error { windows.SERVICE_CONFIG_DESCRIPTION, (*byte)(unsafe.Pointer(&d))) } +func updateSidType(handle windows.Handle, sidType uint32) error { + return windows.ChangeServiceConfig2(handle, windows.SERVICE_CONFIG_SERVICE_SID_INFO, (*byte)(unsafe.Pointer(&sidType))) +} + // UpdateConfig updates service s configuration parameters. func (s *Service) UpdateConfig(c Config) error { err := windows.ChangeServiceConfig(s.Handle, c.ServiceType, c.StartType, @@ -123,6 +128,10 @@ func (s *Service) UpdateConfig(c Config) error { if err != nil { return err } + err = updateSidType(s.Handle, c.SidType) + if err != nil { + return err + } return updateDescription(s.Handle, c.Description) } diff --git a/windows/svc/mgr/mgr.go b/windows/svc/mgr/mgr.go index 76965b56..24638d72 100644 --- a/windows/svc/mgr/mgr.go +++ b/windows/svc/mgr/mgr.go @@ -102,9 +102,19 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se 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.CloseHandle(h) + return nil, err + } + } if c.Description != "" { err = updateDescription(h, c.Description) if err != nil { + windows.DeleteService(h) + windows.CloseHandle(h) return nil, err } }