service.go (10435B)
1 // 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 //go:build windows 6 // +build windows 7 8 package windows 9 10 const ( 11 SC_MANAGER_CONNECT = 1 12 SC_MANAGER_CREATE_SERVICE = 2 13 SC_MANAGER_ENUMERATE_SERVICE = 4 14 SC_MANAGER_LOCK = 8 15 SC_MANAGER_QUERY_LOCK_STATUS = 16 16 SC_MANAGER_MODIFY_BOOT_CONFIG = 32 17 SC_MANAGER_ALL_ACCESS = 0xf003f 18 ) 19 20 const ( 21 SERVICE_KERNEL_DRIVER = 1 22 SERVICE_FILE_SYSTEM_DRIVER = 2 23 SERVICE_ADAPTER = 4 24 SERVICE_RECOGNIZER_DRIVER = 8 25 SERVICE_WIN32_OWN_PROCESS = 16 26 SERVICE_WIN32_SHARE_PROCESS = 32 27 SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS 28 SERVICE_INTERACTIVE_PROCESS = 256 29 SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_RECOGNIZER_DRIVER 30 SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS 31 32 SERVICE_BOOT_START = 0 33 SERVICE_SYSTEM_START = 1 34 SERVICE_AUTO_START = 2 35 SERVICE_DEMAND_START = 3 36 SERVICE_DISABLED = 4 37 38 SERVICE_ERROR_IGNORE = 0 39 SERVICE_ERROR_NORMAL = 1 40 SERVICE_ERROR_SEVERE = 2 41 SERVICE_ERROR_CRITICAL = 3 42 43 SC_STATUS_PROCESS_INFO = 0 44 45 SC_ACTION_NONE = 0 46 SC_ACTION_RESTART = 1 47 SC_ACTION_REBOOT = 2 48 SC_ACTION_RUN_COMMAND = 3 49 50 SERVICE_STOPPED = 1 51 SERVICE_START_PENDING = 2 52 SERVICE_STOP_PENDING = 3 53 SERVICE_RUNNING = 4 54 SERVICE_CONTINUE_PENDING = 5 55 SERVICE_PAUSE_PENDING = 6 56 SERVICE_PAUSED = 7 57 SERVICE_NO_CHANGE = 0xffffffff 58 59 SERVICE_ACCEPT_STOP = 1 60 SERVICE_ACCEPT_PAUSE_CONTINUE = 2 61 SERVICE_ACCEPT_SHUTDOWN = 4 62 SERVICE_ACCEPT_PARAMCHANGE = 8 63 SERVICE_ACCEPT_NETBINDCHANGE = 16 64 SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 32 65 SERVICE_ACCEPT_POWEREVENT = 64 66 SERVICE_ACCEPT_SESSIONCHANGE = 128 67 SERVICE_ACCEPT_PRESHUTDOWN = 256 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 SERVICE_CONTROL_PRESHUTDOWN = 15 84 85 SERVICE_ACTIVE = 1 86 SERVICE_INACTIVE = 2 87 SERVICE_STATE_ALL = 3 88 89 SERVICE_QUERY_CONFIG = 1 90 SERVICE_CHANGE_CONFIG = 2 91 SERVICE_QUERY_STATUS = 4 92 SERVICE_ENUMERATE_DEPENDENTS = 8 93 SERVICE_START = 16 94 SERVICE_STOP = 32 95 SERVICE_PAUSE_CONTINUE = 64 96 SERVICE_INTERROGATE = 128 97 SERVICE_USER_DEFINED_CONTROL = 256 98 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 99 100 SERVICE_RUNS_IN_SYSTEM_PROCESS = 1 101 102 SERVICE_CONFIG_DESCRIPTION = 1 103 SERVICE_CONFIG_FAILURE_ACTIONS = 2 104 SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 3 105 SERVICE_CONFIG_FAILURE_ACTIONS_FLAG = 4 106 SERVICE_CONFIG_SERVICE_SID_INFO = 5 107 SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 6 108 SERVICE_CONFIG_PRESHUTDOWN_INFO = 7 109 SERVICE_CONFIG_TRIGGER_INFO = 8 110 SERVICE_CONFIG_PREFERRED_NODE = 9 111 SERVICE_CONFIG_LAUNCH_PROTECTED = 12 112 113 SERVICE_SID_TYPE_NONE = 0 114 SERVICE_SID_TYPE_UNRESTRICTED = 1 115 SERVICE_SID_TYPE_RESTRICTED = 2 | SERVICE_SID_TYPE_UNRESTRICTED 116 117 SC_ENUM_PROCESS_INFO = 0 118 119 SERVICE_NOTIFY_STATUS_CHANGE = 2 120 SERVICE_NOTIFY_STOPPED = 0x00000001 121 SERVICE_NOTIFY_START_PENDING = 0x00000002 122 SERVICE_NOTIFY_STOP_PENDING = 0x00000004 123 SERVICE_NOTIFY_RUNNING = 0x00000008 124 SERVICE_NOTIFY_CONTINUE_PENDING = 0x00000010 125 SERVICE_NOTIFY_PAUSE_PENDING = 0x00000020 126 SERVICE_NOTIFY_PAUSED = 0x00000040 127 SERVICE_NOTIFY_CREATED = 0x00000080 128 SERVICE_NOTIFY_DELETED = 0x00000100 129 SERVICE_NOTIFY_DELETE_PENDING = 0x00000200 130 131 SC_EVENT_DATABASE_CHANGE = 0 132 SC_EVENT_PROPERTY_CHANGE = 1 133 SC_EVENT_STATUS_CHANGE = 2 134 135 SERVICE_START_REASON_DEMAND = 0x00000001 136 SERVICE_START_REASON_AUTO = 0x00000002 137 SERVICE_START_REASON_TRIGGER = 0x00000004 138 SERVICE_START_REASON_RESTART_ON_FAILURE = 0x00000008 139 SERVICE_START_REASON_DELAYEDAUTO = 0x00000010 140 141 SERVICE_DYNAMIC_INFORMATION_LEVEL_START_REASON = 1 142 ) 143 144 type ENUM_SERVICE_STATUS struct { 145 ServiceName *uint16 146 DisplayName *uint16 147 ServiceStatus SERVICE_STATUS 148 } 149 150 type SERVICE_STATUS struct { 151 ServiceType uint32 152 CurrentState uint32 153 ControlsAccepted uint32 154 Win32ExitCode uint32 155 ServiceSpecificExitCode uint32 156 CheckPoint uint32 157 WaitHint uint32 158 } 159 160 type SERVICE_TABLE_ENTRY struct { 161 ServiceName *uint16 162 ServiceProc uintptr 163 } 164 165 type QUERY_SERVICE_CONFIG struct { 166 ServiceType uint32 167 StartType uint32 168 ErrorControl uint32 169 BinaryPathName *uint16 170 LoadOrderGroup *uint16 171 TagId uint32 172 Dependencies *uint16 173 ServiceStartName *uint16 174 DisplayName *uint16 175 } 176 177 type SERVICE_DESCRIPTION struct { 178 Description *uint16 179 } 180 181 type SERVICE_DELAYED_AUTO_START_INFO struct { 182 IsDelayedAutoStartUp uint32 183 } 184 185 type SERVICE_STATUS_PROCESS struct { 186 ServiceType uint32 187 CurrentState uint32 188 ControlsAccepted uint32 189 Win32ExitCode uint32 190 ServiceSpecificExitCode uint32 191 CheckPoint uint32 192 WaitHint uint32 193 ProcessId uint32 194 ServiceFlags uint32 195 } 196 197 type ENUM_SERVICE_STATUS_PROCESS struct { 198 ServiceName *uint16 199 DisplayName *uint16 200 ServiceStatusProcess SERVICE_STATUS_PROCESS 201 } 202 203 type SERVICE_NOTIFY struct { 204 Version uint32 205 NotifyCallback uintptr 206 Context uintptr 207 NotificationStatus uint32 208 ServiceStatus SERVICE_STATUS_PROCESS 209 NotificationTriggered uint32 210 ServiceNames *uint16 211 } 212 213 type SERVICE_FAILURE_ACTIONS struct { 214 ResetPeriod uint32 215 RebootMsg *uint16 216 Command *uint16 217 ActionsCount uint32 218 Actions *SC_ACTION 219 } 220 221 type SC_ACTION struct { 222 Type uint32 223 Delay uint32 224 } 225 226 type QUERY_SERVICE_LOCK_STATUS struct { 227 IsLocked uint32 228 LockOwner *uint16 229 LockDuration uint32 230 } 231 232 //sys OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenSCManagerW 233 //sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle 234 //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 235 //sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW 236 //sys DeleteService(service Handle) (err error) = advapi32.DeleteService 237 //sys StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) = advapi32.StartServiceW 238 //sys QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) = advapi32.QueryServiceStatus 239 //sys QueryServiceLockStatus(mgr Handle, lockStatus *QUERY_SERVICE_LOCK_STATUS, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceLockStatusW 240 //sys ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) = advapi32.ControlService 241 //sys StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) = advapi32.StartServiceCtrlDispatcherW 242 //sys SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) = advapi32.SetServiceStatus 243 //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 244 //sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW 245 //sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W 246 //sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W 247 //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 248 //sys QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceStatusEx 249 //sys NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) = advapi32.NotifyServiceStatusChangeW 250 //sys SubscribeServiceChangeNotifications(service Handle, eventType uint32, callback uintptr, callbackCtx uintptr, subscription *uintptr) (ret error) = sechost.SubscribeServiceChangeNotifications? 251 //sys UnsubscribeServiceChangeNotifications(subscription uintptr) = sechost.UnsubscribeServiceChangeNotifications? 252 //sys RegisterServiceCtrlHandlerEx(serviceName *uint16, handlerProc uintptr, context uintptr) (handle Handle, err error) = advapi32.RegisterServiceCtrlHandlerExW 253 //sys QueryServiceDynamicInformation(service Handle, infoLevel uint32, dynamicInfo unsafe.Pointer) (err error) = advapi32.QueryServiceDynamicInformation? 254 //sys EnumDependentServices(service Handle, activityState uint32, services *ENUM_SERVICE_STATUS, buffSize uint32, bytesNeeded *uint32, servicesReturned *uint32) (err error) = advapi32.EnumDependentServicesW