blob: 62fc31b40bd92a25fd6b7a98e96814eadeff6301 [file] [log] [blame]
Matteo Scandolo1f49bf52018-11-20 13:56:45 -08001// 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
68
69 SERVICE_CONTROL_STOP = 1
70 SERVICE_CONTROL_PAUSE = 2
71 SERVICE_CONTROL_CONTINUE = 3
72 SERVICE_CONTROL_INTERROGATE = 4
73 SERVICE_CONTROL_SHUTDOWN = 5
74 SERVICE_CONTROL_PARAMCHANGE = 6
75 SERVICE_CONTROL_NETBINDADD = 7
76 SERVICE_CONTROL_NETBINDREMOVE = 8
77 SERVICE_CONTROL_NETBINDENABLE = 9
78 SERVICE_CONTROL_NETBINDDISABLE = 10
79 SERVICE_CONTROL_DEVICEEVENT = 11
80 SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12
81 SERVICE_CONTROL_POWEREVENT = 13
82 SERVICE_CONTROL_SESSIONCHANGE = 14
83
84 SERVICE_ACTIVE = 1
85 SERVICE_INACTIVE = 2
86 SERVICE_STATE_ALL = 3
87
88 SERVICE_QUERY_CONFIG = 1
89 SERVICE_CHANGE_CONFIG = 2
90 SERVICE_QUERY_STATUS = 4
91 SERVICE_ENUMERATE_DEPENDENTS = 8
92 SERVICE_START = 16
93 SERVICE_STOP = 32
94 SERVICE_PAUSE_CONTINUE = 64
95 SERVICE_INTERROGATE = 128
96 SERVICE_USER_DEFINED_CONTROL = 256
97 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
98 SERVICE_RUNS_IN_SYSTEM_PROCESS = 1
99 SERVICE_CONFIG_DESCRIPTION = 1
100 SERVICE_CONFIG_FAILURE_ACTIONS = 2
101
102 NO_ERROR = 0
103
104 SC_ENUM_PROCESS_INFO = 0
105)
106
107type SERVICE_STATUS struct {
108 ServiceType uint32
109 CurrentState uint32
110 ControlsAccepted uint32
111 Win32ExitCode uint32
112 ServiceSpecificExitCode uint32
113 CheckPoint uint32
114 WaitHint uint32
115}
116
117type SERVICE_TABLE_ENTRY struct {
118 ServiceName *uint16
119 ServiceProc uintptr
120}
121
122type QUERY_SERVICE_CONFIG struct {
123 ServiceType uint32
124 StartType uint32
125 ErrorControl uint32
126 BinaryPathName *uint16
127 LoadOrderGroup *uint16
128 TagId uint32
129 Dependencies *uint16
130 ServiceStartName *uint16
131 DisplayName *uint16
132}
133
134type SERVICE_DESCRIPTION struct {
135 Description *uint16
136}
137
138type SERVICE_STATUS_PROCESS struct {
139 ServiceType uint32
140 CurrentState uint32
141 ControlsAccepted uint32
142 Win32ExitCode uint32
143 ServiceSpecificExitCode uint32
144 CheckPoint uint32
145 WaitHint uint32
146 ProcessId uint32
147 ServiceFlags uint32
148}
149
150type ENUM_SERVICE_STATUS_PROCESS struct {
151 ServiceName *uint16
152 DisplayName *uint16
153 ServiceStatusProcess SERVICE_STATUS_PROCESS
154}
155
156type SERVICE_FAILURE_ACTIONS struct {
157 ResetPeriod uint32
158 RebootMsg *uint16
159 Command *uint16
160 ActionsCount uint32
161 Actions *SC_ACTION
162}
163
164type SC_ACTION struct {
165 Type uint32
166 Delay uint32
167}
168
169//sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle
170//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
171//sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW
172//sys DeleteService(service Handle) (err error) = advapi32.DeleteService
173//sys StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) = advapi32.StartServiceW
174//sys QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) = advapi32.QueryServiceStatus
175//sys ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) = advapi32.ControlService
176//sys StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) = advapi32.StartServiceCtrlDispatcherW
177//sys SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) = advapi32.SetServiceStatus
178//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
179//sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW
180//sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W
181//sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W
182//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
183//sys QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceStatusEx