@@ -43,6 +43,7 @@ type Config struct {
43
43
Password string
44
44
Description string
45
45
SidType uint32 // one of SERVICE_SID_TYPE, the type of sid to use for the service
46
+ DelayedAutoStart bool // the service is started after other auto-start services are started plus a short delay
46
47
}
47
48
48
49
func toString (p * uint16 ) string {
@@ -95,6 +96,16 @@ func (s *Service) Config() (Config, error) {
95
96
}
96
97
p2 := (* windows .SERVICE_DESCRIPTION )(unsafe .Pointer (& b [0 ]))
97
98
99
+ b , err = s .queryServiceConfig2 (windows .SERVICE_CONFIG_DELAYED_AUTO_START_INFO )
100
+ if err != nil {
101
+ return Config {}, err
102
+ }
103
+ p3 := (* windows .SERVICE_DELAYED_AUTO_START_INFO )(unsafe .Pointer (& b [0 ]))
104
+ delayedStart := false
105
+ if p3 .IsDelayedAutoStartUp != 0 {
106
+ delayedStart = true
107
+ }
108
+
98
109
return Config {
99
110
ServiceType : p .ServiceType ,
100
111
StartType : p .StartType ,
@@ -106,6 +117,7 @@ func (s *Service) Config() (Config, error) {
106
117
ServiceStartName : toString (p .ServiceStartName ),
107
118
DisplayName : toString (p .DisplayName ),
108
119
Description : toString (p2 .Description ),
120
+ DelayedAutoStart : delayedStart ,
109
121
}, nil
110
122
}
111
123
@@ -119,6 +131,15 @@ func updateSidType(handle windows.Handle, sidType uint32) error {
119
131
return windows .ChangeServiceConfig2 (handle , windows .SERVICE_CONFIG_SERVICE_SID_INFO , (* byte )(unsafe .Pointer (& sidType )))
120
132
}
121
133
134
+ func updateStartUp (handle windows.Handle , isDelayed bool ) error {
135
+ var d windows.SERVICE_DELAYED_AUTO_START_INFO
136
+ if isDelayed {
137
+ d .IsDelayedAutoStartUp = 1
138
+ }
139
+ return windows .ChangeServiceConfig2 (handle ,
140
+ windows .SERVICE_CONFIG_DELAYED_AUTO_START_INFO , (* byte )(unsafe .Pointer (& d )))
141
+ }
142
+
122
143
// UpdateConfig updates service s configuration parameters.
123
144
func (s * Service ) UpdateConfig (c Config ) error {
124
145
err := windows .ChangeServiceConfig (s .Handle , c .ServiceType , c .StartType ,
@@ -132,6 +153,12 @@ func (s *Service) UpdateConfig(c Config) error {
132
153
if err != nil {
133
154
return err
134
155
}
156
+
157
+ err = updateStartUp (s .Handle , c .DelayedAutoStart )
158
+ if err != nil {
159
+ return err
160
+ }
161
+
135
162
return updateDescription (s .Handle , c .Description )
136
163
}
137
164
0 commit comments