Home | History | Annotate | Download | only in include
      1 /**
      2  * This file has no copyright assigned and is placed in the Public Domain.
      3  * This file is part of the mingw-w64 runtime package.
      4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
      5  */
      6 #ifndef _WINSVC_
      7 #define _WINSVC_
      8 
      9 #include <_mingw.h>
     10 #include <_mingw_unicode.h>
     11 #include <apisetcconv.h>
     12 
     13 #ifdef __cplusplus
     14 extern "C" {
     15 #endif
     16 
     17 #define SERVICES_ACTIVE_DATABASEW L"ServicesActive"
     18 #define SERVICES_FAILED_DATABASEW L"ServicesFailed"
     19 
     20 #define SERVICES_ACTIVE_DATABASEA "ServicesActive"
     21 #define SERVICES_FAILED_DATABASEA "ServicesFailed"
     22 
     23 #define SC_GROUP_IDENTIFIERW L'+'
     24 #define SC_GROUP_IDENTIFIERA '+'
     25 
     26 #define SERVICES_ACTIVE_DATABASE __MINGW_NAME_AW(SERVICES_ACTIVE_DATABASE)
     27 #define SERVICES_FAILED_DATABASE __MINGW_NAME_AW(SERVICES_FAILED_DATABASE)
     28 
     29 #define SC_GROUP_IDENTIFIER __MINGW_NAME_AW(SC_GROUP_IDENTIFIER)
     30 
     31 #define SERVICE_NO_CHANGE 0xffffffff
     32 
     33 #define SERVICE_ACTIVE 0x00000001
     34 #define SERVICE_INACTIVE 0x00000002
     35 #define SERVICE_STATE_ALL (SERVICE_ACTIVE | SERVICE_INACTIVE)
     36 
     37 #define SERVICE_CONTROL_STOP 0x00000001
     38 #define SERVICE_CONTROL_PAUSE 0x00000002
     39 #define SERVICE_CONTROL_CONTINUE 0x00000003
     40 #define SERVICE_CONTROL_INTERROGATE 0x00000004
     41 #define SERVICE_CONTROL_SHUTDOWN 0x00000005
     42 #define SERVICE_CONTROL_PARAMCHANGE 0x00000006
     43 #define SERVICE_CONTROL_NETBINDADD 0x00000007
     44 #define SERVICE_CONTROL_NETBINDREMOVE 0x00000008
     45 #define SERVICE_CONTROL_NETBINDENABLE 0x00000009
     46 #define SERVICE_CONTROL_NETBINDDISABLE 0x0000000A
     47 #define SERVICE_CONTROL_DEVICEEVENT 0x0000000B
     48 #define SERVICE_CONTROL_HARDWAREPROFILECHANGE 0x0000000C
     49 #define SERVICE_CONTROL_POWEREVENT 0x0000000D
     50 #define SERVICE_CONTROL_SESSIONCHANGE 0x0000000E
     51 
     52 #define SERVICE_STOPPED 0x00000001
     53 #define SERVICE_START_PENDING 0x00000002
     54 #define SERVICE_STOP_PENDING 0x00000003
     55 #define SERVICE_RUNNING 0x00000004
     56 #define SERVICE_CONTINUE_PENDING 0x00000005
     57 #define SERVICE_PAUSE_PENDING 0x00000006
     58 #define SERVICE_PAUSED 0x00000007
     59 
     60 #define SERVICE_ACCEPT_STOP 0x00000001
     61 #define SERVICE_ACCEPT_PAUSE_CONTINUE 0x00000002
     62 #define SERVICE_ACCEPT_SHUTDOWN 0x00000004
     63 #define SERVICE_ACCEPT_PARAMCHANGE 0x00000008
     64 #define SERVICE_ACCEPT_NETBINDCHANGE 0x00000010
     65 #define SERVICE_ACCEPT_HARDWAREPROFILECHANGE 0x00000020
     66 #define SERVICE_ACCEPT_POWEREVENT 0x00000040
     67 #define SERVICE_ACCEPT_SESSIONCHANGE 0x00000080
     68 
     69 #define SC_MANAGER_CONNECT 0x0001
     70 #define SC_MANAGER_CREATE_SERVICE 0x0002
     71 #define SC_MANAGER_ENUMERATE_SERVICE 0x0004
     72 #define SC_MANAGER_LOCK 0x0008
     73 #define SC_MANAGER_QUERY_LOCK_STATUS 0x0010
     74 #define SC_MANAGER_MODIFY_BOOT_CONFIG 0x0020
     75 
     76 #define SC_MANAGER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_LOCK | SC_MANAGER_QUERY_LOCK_STATUS | SC_MANAGER_MODIFY_BOOT_CONFIG)
     77 
     78 #define SERVICE_QUERY_CONFIG 0x0001
     79 #define SERVICE_CHANGE_CONFIG 0x0002
     80 #define SERVICE_QUERY_STATUS 0x0004
     81 #define SERVICE_ENUMERATE_DEPENDENTS 0x0008
     82 #define SERVICE_START 0x0010
     83 #define SERVICE_STOP 0x0020
     84 #define SERVICE_PAUSE_CONTINUE 0x0040
     85 #define SERVICE_INTERROGATE 0x0080
     86 #define SERVICE_USER_DEFINED_CONTROL 0x0100
     87 
     88 #define 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)
     89 
     90 #define SERVICE_RUNS_IN_SYSTEM_PROCESS 0x00000001
     91 
     92 #define SERVICE_CONFIG_DESCRIPTION 1
     93 #define SERVICE_CONFIG_FAILURE_ACTIONS 2
     94 
     95   typedef struct _SERVICE_DESCRIPTIONA {
     96     LPSTR lpDescription;
     97   } SERVICE_DESCRIPTIONA,*LPSERVICE_DESCRIPTIONA;
     98 
     99   typedef struct _SERVICE_DESCRIPTIONW {
    100     LPWSTR lpDescription;
    101   } SERVICE_DESCRIPTIONW,*LPSERVICE_DESCRIPTIONW;
    102 
    103   __MINGW_TYPEDEF_AW(SERVICE_DESCRIPTION)
    104   __MINGW_TYPEDEF_AW(LPSERVICE_DESCRIPTION)
    105 
    106   typedef enum _SC_ACTION_TYPE {
    107     SC_ACTION_NONE = 0,SC_ACTION_RESTART = 1,SC_ACTION_REBOOT = 2,SC_ACTION_RUN_COMMAND = 3
    108   } SC_ACTION_TYPE;
    109 
    110   typedef struct _SC_ACTION {
    111     SC_ACTION_TYPE Type;
    112     DWORD Delay;
    113   } SC_ACTION,*LPSC_ACTION;
    114 
    115   typedef struct _SERVICE_FAILURE_ACTIONSA {
    116     DWORD dwResetPeriod;
    117     LPSTR lpRebootMsg;
    118     LPSTR lpCommand;
    119     DWORD cActions;
    120     SC_ACTION *lpsaActions;
    121   } SERVICE_FAILURE_ACTIONSA,*LPSERVICE_FAILURE_ACTIONSA;
    122 
    123   typedef struct _SERVICE_FAILURE_ACTIONSW {
    124     DWORD dwResetPeriod;
    125     LPWSTR lpRebootMsg;
    126     LPWSTR lpCommand;
    127     DWORD cActions;
    128     SC_ACTION *lpsaActions;
    129   } SERVICE_FAILURE_ACTIONSW,*LPSERVICE_FAILURE_ACTIONSW;
    130 
    131   __MINGW_TYPEDEF_AW(SERVICE_FAILURE_ACTIONS)
    132   __MINGW_TYPEDEF_AW(LPSERVICE_FAILURE_ACTIONS)
    133 
    134   DECLARE_HANDLE(SC_HANDLE);
    135   typedef SC_HANDLE *LPSC_HANDLE;
    136 
    137   DECLARE_HANDLE(SERVICE_STATUS_HANDLE);
    138 
    139   typedef enum _SC_STATUS_TYPE {
    140     SC_STATUS_PROCESS_INFO = 0
    141   } SC_STATUS_TYPE;
    142 
    143   typedef enum _SC_ENUM_TYPE {
    144     SC_ENUM_PROCESS_INFO = 0
    145   } SC_ENUM_TYPE;
    146 
    147   typedef struct _SERVICE_STATUS {
    148     DWORD dwServiceType;
    149     DWORD dwCurrentState;
    150     DWORD dwControlsAccepted;
    151     DWORD dwWin32ExitCode;
    152     DWORD dwServiceSpecificExitCode;
    153     DWORD dwCheckPoint;
    154     DWORD dwWaitHint;
    155   } SERVICE_STATUS,*LPSERVICE_STATUS;
    156 
    157   typedef struct _SERVICE_STATUS_PROCESS {
    158     DWORD dwServiceType;
    159     DWORD dwCurrentState;
    160     DWORD dwControlsAccepted;
    161     DWORD dwWin32ExitCode;
    162     DWORD dwServiceSpecificExitCode;
    163     DWORD dwCheckPoint;
    164     DWORD dwWaitHint;
    165     DWORD dwProcessId;
    166     DWORD dwServiceFlags;
    167   } SERVICE_STATUS_PROCESS,*LPSERVICE_STATUS_PROCESS;
    168 
    169   typedef struct _ENUM_SERVICE_STATUSA {
    170     LPSTR lpServiceName;
    171     LPSTR lpDisplayName;
    172     SERVICE_STATUS ServiceStatus;
    173   } ENUM_SERVICE_STATUSA,*LPENUM_SERVICE_STATUSA;
    174 
    175   typedef struct _ENUM_SERVICE_STATUSW {
    176     LPWSTR lpServiceName;
    177     LPWSTR lpDisplayName;
    178     SERVICE_STATUS ServiceStatus;
    179   } ENUM_SERVICE_STATUSW,*LPENUM_SERVICE_STATUSW;
    180 
    181   __MINGW_TYPEDEF_AW(ENUM_SERVICE_STATUS)
    182   __MINGW_TYPEDEF_AW(LPENUM_SERVICE_STATUS)
    183 
    184   typedef struct _ENUM_SERVICE_STATUS_PROCESSA {
    185     LPSTR lpServiceName;
    186     LPSTR lpDisplayName;
    187     SERVICE_STATUS_PROCESS ServiceStatusProcess;
    188   } ENUM_SERVICE_STATUS_PROCESSA,*LPENUM_SERVICE_STATUS_PROCESSA;
    189 
    190   typedef struct _ENUM_SERVICE_STATUS_PROCESSW {
    191     LPWSTR lpServiceName;
    192     LPWSTR lpDisplayName;
    193     SERVICE_STATUS_PROCESS ServiceStatusProcess;
    194   } ENUM_SERVICE_STATUS_PROCESSW,*LPENUM_SERVICE_STATUS_PROCESSW;
    195 
    196   __MINGW_TYPEDEF_AW(ENUM_SERVICE_STATUS_PROCESS)
    197   __MINGW_TYPEDEF_AW(LPENUM_SERVICE_STATUS_PROCESS)
    198 
    199   typedef LPVOID SC_LOCK;
    200 
    201   typedef struct _QUERY_SERVICE_LOCK_STATUSA {
    202     DWORD fIsLocked;
    203     LPSTR lpLockOwner;
    204     DWORD dwLockDuration;
    205   } QUERY_SERVICE_LOCK_STATUSA,*LPQUERY_SERVICE_LOCK_STATUSA;
    206 
    207   typedef struct _QUERY_SERVICE_LOCK_STATUSW {
    208     DWORD fIsLocked;
    209     LPWSTR lpLockOwner;
    210     DWORD dwLockDuration;
    211   } QUERY_SERVICE_LOCK_STATUSW,*LPQUERY_SERVICE_LOCK_STATUSW;
    212 
    213   __MINGW_TYPEDEF_AW(QUERY_SERVICE_LOCK_STATUS)
    214   __MINGW_TYPEDEF_AW(LPQUERY_SERVICE_LOCK_STATUS)
    215 
    216   typedef struct _QUERY_SERVICE_CONFIGA {
    217     DWORD dwServiceType;
    218     DWORD dwStartType;
    219     DWORD dwErrorControl;
    220     LPSTR lpBinaryPathName;
    221     LPSTR lpLoadOrderGroup;
    222     DWORD dwTagId;
    223     LPSTR lpDependencies;
    224     LPSTR lpServiceStartName;
    225     LPSTR lpDisplayName;
    226   } QUERY_SERVICE_CONFIGA,*LPQUERY_SERVICE_CONFIGA;
    227 
    228   typedef struct _QUERY_SERVICE_CONFIGW {
    229     DWORD dwServiceType;
    230     DWORD dwStartType;
    231     DWORD dwErrorControl;
    232     LPWSTR lpBinaryPathName;
    233     LPWSTR lpLoadOrderGroup;
    234     DWORD dwTagId;
    235     LPWSTR lpDependencies;
    236     LPWSTR lpServiceStartName;
    237     LPWSTR lpDisplayName;
    238   } QUERY_SERVICE_CONFIGW,*LPQUERY_SERVICE_CONFIGW;
    239 
    240   __MINGW_TYPEDEF_AW(QUERY_SERVICE_CONFIG)
    241   __MINGW_TYPEDEF_AW(LPQUERY_SERVICE_CONFIG)
    242 
    243   typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONW)(DWORD dwNumServicesArgs,LPWSTR *lpServiceArgVectors);
    244   typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONA)(DWORD dwNumServicesArgs,LPSTR *lpServiceArgVectors);
    245 
    246 #define LPSERVICE_MAIN_FUNCTION __MINGW_NAME_AW(LPSERVICE_MAIN_FUNCTION)
    247 
    248   typedef struct _SERVICE_TABLE_ENTRYA {
    249     LPSTR lpServiceName;
    250     LPSERVICE_MAIN_FUNCTIONA lpServiceProc;
    251   } SERVICE_TABLE_ENTRYA,*LPSERVICE_TABLE_ENTRYA;
    252 
    253   typedef struct _SERVICE_TABLE_ENTRYW {
    254     LPWSTR lpServiceName;
    255     LPSERVICE_MAIN_FUNCTIONW lpServiceProc;
    256   } SERVICE_TABLE_ENTRYW,*LPSERVICE_TABLE_ENTRYW;
    257 
    258   __MINGW_TYPEDEF_AW(SERVICE_TABLE_ENTRY)
    259   __MINGW_TYPEDEF_AW(LPSERVICE_TABLE_ENTRY)
    260 
    261   typedef VOID (WINAPI *LPHANDLER_FUNCTION)(DWORD dwControl);
    262   typedef DWORD (WINAPI *LPHANDLER_FUNCTION_EX)(DWORD dwControl,DWORD dwEventType,LPVOID lpEventData,LPVOID lpContext);
    263 
    264 #define ChangeServiceConfig __MINGW_NAME_AW(ChangeServiceConfig)
    265 #define ChangeServiceConfig2 __MINGW_NAME_AW(ChangeServiceConfig2)
    266 #define CreateService __MINGW_NAME_AW(CreateService)
    267 #define EnumDependentServices __MINGW_NAME_AW(EnumDependentServices)
    268 #define EnumServicesStatus __MINGW_NAME_AW(EnumServicesStatus)
    269 #define EnumServicesStatusEx __MINGW_NAME_AW(EnumServicesStatusEx)
    270 #define GetServiceKeyName __MINGW_NAME_AW(GetServiceKeyName)
    271 #define GetServiceDisplayName __MINGW_NAME_AW(GetServiceDisplayName)
    272 #define OpenSCManager __MINGW_NAME_AW(OpenSCManager)
    273 #define OpenService __MINGW_NAME_AW(OpenService)
    274 #define QueryServiceConfig __MINGW_NAME_AW(QueryServiceConfig)
    275 #define QueryServiceConfig2 __MINGW_NAME_AW(QueryServiceConfig2)
    276 #define QueryServiceLockStatus __MINGW_NAME_AW(QueryServiceLockStatus)
    277 #define RegisterServiceCtrlHandler __MINGW_NAME_AW(RegisterServiceCtrlHandler)
    278 #define RegisterServiceCtrlHandlerEx __MINGW_NAME_AW(RegisterServiceCtrlHandlerEx)
    279 #define StartServiceCtrlDispatcher __MINGW_NAME_AW(StartServiceCtrlDispatcher)
    280 #define StartService __MINGW_NAME_AW(StartService)
    281 
    282   WINADVAPI WINBOOL WINAPI ChangeServiceConfigA(SC_HANDLE hService,DWORD dwServiceType,DWORD dwStartType,DWORD dwErrorControl,LPCSTR lpBinaryPathName,LPCSTR lpLoadOrderGroup,LPDWORD lpdwTagId,LPCSTR lpDependencies,LPCSTR lpServiceStartName,LPCSTR lpPassword,LPCSTR lpDisplayName);
    283   WINADVAPI WINBOOL WINAPI ChangeServiceConfigW(SC_HANDLE hService,DWORD dwServiceType,DWORD dwStartType,DWORD dwErrorControl,LPCWSTR lpBinaryPathName,LPCWSTR lpLoadOrderGroup,LPDWORD lpdwTagId,LPCWSTR lpDependencies,LPCWSTR lpServiceStartName,LPCWSTR lpPassword,LPCWSTR lpDisplayName);
    284   WINADVAPI WINBOOL WINAPI ChangeServiceConfig2A(SC_HANDLE hService,DWORD dwInfoLevel,LPVOID lpInfo);
    285   WINADVAPI WINBOOL WINAPI ChangeServiceConfig2W(SC_HANDLE hService,DWORD dwInfoLevel,LPVOID lpInfo);
    286   WINADVAPI WINBOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject);
    287   WINADVAPI WINBOOL WINAPI ControlService(SC_HANDLE hService,DWORD dwControl,LPSERVICE_STATUS lpServiceStatus);
    288   WINADVAPI SC_HANDLE WINAPI CreateServiceA(SC_HANDLE hSCManager,LPCSTR lpServiceName,LPCSTR lpDisplayName,DWORD dwDesiredAccess,DWORD dwServiceType,DWORD dwStartType,DWORD dwErrorControl,LPCSTR lpBinaryPathName,LPCSTR lpLoadOrderGroup,LPDWORD lpdwTagId,LPCSTR lpDependencies,LPCSTR lpServiceStartName,LPCSTR lpPassword);
    289   WINADVAPI SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager,LPCWSTR lpServiceName,LPCWSTR lpDisplayName,DWORD dwDesiredAccess,DWORD dwServiceType,DWORD dwStartType,DWORD dwErrorControl,LPCWSTR lpBinaryPathName,LPCWSTR lpLoadOrderGroup,LPDWORD lpdwTagId,LPCWSTR lpDependencies,LPCWSTR lpServiceStartName,LPCWSTR lpPassword);
    290   WINADVAPI WINBOOL WINAPI DeleteService(SC_HANDLE hService);
    291   WINADVAPI WINBOOL WINAPI EnumDependentServicesA(SC_HANDLE hService,DWORD dwServiceState,LPENUM_SERVICE_STATUSA lpServices,DWORD cbBufSize,LPDWORD pcbBytesNeeded,LPDWORD lpServicesReturned);
    292   WINADVAPI WINBOOL WINAPI EnumDependentServicesW(SC_HANDLE hService,DWORD dwServiceState,LPENUM_SERVICE_STATUSW lpServices,DWORD cbBufSize,LPDWORD pcbBytesNeeded,LPDWORD lpServicesReturned);
    293   WINADVAPI WINBOOL WINAPI EnumServicesStatusA(SC_HANDLE hSCManager,DWORD dwServiceType,DWORD dwServiceState,LPENUM_SERVICE_STATUSA lpServices,DWORD cbBufSize,LPDWORD pcbBytesNeeded,LPDWORD lpServicesReturned,LPDWORD lpResumeHandle);
    294   WINADVAPI WINBOOL WINAPI EnumServicesStatusW(SC_HANDLE hSCManager,DWORD dwServiceType,DWORD dwServiceState,LPENUM_SERVICE_STATUSW lpServices,DWORD cbBufSize,LPDWORD pcbBytesNeeded,LPDWORD lpServicesReturned,LPDWORD lpResumeHandle);
    295   WINADVAPI WINBOOL WINAPI EnumServicesStatusExA(SC_HANDLE hSCManager,SC_ENUM_TYPE InfoLevel,DWORD dwServiceType,DWORD dwServiceState,LPBYTE lpServices,DWORD cbBufSize,LPDWORD pcbBytesNeeded,LPDWORD lpServicesReturned,LPDWORD lpResumeHandle,LPCSTR pszGroupName);
    296   WINADVAPI WINBOOL WINAPI EnumServicesStatusExW(SC_HANDLE hSCManager,SC_ENUM_TYPE InfoLevel,DWORD dwServiceType,DWORD dwServiceState,LPBYTE lpServices,DWORD cbBufSize,LPDWORD pcbBytesNeeded,LPDWORD lpServicesReturned,LPDWORD lpResumeHandle,LPCWSTR pszGroupName);
    297   WINADVAPI WINBOOL WINAPI GetServiceKeyNameA(SC_HANDLE hSCManager,LPCSTR lpDisplayName,LPSTR lpServiceName,LPDWORD lpcchBuffer);
    298   WINADVAPI WINBOOL WINAPI GetServiceKeyNameW(SC_HANDLE hSCManager,LPCWSTR lpDisplayName,LPWSTR lpServiceName,LPDWORD lpcchBuffer);
    299   WINADVAPI WINBOOL WINAPI GetServiceDisplayNameA(SC_HANDLE hSCManager,LPCSTR lpServiceName,LPSTR lpDisplayName,LPDWORD lpcchBuffer);
    300   WINADVAPI WINBOOL WINAPI GetServiceDisplayNameW(SC_HANDLE hSCManager,LPCWSTR lpServiceName,LPWSTR lpDisplayName,LPDWORD lpcchBuffer);
    301   WINADVAPI SC_LOCK WINAPI LockServiceDatabase(SC_HANDLE hSCManager);
    302   WINADVAPI WINBOOL WINAPI NotifyBootConfigStatus(WINBOOL BootAcceptable);
    303   WINADVAPI SC_HANDLE WINAPI OpenSCManagerA(LPCSTR lpMachineName,LPCSTR lpDatabaseName,DWORD dwDesiredAccess);
    304   WINADVAPI SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName,LPCWSTR lpDatabaseName,DWORD dwDesiredAccess);
    305   WINADVAPI SC_HANDLE WINAPI OpenServiceA(SC_HANDLE hSCManager,LPCSTR lpServiceName,DWORD dwDesiredAccess);
    306   WINADVAPI SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager,LPCWSTR lpServiceName,DWORD dwDesiredAccess);
    307   WINADVAPI WINBOOL WINAPI QueryServiceConfigA(SC_HANDLE hService,LPQUERY_SERVICE_CONFIGA lpServiceConfig,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    308   WINADVAPI WINBOOL WINAPI QueryServiceConfigW(SC_HANDLE hService,LPQUERY_SERVICE_CONFIGW lpServiceConfig,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    309   WINADVAPI WINBOOL WINAPI QueryServiceConfig2A(SC_HANDLE hService,DWORD dwInfoLevel,LPBYTE lpBuffer,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    310   WINADVAPI WINBOOL WINAPI QueryServiceConfig2W(SC_HANDLE hService,DWORD dwInfoLevel,LPBYTE lpBuffer,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    311   WINADVAPI WINBOOL WINAPI QueryServiceLockStatusA(SC_HANDLE hSCManager,LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    312   WINADVAPI WINBOOL WINAPI QueryServiceLockStatusW(SC_HANDLE hSCManager,LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    313   WINADVAPI WINBOOL WINAPI QueryServiceObjectSecurity(SC_HANDLE hService,SECURITY_INFORMATION dwSecurityInformation,PSECURITY_DESCRIPTOR lpSecurityDescriptor,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    314   WINADVAPI WINBOOL WINAPI QueryServiceStatus(SC_HANDLE hService,LPSERVICE_STATUS lpServiceStatus);
    315   WINADVAPI WINBOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService,SC_STATUS_TYPE InfoLevel,LPBYTE lpBuffer,DWORD cbBufSize,LPDWORD pcbBytesNeeded);
    316   WINADVAPI SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerA(LPCSTR lpServiceName,LPHANDLER_FUNCTION lpHandlerProc);
    317   WINADVAPI SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,LPHANDLER_FUNCTION lpHandlerProc);
    318   WINADVAPI SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExA(LPCSTR lpServiceName,LPHANDLER_FUNCTION_EX lpHandlerProc,LPVOID lpContext);
    319   WINADVAPI SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,LPHANDLER_FUNCTION_EX lpHandlerProc,LPVOID lpContext);
    320   WINADVAPI WINBOOL WINAPI SetServiceObjectSecurity(SC_HANDLE hService,SECURITY_INFORMATION dwSecurityInformation,PSECURITY_DESCRIPTOR lpSecurityDescriptor);
    321   WINADVAPI WINBOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus,LPSERVICE_STATUS lpServiceStatus);
    322   WINADVAPI WINBOOL WINAPI StartServiceCtrlDispatcherA(CONST SERVICE_TABLE_ENTRYA *lpServiceStartTable);
    323   WINADVAPI WINBOOL WINAPI StartServiceCtrlDispatcherW(CONST SERVICE_TABLE_ENTRYW *lpServiceStartTable);
    324   WINADVAPI WINBOOL WINAPI StartServiceA(SC_HANDLE hService,DWORD dwNumServiceArgs,LPCSTR *lpServiceArgVectors);
    325   WINADVAPI WINBOOL WINAPI StartServiceW(SC_HANDLE hService,DWORD dwNumServiceArgs,LPCWSTR *lpServiceArgVectors);
    326   WINADVAPI WINBOOL WINAPI UnlockServiceDatabase(SC_LOCK ScLock);
    327 
    328 #if (_WIN32_WINNT >= 0x0600)
    329 
    330 typedef VOID( CALLBACK * PFN_SC_NOTIFY_CALLBACK ) (
    331   PVOID pParameter
    332 );
    333 
    334 typedef struct _SERVICE_CONTROL_STATUS_REASON_PARAMSA {
    335   DWORD                  dwReason;
    336   LPSTR                  pszComment;
    337   SERVICE_STATUS_PROCESS ServiceStatus;
    338 } SERVICE_CONTROL_STATUS_REASON_PARAMSA, *PSERVICE_CONTROL_STATUS_REASON_PARAMSA;
    339 
    340 typedef struct _SERVICE_CONTROL_STATUS_REASON_PARAMSW {
    341   DWORD                  dwReason;
    342   LPWSTR                 pszComment;
    343   SERVICE_STATUS_PROCESS ServiceStatus;
    344 } SERVICE_CONTROL_STATUS_REASON_PARAMSW, *PSERVICE_CONTROL_STATUS_REASON_PARAMSW;
    345 
    346 __MINGW_TYPEDEF_AW(SERVICE_CONTROL_STATUS_REASON_PARAMS)
    347 __MINGW_TYPEDEF_AW(PSERVICE_CONTROL_STATUS_REASON_PARAMS)
    348 
    349 #define SERVICE_STOP_REASON_FLAG_CUSTOM 0x20000000
    350 #define SERVICE_STOP_REASON_FLAG_PLANNED 0x40000000
    351 #define SERVICE_STOP_REASON_FLAG_UNPLANNED 0x10000000
    352 
    353 #define SERVICE_STOP_REASON_MAJOR_APPLICATION 0x00050000
    354 #define SERVICE_STOP_REASON_MAJOR_HARDWARE 0x00020000
    355 #define SERVICE_STOP_REASON_MAJOR_NONE 0x00060000
    356 #define SERVICE_STOP_REASON_MAJOR_OPERATINGSYSTEM 0x00030000
    357 #define SERVICE_STOP_REASON_MAJOR_OTHER 0x00010000
    358 #define SERVICE_STOP_REASON_MAJOR_SOFTWARE 0x00040000
    359 
    360 #define SERVICE_STOP_REASON_MINOR_DISK 0x00000008
    361 #define SERVICE_STOP_REASON_MINOR_ENVIRONMENT 0x0000000a
    362 #define SERVICE_STOP_REASON_MINOR_HARDWARE_DRIVER 0x0000000b
    363 #define SERVICE_STOP_REASON_MINOR_HUNG 0x00000006
    364 #define SERVICE_STOP_REASON_MINOR_INSTALLATION 0x00000003
    365 #define SERVICE_STOP_REASON_MINOR_MAINTENANCE 0x00000002
    366 #define SERVICE_STOP_REASON_MINOR_MMC 0x00000016
    367 #define SERVICE_STOP_REASON_MINOR_NETWORK_CONNECTIVITY 0x00000011
    368 #define SERVICE_STOP_REASON_MINOR_NETWORKCARD 0x00000009
    369 #define SERVICE_STOP_REASON_MINOR_NONE 0x00060000
    370 #define SERVICE_STOP_REASON_MINOR_OTHER 0x00000001
    371 #define SERVICE_STOP_REASON_MINOR_OTHERDRIVER 0x0000000c
    372 #define SERVICE_STOP_REASON_MINOR_RECONFIG 0x00000005
    373 #define SERVICE_STOP_REASON_MINOR_SECURITY 0x00000010
    374 #define SERVICE_STOP_REASON_MINOR_SECURITYFIX 0x0000000f
    375 #define SERVICE_STOP_REASON_MINOR_SECURITYFIX_UNINSTALL 0x00000015
    376 #define SERVICE_STOP_REASON_MINOR_SERVICEPACK 0x0000000d
    377 #define SERVICE_STOP_REASON_MINOR_SERVICEPACK_UNINSTALL 0x00000013
    378 #define SERVICE_STOP_REASON_MINOR_SOFTWARE_UPDATE 0x0000000e
    379 #define SERVICE_STOP_REASON_MINOR_SOFTWARE_UPDATE_UNINSTALL 0x0000000e
    380 #define SERVICE_STOP_REASON_MINOR_UNSTABLE 0x00000007
    381 #define SERVICE_STOP_REASON_MINOR_UPGRADE 0x00000004
    382 #define SERVICE_STOP_REASON_MINOR_WMI 0x00000012
    383 
    384 typedef struct _SERVICE_NOTIFYA {
    385   DWORD                  dwVersion;
    386   PFN_SC_NOTIFY_CALLBACK pfnNotifyCallback;
    387   PVOID                  pContext;
    388   DWORD                  dwNotificationStatus;
    389   SERVICE_STATUS_PROCESS ServiceStatus;
    390   DWORD                  dwNotificationTriggered;
    391   LPSTR                  pszServiceNames;
    392 } SERVICE_NOTIFYA, *PSERVICE_NOTIFYA;
    393 
    394 typedef struct _SERVICE_NOTIFYW {
    395   DWORD                  dwVersion;
    396   PFN_SC_NOTIFY_CALLBACK pfnNotifyCallback;
    397   PVOID                  pContext;
    398   DWORD                  dwNotificationStatus;
    399   SERVICE_STATUS_PROCESS ServiceStatus;
    400   DWORD                  dwNotificationTriggered;
    401   LPWSTR                 pszServiceNames;
    402 } SERVICE_NOTIFYW, *PSERVICE_NOTIFYW;
    403 
    404 __MINGW_TYPEDEF_AW(SERVICE_NOTIFY)
    405 __MINGW_TYPEDEF_AW(PSERVICE_NOTIFY)
    406 
    407 #define SERVICE_CONFIG_DELAYED_AUTO_START_INFO 3
    408 #define SERVICE_CONFIG_FAILURE_ACTIONS_FLAG 4
    409 #define SERVICE_CONFIG_SERVICE_SID_INFO 5
    410 #define SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO 6
    411 #define SERVICE_CONFIG_PRESHUTDOWN_INFO 7
    412 
    413 typedef struct _SERVICE_DELAYED_AUTO_START_INFO {
    414   WINBOOL fDelayedAutostart;
    415 } SERVICE_DELAYED_AUTO_START_INFO, *LPSERVICE_DELAYED_AUTO_START_INFO;
    416 
    417 typedef struct _SERVICE_FAILURE_ACTIONS_FLAG {
    418   WINBOOL fFailureActionsOnNonCrashFailures;
    419 } SERVICE_FAILURE_ACTIONS_FLAG, *LPSERVICE_FAILURE_ACTIONS_FLAG;
    420 
    421 typedef struct _SERVICE_PRESHUTDOWN_INFO {
    422   DWORD dwPreshutdownTimeout;
    423 } SERVICE_PRESHUTDOWN_INFO, *LPSERVICE_PRESHUTDOWN_INFO;
    424 
    425 typedef struct _SERVICE_REQUIRED_PRIVILEGES_INFOA {
    426   LPSTR pmszRequiredPrivileges;
    427 } SERVICE_REQUIRED_PRIVILEGES_INFOA, *LPSERVICE_REQUIRED_PRIVILEGES_INFOA;
    428 
    429 typedef struct _SERVICE_REQUIRED_PRIVILEGES_INFOW {
    430   LPWSTR pmszRequiredPrivileges;
    431 } SERVICE_REQUIRED_PRIVILEGES_INFOW, *LPSERVICE_REQUIRED_PRIVILEGES_INFOW;
    432 
    433 __MINGW_TYPEDEF_AW(SERVICE_REQUIRED_PRIVILEGES_INFO)
    434 
    435 #define SERVICE_SID_TYPE_NONE 0x00000000
    436 #define SERVICE_SID_TYPE_RESTRICTED 0x00000003
    437 #define SERVICE_SID_TYPE_UNRESTRICTED 0x00000001
    438 
    439 typedef struct _SERVICE_SID_INFO {
    440   DWORD dwServiceSidType;
    441 } SERVICE_SID_INFO, *LPSERVICE_SID_INFO;
    442 
    443 WINADVAPI WINBOOL WINAPI ControlServiceExA(
    444   SC_HANDLE hService,
    445   DWORD dwControl,
    446   DWORD dwInfoLevel,
    447   PVOID pControlParams
    448 );
    449 
    450 WINADVAPI WINBOOL WINAPI ControlServiceExW(
    451   SC_HANDLE hService,
    452   DWORD dwControl,
    453   DWORD dwInfoLevel,
    454   PVOID pControlParams
    455 );
    456 
    457 #define ControlServiceEx __MINGW_NAME_AW(ControlServiceEx)
    458 
    459 #define NotifyServiceStatusChange __MINGW_NAME_AW(NotifyServiceStatusChange)
    460 
    461 DWORD WINAPI NotifyServiceStatusChangeA(
    462   SC_HANDLE hService,
    463   DWORD dwNotifyMask,
    464   PSERVICE_NOTIFYA pNotifyBuffer
    465 );
    466 
    467 DWORD WINAPI NotifyServiceStatusChangeW(
    468   SC_HANDLE hService,
    469   DWORD dwNotifyMask,
    470   PSERVICE_NOTIFYW pNotifyBuffer
    471 );
    472 
    473 #endif /*(_WIN32_WINNT >= 0x0600)*/
    474 
    475 #ifdef __cplusplus
    476 }
    477 #endif
    478 
    479 #endif /* _WINSVC_ */
    480