golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/windows/service.go (about)

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