blob: b269850d0666eaa46943dde061d76a7b7fe7130d [file] [log] [blame]
khenaidoo59ce9dd2019-11-11 13:05:32 -05001// Copyright 2012 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build windows
6
7package windows
8
9const (
10 SC_MANAGER_CONNECT = 1
11 SC_MANAGER_CREATE_SERVICE = 2
12 SC_MANAGER_ENUMERATE_SERVICE = 4
13 SC_MANAGER_LOCK = 8
14 SC_MANAGER_QUERY_LOCK_STATUS = 16
15 SC_MANAGER_MODIFY_BOOT_CONFIG = 32
16 SC_MANAGER_ALL_ACCESS = 0xf003f
17)
18
19//sys OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenSCManagerW
20
21const (
22 SERVICE_KERNEL_DRIVER = 1
23 SERVICE_FILE_SYSTEM_DRIVER = 2
24 SERVICE_ADAPTER = 4
25 SERVICE_RECOGNIZER_DRIVER = 8
26 SERVICE_WIN32_OWN_PROCESS = 16
27 SERVICE_WIN32_SHARE_PROCESS = 32
28 SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS
29 SERVICE_INTERACTIVE_PROCESS = 256
30 SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_RECOGNIZER_DRIVER
31 SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS
32
33 SERVICE_BOOT_START = 0
34 SERVICE_SYSTEM_START = 1
35 SERVICE_AUTO_START = 2
36 SERVICE_DEMAND_START = 3
37 SERVICE_DISABLED = 4
38
39 SERVICE_ERROR_IGNORE = 0
40 SERVICE_ERROR_NORMAL = 1
41 SERVICE_ERROR_SEVERE = 2
42 SERVICE_ERROR_CRITICAL = 3
43
44 SC_STATUS_PROCESS_INFO = 0
45
46 SC_ACTION_NONE = 0
47 SC_ACTION_RESTART = 1
48 SC_ACTION_REBOOT = 2
49 SC_ACTION_RUN_COMMAND = 3
50
51 SERVICE_STOPPED = 1
52 SERVICE_START_PENDING = 2
53 SERVICE_STOP_PENDING = 3
54 SERVICE_RUNNING = 4
55 SERVICE_CONTINUE_PENDING = 5
56 SERVICE_PAUSE_PENDING = 6
57 SERVICE_PAUSED = 7
58 SERVICE_NO_CHANGE = 0xffffffff
59
60 SERVICE_ACCEPT_STOP = 1
61 SERVICE_ACCEPT_PAUSE_CONTINUE = 2
62 SERVICE_ACCEPT_SHUTDOWN = 4
63 SERVICE_ACCEPT_PARAMCHANGE = 8
64 SERVICE_ACCEPT_NETBINDCHANGE = 16
65 SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 32
66 SERVICE_ACCEPT_POWEREVENT = 64
67 SERVICE_ACCEPT_SESSIONCHANGE = 128
khenaidoo26721882021-08-11 17:42:52 -040068 SERVICE_ACCEPT_PRESHUTDOWN = 256
khenaidoo59ce9dd2019-11-11 13:05:32 -050069
70 SERVICE_CONTROL_STOP = 1
71 SERVICE_CONTROL_PAUSE = 2
72 SERVICE_CONTROL_CONTINUE = 3
73 SERVICE_CONTROL_INTERROGATE = 4
74 SERVICE_CONTROL_SHUTDOWN = 5
75 SERVICE_CONTROL_PARAMCHANGE = 6
76 SERVICE_CONTROL_NETBINDADD = 7
77 SERVICE_CONTROL_NETBINDREMOVE = 8
78 SERVICE_CONTROL_NETBINDENABLE = 9
79 SERVICE_CONTROL_NETBINDDISABLE = 10
80 SERVICE_CONTROL_DEVICEEVENT = 11
81 SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12
82 SERVICE_CONTROL_POWEREVENT = 13
83 SERVICE_CONTROL_SESSIONCHANGE = 14
khenaidoo26721882021-08-11 17:42:52 -040084 SERVICE_CONTROL_PRESHUTDOWN = 15
khenaidoo59ce9dd2019-11-11 13:05:32 -050085
86 SERVICE_ACTIVE = 1
87 SERVICE_INACTIVE = 2
88 SERVICE_STATE_ALL = 3
89
90 SERVICE_QUERY_CONFIG = 1
91 SERVICE_CHANGE_CONFIG = 2
92 SERVICE_QUERY_STATUS = 4
93 SERVICE_ENUMERATE_DEPENDENTS = 8
94 SERVICE_START = 16
95 SERVICE_STOP = 32
96 SERVICE_PAUSE_CONTINUE = 64
97 SERVICE_INTERROGATE = 128
98 SERVICE_USER_DEFINED_CONTROL = 256
99 SERVICE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_INTERROGATE | SERVICE_USER_DEFINED_CONTROL
100
101 SERVICE_RUNS_IN_SYSTEM_PROCESS = 1
102
103 SERVICE_CONFIG_DESCRIPTION = 1
104 SERVICE_CONFIG_FAILURE_ACTIONS = 2
105 SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 3
106 SERVICE_CONFIG_FAILURE_ACTIONS_FLAG = 4
107 SERVICE_CONFIG_SERVICE_SID_INFO = 5
108 SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 6
109 SERVICE_CONFIG_PRESHUTDOWN_INFO = 7
110 SERVICE_CONFIG_TRIGGER_INFO = 8
111 SERVICE_CONFIG_PREFERRED_NODE = 9
112 SERVICE_CONFIG_LAUNCH_PROTECTED = 12
113
114 SERVICE_SID_TYPE_NONE = 0
115 SERVICE_SID_TYPE_UNRESTRICTED = 1
116 SERVICE_SID_TYPE_RESTRICTED = 2 | SERVICE_SID_TYPE_UNRESTRICTED
117
118 SC_ENUM_PROCESS_INFO = 0
119
120 SERVICE_NOTIFY_STATUS_CHANGE = 2
121 SERVICE_NOTIFY_STOPPED = 0x00000001
122 SERVICE_NOTIFY_START_PENDING = 0x00000002
123 SERVICE_NOTIFY_STOP_PENDING = 0x00000004
124 SERVICE_NOTIFY_RUNNING = 0x00000008
125 SERVICE_NOTIFY_CONTINUE_PENDING = 0x00000010
126 SERVICE_NOTIFY_PAUSE_PENDING = 0x00000020
127 SERVICE_NOTIFY_PAUSED = 0x00000040
128 SERVICE_NOTIFY_CREATED = 0x00000080
129 SERVICE_NOTIFY_DELETED = 0x00000100
130 SERVICE_NOTIFY_DELETE_PENDING = 0x00000200
khenaidoo26721882021-08-11 17:42:52 -0400131
132 SC_EVENT_DATABASE_CHANGE = 0
133 SC_EVENT_PROPERTY_CHANGE = 1
134 SC_EVENT_STATUS_CHANGE = 2
khenaidoo59ce9dd2019-11-11 13:05:32 -0500135)
136
137type SERVICE_STATUS struct {
138 ServiceType uint32
139 CurrentState uint32
140 ControlsAccepted uint32
141 Win32ExitCode uint32
142 ServiceSpecificExitCode uint32
143 CheckPoint uint32
144 WaitHint uint32
145}
146
147type SERVICE_TABLE_ENTRY struct {
148 ServiceName *uint16
149 ServiceProc uintptr
150}
151
152type QUERY_SERVICE_CONFIG struct {
153 ServiceType uint32
154 StartType uint32
155 ErrorControl uint32
156 BinaryPathName *uint16
157 LoadOrderGroup *uint16
158 TagId uint32
159 Dependencies *uint16
160 ServiceStartName *uint16
161 DisplayName *uint16
162}
163
164type SERVICE_DESCRIPTION struct {
165 Description *uint16
166}
167
168type SERVICE_DELAYED_AUTO_START_INFO struct {
169 IsDelayedAutoStartUp uint32
170}
171
172type SERVICE_STATUS_PROCESS struct {
173 ServiceType uint32
174 CurrentState uint32
175 ControlsAccepted uint32
176 Win32ExitCode uint32
177 ServiceSpecificExitCode uint32
178 CheckPoint uint32
179 WaitHint uint32
180 ProcessId uint32
181 ServiceFlags uint32
182}
183
184type ENUM_SERVICE_STATUS_PROCESS struct {
185 ServiceName *uint16
186 DisplayName *uint16
187 ServiceStatusProcess SERVICE_STATUS_PROCESS
188}
189
190type SERVICE_NOTIFY struct {
191 Version uint32
192 NotifyCallback uintptr
193 Context uintptr
194 NotificationStatus uint32
195 ServiceStatus SERVICE_STATUS_PROCESS
196 NotificationTriggered uint32
197 ServiceNames *uint16
198}
199
200type SERVICE_FAILURE_ACTIONS struct {
201 ResetPeriod uint32
202 RebootMsg *uint16
203 Command *uint16
204 ActionsCount uint32
205 Actions *SC_ACTION
206}
207
208type SC_ACTION struct {
209 Type uint32
210 Delay uint32
211}
212
213type QUERY_SERVICE_LOCK_STATUS struct {
214 IsLocked uint32
215 LockOwner *uint16
216 LockDuration uint32
217}
218
219//sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle
220//sys CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) [failretval==0] = advapi32.CreateServiceW
221//sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW
222//sys DeleteService(service Handle) (err error) = advapi32.DeleteService
223//sys StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) = advapi32.StartServiceW
224//sys QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) = advapi32.QueryServiceStatus
225//sys QueryServiceLockStatus(mgr Handle, lockStatus *QUERY_SERVICE_LOCK_STATUS, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceLockStatusW
226//sys ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) = advapi32.ControlService
227//sys StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) = advapi32.StartServiceCtrlDispatcherW
228//sys SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) = advapi32.SetServiceStatus
229//sys ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) = advapi32.ChangeServiceConfigW
230//sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW
231//sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W
232//sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W
233//sys EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) = advapi32.EnumServicesStatusExW
234//sys QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceStatusEx
235//sys NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) = advapi32.NotifyServiceStatusChangeW
khenaidoo26721882021-08-11 17:42:52 -0400236//sys SubscribeServiceChangeNotifications(service Handle, eventType uint32, callback uintptr, callbackCtx uintptr, subscription *uintptr) (ret error) = sechost.SubscribeServiceChangeNotifications?
237//sys UnsubscribeServiceChangeNotifications(subscription uintptr) = sechost.UnsubscribeServiceChangeNotifications?