service.go (9054B)
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 // +build windows 6 7 package windows 8 9 const ( 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 21 const ( 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 SERVICE_ACCEPT_PRESHUTDOWN = 256 69 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 84 SERVICE_CONTROL_PRESHUTDOWN = 15 85 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 131 ) 132 133 type SERVICE_STATUS struct { 134 ServiceType uint32 135 CurrentState uint32 136 ControlsAccepted uint32 137 Win32ExitCode uint32 138 ServiceSpecificExitCode uint32 139 CheckPoint uint32 140 WaitHint uint32 141 } 142 143 type SERVICE_TABLE_ENTRY struct { 144 ServiceName *uint16 145 ServiceProc uintptr 146 } 147 148 type QUERY_SERVICE_CONFIG struct { 149 ServiceType uint32 150 StartType uint32 151 ErrorControl uint32 152 BinaryPathName *uint16 153 LoadOrderGroup *uint16 154 TagId uint32 155 Dependencies *uint16 156 ServiceStartName *uint16 157 DisplayName *uint16 158 } 159 160 type SERVICE_DESCRIPTION struct { 161 Description *uint16 162 } 163 164 type SERVICE_DELAYED_AUTO_START_INFO struct { 165 IsDelayedAutoStartUp uint32 166 } 167 168 type SERVICE_STATUS_PROCESS struct { 169 ServiceType uint32 170 CurrentState uint32 171 ControlsAccepted uint32 172 Win32ExitCode uint32 173 ServiceSpecificExitCode uint32 174 CheckPoint uint32 175 WaitHint uint32 176 ProcessId uint32 177 ServiceFlags uint32 178 } 179 180 type ENUM_SERVICE_STATUS_PROCESS struct { 181 ServiceName *uint16 182 DisplayName *uint16 183 ServiceStatusProcess SERVICE_STATUS_PROCESS 184 } 185 186 type SERVICE_NOTIFY struct { 187 Version uint32 188 NotifyCallback uintptr 189 Context uintptr 190 NotificationStatus uint32 191 ServiceStatus SERVICE_STATUS_PROCESS 192 NotificationTriggered uint32 193 ServiceNames *uint16 194 } 195 196 type SERVICE_FAILURE_ACTIONS struct { 197 ResetPeriod uint32 198 RebootMsg *uint16 199 Command *uint16 200 ActionsCount uint32 201 Actions *SC_ACTION 202 } 203 204 type SC_ACTION struct { 205 Type uint32 206 Delay uint32 207 } 208 209 type QUERY_SERVICE_LOCK_STATUS struct { 210 IsLocked uint32 211 LockOwner *uint16 212 LockDuration uint32 213 } 214 215 //sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle 216 //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 217 //sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW 218 //sys DeleteService(service Handle) (err error) = advapi32.DeleteService 219 //sys StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) = advapi32.StartServiceW 220 //sys QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) = advapi32.QueryServiceStatus 221 //sys QueryServiceLockStatus(mgr Handle, lockStatus *QUERY_SERVICE_LOCK_STATUS, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceLockStatusW 222 //sys ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) = advapi32.ControlService 223 //sys StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) = advapi32.StartServiceCtrlDispatcherW 224 //sys SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) = advapi32.SetServiceStatus 225 //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 226 //sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW 227 //sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W 228 //sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W 229 //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 230 //sys QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceStatusEx 231 //sys NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) = advapi32.NotifyServiceStatusChangeW