' ########################################################################################
' Microsoft Windows
' File: WinSvc.inc
' Contents: Header file for the Service Control Manager
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_WinSvc_PBI)
#DEFINE PBX_WinSvc_PBI
%EQUATE `WINSVC_INC = 1
#INCLUDE ONCE "Core/Windows.inc"
'//
'// Constants
'//
'//
'// Service database names
'//
$$SERVICES_ACTIVE_DATABASEW = "ServicesActive"$$
$$SERVICES_FAILED_DATABASEW = "ServicesFailed"$$
$SERVICES_ACTIVE_DATABASEA = "ServicesActive"
$SERVICES_FAILED_DATABASEA = "ServicesFailed"
'//
'// Character to designate that a name is a group
'//
$$SC_GROUP_IDENTIFIERW = "+"$$
$SC_GROUP_IDENTIFIERA = "+"
' // For compatibility with the PB declares
%EQUATE `SC_GROUP_IDENTIFIERW = &H002b ' "+"$$
%EQUATE `SC_GROUP_IDENTIFIERA = &H2b ' "+"
#IF %DEF(%UNICODE)
 MACRO SERVICES_ACTIVE_DATABASE = SERVICES_ACTIVE_DATABASEW
 MACRO SERVICES_FAILED_DATABASE = SERVICES_FAILED_DATABASEW
 %SC_GROUP_IDENTIFIER = %SC_GROUP_IDENTIFIERW
#ELSE ' NOT %DEF UNICODE
 MACRO SERVICES_ACTIVE_DATABASE = SERVICES_ACTIVE_DATABASEA
 MACRO SERVICES_FAILED_DATABASE = SERVICES_FAILED_DATABASEA
 %SC_GROUP_IDENTIFIER = %SC_GROUP_IDENTIFIERA
#ENDIF ' NOT %DEF UNICODE
'//
'// Value to indicate no change to an optional parameter
'//
%EQUATE `SERVICE_NO_CHANGE = &HFFFFFFFF
'//
'// Service State -- for Enum Requests (Bit Mask)
'//
%EQUATE `SERVICE_ACTIVE = &H00000001
%EQUATE `SERVICE_INACTIVE = &H00000002
%EQUATE `SERVICE_STATE_ALL = %SERVICE_ACTIVE OR %SERVICE_INACTIVE
'//
'// Controls
'//
%EQUATE `SERVICE_CONTROL_STOP = &H00000001
%EQUATE `SERVICE_CONTROL_PAUSE = &H00000002
%EQUATE `SERVICE_CONTROL_CONTINUE = &H00000003
%EQUATE `SERVICE_CONTROL_INTERROGATE = &H00000004
%EQUATE `SERVICE_CONTROL_SHUTDOWN = &H00000005
%EQUATE `SERVICE_CONTROL_PARAMCHANGE = &H00000006
%EQUATE `SERVICE_CONTROL_NETBINDADD = &H00000007
%EQUATE `SERVICE_CONTROL_NETBINDREMOVE = &H00000008
%EQUATE `SERVICE_CONTROL_NETBINDENABLE = &H00000009
%EQUATE `SERVICE_CONTROL_NETBINDDISABLE = &H0000000A
%EQUATE `SERVICE_CONTROL_DEVICEEVENT = &H0000000B
%EQUATE `SERVICE_CONTROL_HARDWAREPROFILECHANGE = &H0000000C
%EQUATE `SERVICE_CONTROL_POWEREVENT = &H0000000D
%EQUATE `SERVICE_CONTROL_SESSIONCHANGE = &H0000000E
%EQUATE `SERVICE_CONTROL_PRESHUTDOWN = &H0000000F
%EQUATE `SERVICE_CONTROL_TIMECHANGE = &H00000010
%EQUATE `SERVICE_CONTROL_TRIGGEREVENT = &H00000020
'//
'// Service State -- for CurrentState
'//
%EQUATE `SERVICE_STOPPED = &H00000001
%EQUATE `SERVICE_START_PENDING = &H00000002
%EQUATE `SERVICE_STOP_PENDING = &H00000003
%EQUATE `SERVICE_RUNNING = &H00000004
%EQUATE `SERVICE_CONTINUE_PENDING = &H00000005
%EQUATE `SERVICE_PAUSE_PENDING = &H00000006
%EQUATE `SERVICE_PAUSED = &H00000007
'//
'// Controls Accepted (Bit Mask)
'//
%EQUATE `SERVICE_ACCEPT_STOP = &H00000001
%EQUATE `SERVICE_ACCEPT_PAUSE_CONTINUE = &H00000002
%EQUATE `SERVICE_ACCEPT_SHUTDOWN = &H00000004
%EQUATE `SERVICE_ACCEPT_PARAMCHANGE = &H00000008
%EQUATE `SERVICE_ACCEPT_NETBINDCHANGE = &H00000010
%EQUATE `SERVICE_ACCEPT_HARDWAREPROFILECHANGE = &H00000020
%EQUATE `SERVICE_ACCEPT_POWEREVENT = &H00000040
%EQUATE `SERVICE_ACCEPT_SESSIONCHANGE = &H00000080
%EQUATE `SERVICE_ACCEPT_PRESHUTDOWN = &H00000100
%EQUATE `SERVICE_ACCEPT_TIMECHANGE = &H00000200
%EQUATE `SERVICE_ACCEPT_TRIGGEREVENT = &H00000400
'//
'// Service Control Manager object specific access types
'//
%EQUATE `SC_MANAGER_CONNECT = &H0001
%EQUATE `SC_MANAGER_CREATE_SERVICE = &H0002
%EQUATE `SC_MANAGER_ENUMERATE_SERVICE = &H0004
%EQUATE `SC_MANAGER_LOCK = &H0008
%EQUATE `SC_MANAGER_QUERY_LOCK_STATUS = &H0010
%EQUATE `SC_MANAGER_MODIFY_BOOT_CONFIG = &H0020
%EQUATE `SC_MANAGER_ALL_ACCESS = %STANDARD_RIGHTS_REQUIRED OR %SC_MANAGER_CONNECT OR %SC_MANAGER_CREATE_SERVICE OR %SC_MANAGER_ENUMERATE_SERVICE OR %SC_MANAGER_LOCK OR %SC_MANAGER_QUERY_LOCK_STATUS OR %SC_MANAGER_MODIFY_BOOT_CONFIG
'//
'// Service object specific access type
'//
%EQUATE `SERVICE_QUERY_CONFIG = &H0001
%EQUATE `SERVICE_CHANGE_CONFIG = &H0002
%EQUATE `SERVICE_QUERY_STATUS = &H0004
%EQUATE `SERVICE_ENUMERATE_DEPENDENTS = &H0008
%EQUATE `SERVICE_START = &H0010
%EQUATE `SERVICE_STOP = &H0020
%EQUATE `SERVICE_PAUSE_CONTINUE = &H0040
%EQUATE `SERVICE_INTERROGATE = &H0080
%EQUATE `SERVICE_USER_DEFINED_CONTROL = &H0100
%EQUATE `SERVICE_ALL_ACCESS = %STANDARD_RIGHTS_REQUIRED OR %SERVICE_QUERY_CONFIG OR %SERVICE_CHANGE_CONFIG OR %SERVICE_QUERY_STATUS OR %SERVICE_ENUMERATE_DEPENDENTS OR %SERVICE_START OR %SERVICE_STOP OR %SERVICE_PAUSE_CONTINUE OR %SERVICE_INTERROGATE OR %SERVICE_USER_DEFINED_CONTROL
'//
'// Service flags for QueryServiceStatusEx
'//
%EQUATE `SERVICE_RUNS_IN_SYSTEM_PROCESS = &H00000001
'//
'// Info levels for ChangeServiceConfig2 and QueryServiceConfig2
'//
%EQUATE `SERVICE_CONFIG_DESCRIPTION = 1
%EQUATE `SERVICE_CONFIG_FAILURE_ACTIONS = 2
%EQUATE `SERVICE_CONFIG_DELAYED_AUTO_START_INFO = 3
%EQUATE `SERVICE_CONFIG_FAILURE_ACTIONS_FLAG = 4
%EQUATE `SERVICE_CONFIG_SERVICE_SID_INFO = 5
%EQUATE `SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO = 6
%EQUATE `SERVICE_CONFIG_PRESHUTDOWN_INFO = 7
%EQUATE `SERVICE_CONFIG_TRIGGER_INFO = 8
%EQUATE `SERVICE_CONFIG_PREFERRED_NODE = 9
'// Info levels for NotifyServiceStatusChange
'//
%EQUATE `SERVICE_NOTIFY_STATUS_CHANGE_1 = 1
%EQUATE `SERVICE_NOTIFY_STATUS_CHANGE_2 = 2
%EQUATE `SERVICE_NOTIFY_STATUS_CHANGE = %SERVICE_NOTIFY_STATUS_CHANGE_2
'//
'// Service notification masks
'//
%EQUATE `SERVICE_NOTIFY_STOPPED = &H00000001
%EQUATE `SERVICE_NOTIFY_START_PENDING = &H00000002
%EQUATE `SERVICE_NOTIFY_STOP_PENDING = &H00000004
%EQUATE `SERVICE_NOTIFY_RUNNING = &H00000008
%EQUATE `SERVICE_NOTIFY_CONTINUE_PENDING = &H00000010
%EQUATE `SERVICE_NOTIFY_PAUSE_PENDING = &H00000020
%EQUATE `SERVICE_NOTIFY_PAUSED = &H00000040
%EQUATE `SERVICE_NOTIFY_CREATED = &H00000080
%EQUATE `SERVICE_NOTIFY_DELETED = &H00000100
%EQUATE `SERVICE_NOTIFY_DELETE_PENDING = &H00000200
'//
'// The following defines are for service stop reason codes
'//
'//
'// Stop reason flags. Update SERVICE_STOP_REASON_FLAG_MAX when
'// new flags are added.
'//
%EQUATE `SERVICE_STOP_REASON_FLAG_MIN = &H00000000
%EQUATE `SERVICE_STOP_REASON_FLAG_UNPLANNED = &H10000000
%EQUATE `SERVICE_STOP_REASON_FLAG_CUSTOM = &H20000000
%EQUATE `SERVICE_STOP_REASON_FLAG_PLANNED = &H40000000
%EQUATE `SERVICE_STOP_REASON_FLAG_MAX = &H80000000
'//
'// Microsoft major reasons. Update SERVICE_STOP_REASON_MAJOR_MAX when
'// new codes are added.
'//
%EQUATE `SERVICE_STOP_REASON_MAJOR_MIN = &H00000000
%EQUATE `SERVICE_STOP_REASON_MAJOR_OTHER = &H00010000
%EQUATE `SERVICE_STOP_REASON_MAJOR_HARDWARE = &H00020000
%EQUATE `SERVICE_STOP_REASON_MAJOR_OPERATINGSYSTEM = &H00030000
%EQUATE `SERVICE_STOP_REASON_MAJOR_SOFTWARE = &H00040000
%EQUATE `SERVICE_STOP_REASON_MAJOR_APPLICATION = &H00050000
%EQUATE `SERVICE_STOP_REASON_MAJOR_NONE = &H00060000
%EQUATE `SERVICE_STOP_REASON_MAJOR_MAX = &H00070000
%EQUATE `SERVICE_STOP_REASON_MAJOR_MIN_CUSTOM = &H00400000
%EQUATE `SERVICE_STOP_REASON_MAJOR_MAX_CUSTOM = &H00ff0000
'//
'// Microsoft minor reasons. Update SERVICE_STOP_REASON_MINOR_MAX when
'// new codes are added.
'//
%EQUATE `SERVICE_STOP_REASON_MINOR_MIN = &H00000000
%EQUATE `SERVICE_STOP_REASON_MINOR_OTHER = &H00000001
%EQUATE `SERVICE_STOP_REASON_MINOR_MAINTENANCE = &H00000002
%EQUATE `SERVICE_STOP_REASON_MINOR_INSTALLATION = &H00000003
%EQUATE `SERVICE_STOP_REASON_MINOR_UPGRADE = &H00000004
%EQUATE `SERVICE_STOP_REASON_MINOR_RECONFIG = &H00000005
%EQUATE `SERVICE_STOP_REASON_MINOR_HUNG = &H00000006
%EQUATE `SERVICE_STOP_REASON_MINOR_UNSTABLE = &H00000007
%EQUATE `SERVICE_STOP_REASON_MINOR_DISK = &H00000008
%EQUATE `SERVICE_STOP_REASON_MINOR_NETWORKCARD = &H00000009
%EQUATE `SERVICE_STOP_REASON_MINOR_ENVIRONMENT = &H0000000a
%EQUATE `SERVICE_STOP_REASON_MINOR_HARDWARE_DRIVER = &H0000000b
%EQUATE `SERVICE_STOP_REASON_MINOR_OTHERDRIVER = &H0000000c
%EQUATE `SERVICE_STOP_REASON_MINOR_SERVICEPACK = &H0000000d
%EQUATE `SERVICE_STOP_REASON_MINOR_SOFTWARE_UPDATE = &H0000000e
%EQUATE `SERVICE_STOP_REASON_MINOR_SECURITYFIX = &H0000000f
%EQUATE `SERVICE_STOP_REASON_MINOR_SECURITY = &H00000010
%EQUATE `SERVICE_STOP_REASON_MINOR_NETWORK_CONNECTIVITY = &H00000011
%EQUATE `SERVICE_STOP_REASON_MINOR_WMI = &H00000012
%EQUATE `SERVICE_STOP_REASON_MINOR_SERVICEPACK_UNINSTALL = &H00000013
%EQUATE `SERVICE_STOP_REASON_MINOR_SOFTWARE_UPDATE_UNINSTALL = &H00000014
%EQUATE `SERVICE_STOP_REASON_MINOR_SECURITYFIX_UNINSTALL = &H00000015
%EQUATE `SERVICE_STOP_REASON_MINOR_MMC = &H00000016
%EQUATE `SERVICE_STOP_REASON_MINOR_NONE = &H00000017
%EQUATE `SERVICE_STOP_REASON_MINOR_MAX = &H00000018
%EQUATE `SERVICE_STOP_REASON_MINOR_MIN_CUSTOM = &H00000100
%EQUATE `SERVICE_STOP_REASON_MINOR_MAX_CUSTOM = &H0000FFFF
'//
'// Info levels for ControlServiceEx
'//
%EQUATE `SERVICE_CONTROL_STATUS_REASON_INFO = 1
'//
'// Service SID types supported
'//
%EQUATE `SERVICE_SID_TYPE_NONE = &H00000000
%EQUATE `SERVICE_SID_TYPE_UNRESTRICTED = &H00000001
%EQUATE `SERVICE_SID_TYPE_RESTRICTED = &H00000002 OR %SERVICE_SID_TYPE_UNRESTRICTED
'//
'// Service trigger types
'//
%EQUATE `SERVICE_TRIGGER_TYPE_DEVICE_INTERFACE_ARRIVAL = 1
%EQUATE `SERVICE_TRIGGER_TYPE_IP_ADDRESS_AVAILABILITY = 2
%EQUATE `SERVICE_TRIGGER_TYPE_DOMAIN_JOIN = 3
%EQUATE `SERVICE_TRIGGER_TYPE_FIREWALL_PORT_EVENT = 4
%EQUATE `SERVICE_TRIGGER_TYPE_GROUP_POLICY = 5
%EQUATE `SERVICE_TRIGGER_TYPE_CUSTOM = 20
'//
'// Service trigger data types
'//
%EQUATE `SERVICE_TRIGGER_DATA_TYPE_BINARY = 1
%EQUATE `SERVICE_TRIGGER_DATA_TYPE_STRING = 2
'//
'// NETWORK_MANAGER_FIRST_IP_ADDRESS_ARRIVAL_GUID & NETWORK_MANAGER_LAST_IP_ADDRESS_REMOVAL_GUID are used with
'// SERVICE_TRIGGER_TYPE_IP_ADDRESS_AVAILABILITY trigger.
'//
$NETWORK_MANAGER_FIRST_IP_ADDRESS_ARRIVAL_GUID = GUID$("{4f27f2de-14e2-430b-a549-7cd48cbc8245}")
$NETWORK_MANAGER_LAST_IP_ADDRESS_REMOVAL_GUID = GUID$("{cc4ba62a-162e-4648-847a-b6bdf993e335}")
'//
'// DOMAIN_JOIN_GUID & DOMAIN_LEAVE_GUID are used with SERVICE_TRIGGER_TYPE_DOMAIN_JOIN trigger.
'//
$DOMAIN_JOIN_GUID = GUID$("{1ce20aba-9851-4421-9430-1ddeb766e809}")
$DOMAIN_LEAVE_GUID = GUID$("{ddaf516e-58c2-4866-9574-c3b615d42ea1}")
'//
'// FIREWALL_PORT_OPEN_GUID & FIREWALL_PORT_CLOSE_GUID are used with
'// SERVICE_TRIGGER_TYPE_FIREWALL_PORT_EVENT trigger.
'//
$FIREWALL_PORT_OPEN_GUID = GUID$("{b7569e07-8421-4ee0-ad10-86915afdad09}")
$FIREWALL_PORT_CLOSE_GUID = GUID$("{a144ed38-8e12-4de4-9d96-e64740b1a524}")
'//
'// MACHINE_POLICY_PRESENT_GUID & USER_POLICY_PRESENT_GUID are used with
'// SERVICE_TRIGGER_TYPE_GROUP_POLICY trigger.
'//
$MACHINE_POLICY_PRESENT_GUID = GUID$("{659FCAE6-5BDB-4DA9-B1FF-CA2A178D46E0}")
$USER_POLICY_PRESENT_GUID = GUID$("{54FB46C8-F089-464C-B1FD-59D1B62C3B50}")
'//
'// Service trigger actions
'//
%EQUATE `SERVICE_TRIGGER_ACTION_SERVICE_START = 1
%EQUATE `SERVICE_TRIGGER_ACTION_SERVICE_STOP = 2
'//
'// argv[1] passed into ServiceMain of trigger started services
'//
$$SERVICE_TRIGGER_STARTED_ARGUMENT = "TriggerStarted"$$
'//
'// Service description string
'//
' // Size = 4 bytes
TYPE SERVICE_DESCRIPTIONA DWORD
 lpDescription AS ASCIIZ PTR
END TYPE
'//
'// Service description string
'//
' // Size = 4 bytes
TYPE SERVICE_DESCRIPTIONW DWORD
 lpDescription AS WSTRINGZ PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_DESCRIPTION = SERVICE_DESCRIPTIONW
#ELSE
 MACRO SERVICE_DESCRIPTION = SERVICE_DESCRIPTIONA
#ENDIF
'//
'// Actions to take on service failure
'//
' SC_ACTION_TYPE enum
%EQUATE `SC_ACTION_NONE = 0
%EQUATE `SC_ACTION_RESTART = 1
%EQUATE `SC_ACTION_REBOOT = 2
%EQUATE `SC_ACTION_RUN_COMMAND = 3
UNION SC_ACTION_TYPE_UNION DWORD
 Type AS LONG ' SC_ACTION_TYPE
 ' // For compatibility with the PB declares
 aType AS LONG ' SC_ACTION_TYPE
END UNION
' // Size = 8 bytes
TYPE SC_ACTION DWORD
 SC_ACTION_TYPE_UNION
 Delay AS DWORD
END TYPE
' // Size = 20 bytes
TYPE SERVICE_FAILURE_ACTIONSA DWORD
 dwResetPeriod AS DWORD
 lpRebootMsg AS ASCIIZ PTR
 lpCommand AS ASCIIZ PTR
 cActions AS DWORD
 lpsaActions AS SC_ACTION PTR ' SC_ACTION*
END TYPE
' // Size = 20 bytes
TYPE SERVICE_FAILURE_ACTIONSW DWORD
 dwResetPeriod AS DWORD
 lpRebootMsg AS WSTRINGZ PTR
 lpCommand AS WSTRINGZ PTR
 cActions AS DWORD
 lpsaActions AS SC_ACTION PTR ' SC_ACTION*
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_FAILURE_ACTIONS = SERVICE_FAILURE_ACTIONSW
#ELSE
 MACRO SERVICE_FAILURE_ACTIONS = SERVICE_FAILURE_ACTIONSA
#ENDIF
'//
'// Service delayed autostart info setting
'//
' // Size = 4 bytes
TYPE SERVICE_DELAYED_AUTO_START_INFO DWORD
 fDelayedAutostart AS LONG ' BOOL // Delayed autostart flag
END TYPE
'//
'// Service failure actions flag setting
'//
' // Size = 4 bytes
TYPE SERVICE_FAILURE_ACTIONS_FLAG DWORD
 fFailureActionsOnNonCrashFailures AS LONG ' BOOL // Failure actions flag
END TYPE
'//
'// Service SID info setting
'//
' // Size = 4 bytes
TYPE SERVICE_SID_INFO DWORD
 dwServiceSidType AS DWORD ' DWORD // Service SID type
END TYPE
'//
'// Service required privileges information
'//
' // Size = 4 bytes
TYPE SERVICE_REQUIRED_PRIVILEGES_INFOA DWORD
 pmszRequiredPrivileges AS ASCIIZ PTR ' LPSTR // Required privileges multi-sz
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_REQUIRED_PRIVILEGES_INFO = SERVICE_REQUIRED_PRIVILEGES_INFOW
#ELSE
 MACRO SERVICE_REQUIRED_PRIVILEGES_INFO = SERVICE_REQUIRED_PRIVILEGES_INFOA
#ENDIF
'//
'// Service required privileges information
'//
' // Size = 4 bytes
TYPE SERVICE_REQUIRED_PRIVILEGES_INFOW DWORD
 pmszRequiredPrivileges AS WSTRINGZ PTR ' LPWSTR // Required privileges multi-sz
END TYPE
'//
'// Service preshutdown timeout setting
'//
' // Size = 4 bytes
TYPE SERVICE_PRESHUTDOWN_INFO DWORD
 dwPreshutdownTimeout AS DWORD ' DWORD // Timeout in msecs
END TYPE
'//
'// Service trigger data item
'//
' // Size = 12 bytes
TYPE SERVICE_TRIGGER_SPECIFIC_DATA_ITEM DWORD
 dwDataType AS DWORD ' DWORD // Data type -- one of SERVICE_TRIGGER_DATA_TYPE_* constants
 cbData AS DWORD ' DWORD // Size of trigger specific data
 pData AS BYTE PTR ' PBYTE // Trigger specific data
END TYPE
'//
'// Trigger-specific information
'//
' // Size = 20 bytes
TYPE SERVICE_TRIGGER DWORD
 dwTriggerType AS DWORD ' DWORD // One of SERVICE_TRIGGER_TYPE_* constants
 dwAction AS DWORD ' DWORD // One of SERVICE_TRIGGER_ACTION_* constants
 pTriggerSubtype AS GUID PTR ' GUID* // Provider GUID if the trigger type is SERVICE_TRIGGER_TYPE_CUSTOM
 ' // Device class interface GUID if the trigger type is
 ' // SERVICE_TRIGGER_TYPE_DEVICE_INTERFACE_ARRIVAL
 cDataItems AS DWORD ' DWORD // Number of data items in pDataItems array
 pDataItems AS SERVICE_TRIGGER_SPECIFIC_DATA_ITEM PTR ' PSERVICE_TRIGGER_SPECIFIC_DATA_ITEM // Trigger specific data
END TYPE
'//
'// Service trigger information
'//
' // Size = 12 bytes
TYPE SERVICE_TRIGGER_INFO DWORD
 cTriggers AS DWORD ' DWORD // Number of triggers in the pTriggers array
 pTriggers AS SERVICE_TRIGGER PTR ' PSERVICE_TRIGGER // Array of triggers
 pReserved AS BYTE PTR ' PBYTE // Reserved, must be NULL
END TYPE
'//
'// Preferred node information
'//
' // Size = 4 bytes
TYPE SERVICE_PREFERRED_NODE_INFO WORD
 usPreferredNode AS WORD ' USHORT // Preferred node
 fDelete AS BYTE ' BOOLEAN // Delete the preferred node setting
END TYPE
'//
'// Time change information
'//
' // Size = 16 bytes
TYPE SERVICE_TIMECHANGE_INFO QWORD
 liNewTime AS QUAD ' LARGE_INTEGER // New time
 liOldTime AS QUAD ' LARGE_INTEGER // Old time
END TYPE
'//
'// Handle Types
'//
'DECLARE_HANDLE(SC_HANDLE);
'typedef SC_HANDLE *LPSC_HANDLE;
'DECLARE_HANDLE(SERVICE_STATUS_HANDLE);
'//
'// Info levels for QueryServiceStatusEx
'//
' SC_STATUS_TYPE enum
%EQUATE `SC_STATUS_PROCESS_INFO = 0
'//
'// Info levels for EnumServicesStatusEx
'//
' SC_ENUM_TYPE enum
%EQUATE `SC_ENUM_PROCESS_INFO = 0
'//
'// Service Status Structures
'//
' // Size = 28 bytes
TYPE SERVICE_STATUS DWORD
 dwServiceType AS DWORD
 dwCurrentState AS DWORD
 dwControlsAccepted AS DWORD
 dwWin32ExitCode AS DWORD
 dwServiceSpecificExitCode AS DWORD
 dwCheckPoint AS DWORD
 dwWaitHint AS DWORD
END TYPE
' // For compatibility with the PB declares
MACRO SERVICE_STATUS_TYPE = SERVICE_STATUS
' // Size = 36 bytes
TYPE SERVICE_STATUS_PROCESS DWORD
 dwServiceType AS DWORD
 dwCurrentState AS DWORD
 dwControlsAccepted AS DWORD
 dwWin32ExitCode AS DWORD
 dwServiceSpecificExitCode AS DWORD
 dwCheckPoint AS DWORD
 dwWaitHint AS DWORD
 dwProcessId AS DWORD
 dwServiceFlags AS DWORD
END TYPE
' // For compatibility with the PB declares
MACRO SERVICE_STATUS_PROCESS_TYPE = SERVICE_STATUS_PROCESS
'//
'// Service Status Enumeration Structure
'//
' // Size = 36 bytes
TYPE ENUM_SERVICE_STATUSA DWORD
 lpServiceName AS ASCIIZ PTR
 lpDisplayName AS ASCIIZ PTR
 ServiceStatus AS SERVICE_STATUS ' SERVICE_STATUS
END TYPE
' // Size = 36 bytes
TYPE ENUM_SERVICE_STATUSW DWORD
 lpServiceName AS WSTRINGZ PTR
 lpDisplayName AS WSTRINGZ PTR
 ServiceStatus AS SERVICE_STATUS ' SERVICE_STATUS
END TYPE
#IF %DEF(%UNICODE)
 MACRO ENUM_SERVICE_STATUS = ENUM_SERVICE_STATUSW
#ELSE
 MACRO ENUM_SERVICE_STATUS = ENUM_SERVICE_STATUSA
#ENDIF
' // Size = 44 bytes
TYPE ENUM_SERVICE_STATUS_PROCESSA DWORD
 lpServiceName AS ASCIIZ PTR
 lpDisplayName AS ASCIIZ PTR
 ServiceStatusProcess AS SERVICE_STATUS_PROCESS ' SERVICE_STATUS_PROCESS
END TYPE
' // Size = 44 bytes
TYPE ENUM_SERVICE_STATUS_PROCESSW DWORD
 lpServiceName AS WSTRINGZ PTR
 lpDisplayName AS WSTRINGZ PTR
 ServiceStatusProcess AS SERVICE_STATUS_PROCESS ' SERVICE_STATUS_PROCESS
END TYPE
#IF %DEF(%UNICODE)
 MACRO ENUM_SERVICE_STATUS_PROCESS = ENUM_SERVICE_STATUS_PROCESSW
#ELSE
 MACRO ENUM_SERVICE_STATUS_PROCESS = ENUM_SERVICE_STATUS_PROCESSA
#ENDIF
'//
'// Structures for the Lock API functions
'//
'typedef LPVOID SC_LOCK;
' // Size = 12 bytes
TYPE QUERY_SERVICE_LOCK_STATUSA DWORD
 fIsLocked AS DWORD
 lpLockOwner AS ASCIIZ PTR
 dwLockDuration AS DWORD
END TYPE
' // Size = 12 bytes
TYPE QUERY_SERVICE_LOCK_STATUSW DWORD
 fIsLocked AS DWORD
 lpLockOwner AS WSTRINGZ PTR
 dwLockDuration AS DWORD
END TYPE
#IF %DEF(%UNICODE)
 MACRO QUERY_SERVICE_LOCK_STATUS = QUERY_SERVICE_LOCK_STATUSW
#ELSE
 MACRO QUERY_SERVICE_LOCK_STATUS = QUERY_SERVICE_LOCK_STATUSA
#ENDIF
'//
'// Query Service Configuration Structure
'//
' // Size = 36 bytes
TYPE QUERY_SERVICE_CONFIGA DWORD
 dwServiceType AS DWORD
 dwStartType AS DWORD
 dwErrorControl AS DWORD
 lpBinaryPathName AS ASCIIZ PTR
 lpLoadOrderGroup AS ASCIIZ PTR
 dwTagId AS DWORD
 lpDependencies AS ASCIIZ PTR
 lpServiceStartName AS ASCIIZ PTR
 lpDisplayName AS ASCIIZ PTR
END TYPE
' // Size = 36 bytes
TYPE QUERY_SERVICE_CONFIGW DWORD
 dwServiceType AS DWORD
 dwStartType AS DWORD
 dwErrorControl AS DWORD
 lpBinaryPathName AS WSTRINGZ PTR
 lpLoadOrderGroup AS WSTRINGZ PTR
 dwTagId AS DWORD
 lpDependencies AS WSTRINGZ PTR
 lpServiceStartName AS WSTRINGZ PTR
 lpDisplayName AS WSTRINGZ PTR
END TYPE
#IF %DEF(%UNICODE)
 MACRO QUERY_SERVICE_CONFIG = QUERY_SERVICE_CONFIGW
#ELSE
 MACRO QUERY_SERVICE_CONFIG = QUERY_SERVICE_CONFIGA
#ENDIF
'//
'// Function Prototype for the Service Main Function
'//
'typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONW)(
' DWORD dwNumServicesArgs,
' LPWSTR *lpServiceArgVectors
' );
'typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONA)(
' DWORD dwNumServicesArgs,
' LPSTR *lpServiceArgVectors
' );
'//
'// Service Start Table
'//
' // Size = 8 bytes
TYPE SERVICE_TABLE_ENTRYA DWORD
 lpServiceName AS ASCIIZ PTR
 lpServiceProc AS LONG ' LPSERVICE_MAIN_FUNCTIONA
END TYPE
' // Size = 8 bytes
TYPE SERVICE_TABLE_ENTRYW DWORD
 lpServiceName AS WSTRINGZ PTR
 lpServiceProc AS LONG ' LPSERVICE_MAIN_FUNCTIONW
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_TABLE_ENTRY = SERVICE_TABLE_ENTRYW
#ELSE
 MACRO SERVICE_TABLE_ENTRY = SERVICE_TABLE_ENTRYA
#ENDIF
'//
'// Prototype for the Service Control Handler Function
'//
'typedef VOID (WINAPI *LPHANDLER_FUNCTION)(
' DWORD dwControl
' );
'typedef DWORD (WINAPI *LPHANDLER_FUNCTION_EX)(
' DWORD dwControl,
' DWORD dwEventType,
' LPVOID lpEventData,
' LPVOID lpContext
' );
'//
'// Service notification parameters
'//
'typedef
'( CALLBACK * PFN_SC_NOTIFY_CALLBACK ) (
' IN PVOID pParameter
' );
'//
'// Each new notify structure is a superset of the older version
'//
' // Size = 52 bytes
TYPE SERVICE_NOTIFY_1 DWORD
 dwVersion AS DWORD
 pfnNotifyCallback AS DWORD ' PFN_SC_NOTIFY_CALLBACK
 pContext AS DWORD
 dwNotificationStatus AS DWORD
 ServiceStatus AS SERVICE_STATUS_PROCESS
END TYPE
' // Size = 60 bytes
TYPE SERVICE_NOTIFY_2A DWORD
 dwVersion AS DWORD
 pfnNotifyCallback AS DWORD ' PFN_SC_NOTIFY_CALLBACK
 pContext AS DWORD
 dwNotificationStatus AS DWORD
 ServiceStatus AS SERVICE_STATUS_PROCESS
 dwNotificationTriggered AS DWORD
 pszServiceNames AS ASCIIZ PTR
END TYPE
' // Size = 60 bytes
TYPE SERVICE_NOTIFY_2W DWORD
 dwVersion AS DWORD
 pfnNotifyCallback AS DWORD ' PFN_SC_NOTIFY_CALLBACK
 pContext AS DWORD
 dwNotificationStatus AS DWORD
 ServiceStatus AS SERVICE_STATUS_PROCESS
 dwNotificationTriggered AS DWORD
 pszServiceNames AS WSTRINGZ PTR
END TYPE
MACRO SERVICE_NOTIFYA = SERVICE_NOTIFY_2A
MACRO SERVICE_NOTIFYW = SERVICE_NOTIFY_2W
#IF %DEF(%UNICODE)
 MACRO SERVICE_NOTIFY_2 = SERVICE_NOTIFY_2W
#ELSE
 MACRO SERVICE_NOTIFY_2 = SERVICE_NOTIFY_2A
#ENDIF
'//
'// Service control status reason parameters
'//
' // Size = 44 bytes
TYPE SERVICE_CONTROL_STATUS_REASON_PARAMSA DWORD
 dwReason AS DWORD
 pszComment AS ASCIIZ PTR
 ServiceStatus AS SERVICE_STATUS_PROCESS
END TYPE
'//
'// Service control status reason parameters
'//
' // Size = 44 bytes
TYPE SERVICE_CONTROL_STATUS_REASON_PARAMSW DWORD
 dwReason AS DWORD
 pszComment AS WSTRINGZ PTR
 ServiceStatus AS SERVICE_STATUS_PROCESS
END TYPE
#IF %DEF(%UNICODE)
 MACRO SERVICE_CONTROL_STATUS_REASON_PARAMS = SERVICE_CONTROL_STATUS_REASON_PARAMSW
#ELSE
 MACRO SERVICE_CONTROL_STATUS_REASON_PARAMS = SERVICE_CONTROL_STATUS_REASON_PARAMSA
#ENDIF
'///////////////////////////////////////////////////////////////////////////
'// API Function Prototypes
'///////////////////////////////////////////////////////////////////////////
DECLARE FUNCTION ChangeServiceConfigA LIB "advapi32.dll" ALIAS "ChangeServiceConfigA" ( BYVAL hService AS QUAD , BYVAL dwServiceType AS QUAD , BYVAL dwStartType AS QUAD , BYVAL dwErrorControl AS QUAD , OPTIONAL BYREF lpBinaryPathName AS ASCIIZ , OPTIONAL BYREF lpLoadOrderGroup AS ASCIIZ , OPTIONAL BYREF lpdwTagId AS QUAD , OPTIONAL BYREF lpDependencies AS ASCIIZ , OPTIONAL BYREF lpServiceStartName AS ASCIIZ , OPTIONAL BYREF lpPassword AS ASCIIZ , OPTIONAL BYREF lpDisplayName AS ASCIIZ ) AS LONG
DECLARE FUNCTION ChangeServiceConfigW LIB "advapi32.dll" ALIAS "ChangeServiceConfigW" ( BYVAL hService AS QUAD
 , BYVAL dwServiceType AS DWORD
 , BYVAL dwStartType AS DWORD
 , BYVAL dwErrorControl AS DWORD
 , OPTIONAL BYREF lpBinaryPathName AS WSTRINGZ
 , OPTIONAL BYREF lpLoadOrderGroup AS WSTRINGZ
 , OPTIONAL BYREF lpdwTagId AS DWORD
 , OPTIONAL BYREF lpDependencies AS WSTRINGZ
 , OPTIONAL BYREF lpServiceStartName AS WSTRINGZ
 , OPTIONAL BYREF lpPassword AS WSTRINGZ
 , OPTIONAL BYREF lpDisplayName AS WSTRINGZ
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO ChangeServiceConfig = ChangeServiceConfigW
#ELSE
 MACRO ChangeServiceConfig = ChangeServiceConfigA
#ENDIF
DECLARE FUNCTION ChangeServiceConfig2A LIB "advapi32.dll" ALIAS "ChangeServiceConfig2A" ( BYVAL hService AS QUAD , BYVAL dwInfoLevel AS QUAD , OPTIONAL BYVAL lpInfo AS QUAD ) AS LONG
DECLARE FUNCTION ChangeServiceConfig2W LIB "advapi32.dll" ALIAS "ChangeServiceConfig2W" ( BYVAL hService AS QUAD
 , BYVAL dwInfoLevel AS DWORD
 , OPTIONAL BYVAL lpInfo AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO ChangeServiceConfig2 = ChangeServiceConfig2W
#ELSE
 MACRO ChangeServiceConfig2 = ChangeServiceConfig2A
#ENDIF
DECLARE FUNCTION CloseServiceHandle LIB "advapi32.dll" ALIAS "CloseServiceHandle" ( BYVAL hSCObject AS QUAD ) AS LONG
DECLARE FUNCTION ControlService LIB "advapi32.dll" ALIAS "ControlService" ( BYVAL hService AS QUAD
 , BYVAL dwControl AS DWORD
 , BYREF lpServiceStatus AS SERVICE_STATUS
 ) AS LONG
DECLARE FUNCTION CreateServiceA LIB "advapi32.dll" ALIAS "CreateServiceA" ( BYVAL hSCManager AS DWORD
 , BYREF lpServiceName AS ASCIIZ
 , BYREF lpDisplayName AS ASCIIZ
 , BYVAL dwDesiredAccess AS DWORD
 , BYVAL dwServiceType AS DWORD
 , BYVAL dwStartType AS DWORD
 , BYVAL dwErrorControl AS DWORD
 , OPTIONAL BYREF lpBinaryPathName AS ASCIIZ
 , OPTIONAL BYREF lpLoadOrderGroup AS ASCIIZ
 , OPTIONAL BYREF lpdwTagId AS DWORD
 , OPTIONAL BYREF lpDependencies AS ASCIIZ
 , OPTIONAL BYREF lpServiceStartName AS ASCIIZ
 , OPTIONAL BYREF lpPassword AS ASCIIZ
 ) AS DWORD ' SC_HANDLE
DECLARE FUNCTION CreateServiceW LIB "advapi32.dll" ALIAS "CreateServiceW" ( BYVAL hSCManager AS QUAD , BYREF lpServiceName AS WSTRINGZ , BYREF lpDisplayName AS WSTRINGZ , BYVAL dwDesiredAccess AS QUAD , BYVAL dwServiceType AS QUAD , BYVAL dwStartType AS QUAD , BYVAL dwErrorControl AS QUAD , OPTIONAL BYREF lpBinaryPathName AS WSTRINGZ , OPTIONAL BYREF lpLoadOrderGroup AS WSTRINGZ , OPTIONAL BYREF lpdwTagId AS QUAD , OPTIONAL BYREF lpDependencies AS WSTRINGZ , OPTIONAL BYREF lpServiceStartName AS WSTRINGZ , OPTIONAL BYREF lpPassword AS WSTRINGZ ) AS QUAD ' SC_HANDLE
#IF %DEF(%UNICODE)
 MACRO CreateService = CreateServiceW
#ELSE
 MACRO CreateService = CreateServiceA
#ENDIF
DECLARE FUNCTION DeleteService LIB "advapi32.dll" ALIAS "DeleteService" ( BYVAL hService AS QUAD ) AS LONG
DECLARE FUNCTION EnumDependentServicesA LIB "advapi32.dll" ALIAS "EnumDependentServicesA" ( BYVAL hService AS QUAD
 , BYVAL dwServiceState AS DWORD
 , BYREF lpServices AS ANY
 , BYVAL cbBufSize AS DWORD
 , BYREF pcbBytesNeeded AS DWORD
 , BYREF lpServicesReturned AS DWORD
 ) AS LONG
DECLARE FUNCTION EnumDependentServicesW LIB "advapi32.dll" ALIAS "EnumDependentServicesW" ( BYVAL hService AS DWORD
 , BYVAL dwServiceState AS DWORD
 , BYREF lpServices AS ANY
 , BYVAL cbBufSize AS DWORD
 , BYREF pcbBytesNeeded AS DWORD
 , BYREF lpServicesReturned AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO EnumDependentServices = EnumDependentServicesW
#ELSE
 MACRO EnumDependentServices = EnumDependentServicesA
#ENDIF
DECLARE FUNCTION EnumServicesStatusA LIB "advapi32.dll" ALIAS "EnumServicesStatusA" ( BYVAL hSCManager AS QUAD , BYVAL dwServiceType AS QUAD , BYVAL dwServiceState AS QUAD , BYREF lpServices AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD , BYREF lpServicesReturned AS QUAD , OPTIONAL BYREF lpResumeHandle AS QUAD ) AS LONG
DECLARE FUNCTION EnumServicesStatusW LIB "advapi32.dll" ALIAS "EnumServicesStatusW" ( BYVAL hSCManager AS QUAD
 , BYVAL dwServiceType AS DWORD
 , BYVAL dwServiceState AS DWORD
 , BYREF lpServices AS ANY
 , BYVAL cbBufSize AS DWORD
 , BYREF pcbBytesNeeded AS DWORD
 , BYREF lpServicesReturned AS DWORD
 , OPTIONAL BYREF lpResumeHandle AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO EnumServicesStatus = EnumServicesStatusW
#ELSE
 MACRO EnumServicesStatus = EnumServicesStatusA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION EnumServicesStatusExA LIB "AdvApi32.dll" ALIAS "EnumServicesStatusExA" ( BYVAL hSCManager AS QUAD, BYVAL InfoLevel AS LONG, ' SC_ENUM_TYPE
 BYVAL dwServiceType AS DWORD, BYVAL dwServiceState AS DWORD, BYVAL lpServices AS BYTE PTR, BYVAL cbBufSize AS DWORD, pcbBytesNeeded AS DWORD, lpServicesReturned AS DWORD, lpResumeHandle AS DWORD, pszGroupName AS ASCIIZ ) AS LONG
#ELSE
DECLARE FUNCTION EnumServicesStatusExA LIB "advapi32.dll" ALIAS "EnumServicesStatusExA" ( BYVAL hSCManager AS QUAD , BYVAL InfoLevel AS LONG , BYVAL dwServiceType AS QUAD , BYVAL dwServiceState AS QUAD , BYREF lpServices AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD , BYREF lpServicesReturned AS QUAD , OPTIONAL BYREF lpResumeHandle AS QUAD , OPTIONAL BYREF pszGroupName AS ASCIIZ ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION EnumServicesStatusExW LIB "AdvApi32.dll" ALIAS "EnumServicesStatusExW" ( BYVAL hSCManager AS QUAD, BYVAL InfoLevel AS LONG, ' SC_ENUM_TYPE
 BYVAL dwServiceType AS DWORD, BYVAL dwServiceState AS DWORD, BYVAL lpServices AS BYTE PTR, BYVAL cbBufSize AS DWORD, pcbBytesNeeded AS DWORD, lpServicesReturned AS DWORD, lpResumeHandle AS DWORD, pszGroupName AS WSTRINGZ ) AS LONG
#ELSE
DECLARE FUNCTION EnumServicesStatusExW LIB "advapi32.dll" ALIAS "EnumServicesStatusExW" ( BYVAL hSCManager AS QUAD , BYVAL InfoLevel AS LONG , BYVAL dwServiceType AS QUAD , BYVAL dwServiceState AS QUAD , BYREF lpServices AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD , BYREF lpServicesReturned AS QUAD , OPTIONAL BYREF lpResumeHandle AS QUAD , OPTIONAL BYREF pszGroupName AS WSTRINGZ ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO EnumServicesStatusEx = EnumServicesStatusExW
#ELSE
 MACRO EnumServicesStatusEx = EnumServicesStatusExA
#ENDIF
DECLARE FUNCTION GetServiceKeyNameA LIB "advapi32.dll" ALIAS "GetServiceKeyNameA" ( BYVAL hSCManager AS QUAD , BYREF lpDisplayName AS ASCIIZ , BYREF lpServiceName AS ASCIIZ , BYREF lpcchBuffer AS QUAD ) AS LONG
DECLARE FUNCTION GetServiceKeyNameW LIB "advapi32.dll" ALIAS "GetServiceKeyNameW" ( BYVAL hSCManager AS QUAD
 , BYREF lpDisplayName AS WSTRINGZ
 , BYREF lpServiceName AS WSTRINGZ
 , BYREF lpcchBuffer AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO GetServiceKeyName = GetServiceKeyNameW
#ELSE
 MACRO GetServiceKeyName = GetServiceKeyNameA
#ENDIF
DECLARE FUNCTION GetServiceDisplayNameA LIB "advapi32.dll" ALIAS "GetServiceDisplayNameA" ( BYVAL hSCManager AS QUAD , BYREF lpServiceName AS ASCIIZ , BYREF lpDisplayName AS ASCIIZ , BYREF lpcchBuffer AS QUAD ) AS LONG
DECLARE FUNCTION GetServiceDisplayNameW LIB "advapi32.dll" ALIAS "GetServiceDisplayNameW" ( BYVAL hSCManager AS QUAD
 , BYREF lpServiceName AS WSTRINGZ
 , BYREF lpDisplayName AS WSTRINGZ
 , BYREF lpcchBuffer AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO GetServiceDisplayName = GetServiceDisplayNameW
#ELSE
 MACRO GetServiceDisplayName = GetServiceDisplayNameA
#ENDIF
DECLARE FUNCTION LockServiceDatabase LIB "advapi32.dll" ALIAS "LockServiceDatabase" ( BYVAL hSCManager AS QUAD ) AS QUAD ' SC_LOCK
DECLARE FUNCTION NotifyBootConfigStatus LIB "advapi32.dll" ALIAS "NotifyBootConfigStatus" ( BYVAL BootAcceptable AS LONG ) AS LONG
DECLARE FUNCTION OpenSCManagerA LIB "advapi32.dll" ALIAS "OpenSCManagerA" ( BYREF lpMachineName AS ASCIIZ
 , BYREF lpDatabaseName AS ASCIIZ
 , BYVAL dwDesiredAccess AS DWORD
 ) AS DWORD ' SC_HANDLE
DECLARE FUNCTION OpenSCManagerW LIB "advapi32.dll" ALIAS "OpenSCManagerW" ( BYREF lpMachineName AS WSTRINGZ , BYREF lpDatabaseName AS WSTRINGZ , BYVAL dwDesiredAccess AS QUAD ) AS QUAD ' SC_HANDLE
#IF %DEF(%UNICODE)
 MACRO OpenSCManager = OpenSCManagerW
#ELSE
 MACRO OpenSCManager = OpenSCManagerA
#ENDIF
DECLARE FUNCTION OpenServiceA LIB "advapi32.dll" ALIAS "OpenServiceA" ( BYVAL hSCManager AS QUAD , BYREF lpServiceName AS ASCIIZ , BYVAL dwDesiredAccess AS QUAD ) AS QUAD ' SC_HANDLE
DECLARE FUNCTION OpenServiceW LIB "advapi32.dll" ALIAS "OpenServiceW" ( BYVAL hSCManager AS QUAD , BYREF lpServiceName AS WSTRINGZ , BYVAL dwDesiredAccess AS QUAD ) AS QUAD ' SC_HANDLE
#IF %DEF(%UNICODE)
 MACRO OpenService = OpenServiceW
#ELSE
 MACRO OpenService = OpenServiceA
#ENDIF
DECLARE FUNCTION QueryServiceConfigA LIB "advapi32.dll" ALIAS "QueryServiceConfigA" ( BYVAL hService AS QUAD , BYREF lpServiceConfig AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD ) AS LONG
DECLARE FUNCTION QueryServiceConfigW LIB "advapi32.dll" ALIAS "QueryServiceConfigW" ( BYVAL hService AS QUAD
 , BYREF lpServiceConfig AS ANY
 , BYVAL cbBufSize AS DWORD
 , BYREF pcbBytesNeeded AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO QueryServiceConfig = QueryServiceConfigW
#ELSE
 MACRO QueryServiceConfig = QueryServiceConfigA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION QueryServiceConfig2A LIB "AdvApi32.dll" ALIAS "QueryServiceConfig2A" ( BYVAL hService AS QUAD, BYVAL dwInfoLevel AS QUAD, BYVAL lpBuffer AS BYTE PTR, BYVAL cbBufSize AS QUAD, pcbBytesNeeded AS QUAD ) AS LONG
#ELSE
DECLARE FUNCTION QueryServiceConfig2A LIB "advapi32.dll" ALIAS "QueryServiceConfig2A" ( BYVAL hService AS QUAD , BYVAL dwInfoLevel AS QUAD , BYREF lpBuffer AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION QueryServiceConfig2W LIB "AdvApi32.dll" ALIAS "QueryServiceConfig2W" ( BYVAL hService AS QUAD, BYVAL dwInfoLevel AS QUAD, BYVAL lpBuffer AS BYTE PTR, BYVAL cbBufSize AS QUAD, pcbBytesNeeded AS QUAD ) AS LONG
#ELSE
DECLARE FUNCTION QueryServiceConfig2W LIB "advapi32.dll" ALIAS "QueryServiceConfig2W" ( BYVAL hService AS QUAD , BYVAL dwInfoLevel AS QUAD , BYREF lpBuffer AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO QueryServiceConfig2 = QueryServiceConfig2W
#ELSE
 MACRO QueryServiceConfig2 = QueryServiceConfig2A
#ENDIF
DECLARE FUNCTION QueryServiceLockStatusA LIB "advapi32.dll" ALIAS "QueryServiceLockStatusA" ( BYVAL hSCManager AS QUAD , BYREF lpLockStatus AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD ) AS LONG
DECLARE FUNCTION QueryServiceLockStatusW LIB "advapi32.dll" ALIAS "QueryServiceLockStatusW" ( BYVAL hSCManager AS QUAD
 , BYREF lpLockStatus AS ANY
 , BYVAL cbBufSize AS DWORD
 , BYREF pcbBytesNeeded AS DWORD
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO QueryServiceLockStatus = QueryServiceLockStatusW
#ELSE
 MACRO QueryServiceLockStatus = QueryServiceLockStatusA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION QueryServiceObjectSecurity LIB "AdvApi32.dll" ALIAS "QueryServiceObjectSecurity" ( BYVAL hService AS QUAD, BYVAL dwSecurityInformation AS QUAD, ' SECURITY_INFORMATION
 lpSecurityDescriptor AS DWORD, ' PSECURITY_DESCRIPTOR
 BYVAL cbBufSize AS DWORD, pcbBytesNeeded AS DWORD ) AS LONG
#ELSE
DECLARE FUNCTION QueryServiceObjectSecurity LIB "advapi32.dll" ALIAS "QueryServiceObjectSecurity" ( BYVAL hService AS QUAD , BYVAL dwSecurityInformation AS SECURITY_INFORMATION , BYREF lpSecurityDescriptor AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD ) AS LONG
#ENDIF
DECLARE FUNCTION QueryServiceStatus LIB "advapi32.dll" ALIAS "QueryServiceStatus" ( BYVAL hService AS QUAD , BYREF lpServiceStatus AS SERVICE_STATUS ) AS LONG
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION QueryServiceStatusEx LIB "AdvApi32.dll" ALIAS "QueryServiceStatusEx" ( BYVAL hService AS QUAD, BYVAL InfoLevel AS LONG, BYVAL lpBuffer AS BYTE PTR, BYVAL cbBufSize AS QUAD, pcbBytesNeeded AS QUAD ) AS LONG
#ELSE
DECLARE FUNCTION QueryServiceStatusEx LIB "advapi32.dll" ALIAS "QueryServiceStatusEx" ( BYVAL hService AS QUAD , BYVAL InfoLevel AS LONG , BYREF lpBuffer AS ANY , BYVAL cbBufSize AS QUAD , BYREF pcbBytesNeeded AS QUAD ) AS LONG
#ENDIF
DECLARE FUNCTION RegisterServiceCtrlHandlerA LIB "advapi32.dll" ALIAS "RegisterServiceCtrlHandlerA" ( BYREF lpServiceName AS ASCIIZ , BYVAL lpHandlerProc AS QUAD ) AS QUAD ' SERVICE_STATUS_HANDLE
DECLARE FUNCTION RegisterServiceCtrlHandlerW LIB "advapi32.dll" ALIAS "RegisterServiceCtrlHandlerW" ( BYREF lpServiceName AS WSTRINGZ , BYVAL lpHandlerProc AS QUAD ) AS QUAD ' SERVICE_STATUS_HANDLE
#IF %DEF(%UNICODE)
 MACRO RegisterServiceCtrlHandler = RegisterServiceCtrlHandlerW
#ELSE
 MACRO RegisterServiceCtrlHandler = RegisterServiceCtrlHandlerA
#ENDIF
DECLARE FUNCTION RegisterServiceCtrlHandlerExA LIB "advapi32.dll" ALIAS "RegisterServiceCtrlHandlerExA" ( BYREF lpServiceName AS ASCIIZ , BYVAL lpHandlerProc AS QUAD , OPTIONAL BYREF lpContext AS ANY ) AS QUAD ' SERVICE_STATUS_HANDLE
DECLARE FUNCTION RegisterServiceCtrlHandlerExW LIB "advapi32.dll" ALIAS "RegisterServiceCtrlHandlerExW" ( BYREF lpServiceName AS WSTRINGZ , BYVAL lpHandlerProc AS QUAD , OPTIONAL BYREF lpContext AS ANY ) AS QUAD ' SERVICE_STATUS_HANDLE
#IF %DEF(%UNICODE)
 MACRO RegisterServiceCtrlHandlerEx = RegisterServiceCtrlHandlerExW
#ELSE
 MACRO RegisterServiceCtrlHandlerEx = RegisterServiceCtrlHandlerExA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SetServiceObjectSecurity LIB "AdvApi32.dll" ALIAS "SetServiceObjectSecurity" ( BYVAL hService AS QUAD, BYVAL dwSecurityInformation AS QUAD, ' SECURITY_INFORMATION
 BYVAL lpSecurityDescriptor AS DWORD ' PSECURITY_DESCRIPTOR
 ) AS LONG
#ELSE
DECLARE FUNCTION SetServiceObjectSecurity LIB "advapi32.dll" ALIAS "SetServiceObjectSecurity" ( BYVAL hService AS QUAD , BYVAL dwSecurityInformation AS SECURITY_INFORMATION , BYREF lpSecurityDescriptor AS ANY ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SetServiceStatus LIB "AdvApi32.dll" ALIAS "SetServiceStatus" ( BYVAL hServiceStatus AS QUAD, ' SERVICE_STATUS_HANDLE
 lpServiceStatus AS DWORD ' LPSERVICE_STATUS
 ) AS LONG
#ELSE
DECLARE FUNCTION SetServiceStatus LIB "advapi32.dll" ALIAS "SetServiceStatus" ( BYVAL hServiceStatus AS QUAD , BYREF lpServiceStatus AS SERVICE_STATUS ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION StartServiceCtrlDispatcherA LIB "AdvApi32.dll" ALIAS "StartServiceCtrlDispatcherA" ( BYVAL lpServiceStartTable AS SERVICE_TABLE_ENTRYA PTR ) AS LONG
#ELSE
DECLARE FUNCTION StartServiceCtrlDispatcherA LIB "advapi32.dll" ALIAS "StartServiceCtrlDispatcherA" ( BYREF lpServiceStartTable AS SERVICE_TABLE_ENTRYA ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION StartServiceCtrlDispatcherW LIB "AdvApi32.dll" ALIAS "StartServiceCtrlDispatcherW" ( BYVAL lpServiceStartTable AS SERVICE_TABLE_ENTRYW PTR ) AS LONG
#ELSE
DECLARE FUNCTION StartServiceCtrlDispatcherW LIB "advapi32.dll" ALIAS "StartServiceCtrlDispatcherW" ( BYREF lpServiceStartTable AS SERVICE_TABLE_ENTRYW ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO StartServiceCtrlDispatcher = StartServiceCtrlDispatcherW
#ELSE
 MACRO StartServiceCtrlDispatcher = StartServiceCtrlDispatcherA
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION StartServiceA LIB "AdvApi32.dll" ALIAS "StartServiceA" ( BYVAL hService AS QUAD, BYVAL dwNumServiceArgs AS QUAD, lpServiceArgVectors AS ANY ) AS LONG
#ELSE
DECLARE FUNCTION StartServiceA LIB "advapi32.dll" ALIAS "StartServiceA" ( BYVAL hService AS QUAD , BYVAL dwNumServiceArgs AS QUAD , BYVAL lpServiceArgVectors AS QUAD ) AS LONG
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION StartServiceW LIB "AdvApi32.dll" ALIAS "StartServiceW" ( BYVAL hService AS QUAD, BYVAL dwNumServiceArgs AS QUAD, lpServiceArgVectors AS ANY ) AS LONG
#ELSE
DECLARE FUNCTION StartServiceW LIB "advapi32.dll" ALIAS "StartServiceW" ( BYVAL hService AS QUAD , BYVAL dwNumServiceArgs AS QUAD , BYREF lpServiceArgVectors AS WSTRINGZ ) AS LONG
#ENDIF
#IF %DEF(%UNICODE)
 MACRO StartService = StartServiceW
#ELSE
 MACRO StartService = StartServiceA
#ENDIF
DECLARE FUNCTION UnlockServiceDatabase LIB "advapi32.dll" ALIAS "UnlockServiceDatabase" ( BYVAL ScLock AS QUAD ) AS LONG
'#if (NTDDI_VERSION >= NTDDI_VISTA)
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION NotifyServiceStatusChangeA LIB "AdvApi32.dll" ALIAS "NotifyServiceStatusChangeA" ( BYVAL hService AS QUAD, BYVAL dwNotifyMask AS QUAD, BYVAL pNotifyBuffer AS SERVICE_NOTIFYA PTR ) AS QUAD
#ELSE
DECLARE FUNCTION NotifyServiceStatusChangeA LIB "advapi32.dll" ALIAS "NotifyServiceStatusChangeA" ( BYVAL hService AS QUAD , BYVAL dwNotifyMask AS QUAD , BYREF pNotifyBuffer AS SERVICE_NOTIFYA ) AS QUAD
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION NotifyServiceStatusChangeW LIB "AdvApi32.dll" ALIAS "NotifyServiceStatusChangeW" ( BYVAL hService AS QUAD, BYVAL dwNotifyMask AS QUAD, BYVAL pNotifyBuffer AS SERVICE_NOTIFYW PTR ) AS QUAD
#ELSE
DECLARE FUNCTION NotifyServiceStatusChangeW LIB "advapi32.dll" ALIAS "NotifyServiceStatusChangeW" ( BYVAL hService AS QUAD , BYVAL dwNotifyMask AS QUAD , BYREF pNotifyBuffer AS SERVICE_NOTIFYW ) AS QUAD
#ENDIF
#IF %DEF(%UNICODE)
 MACRO NotifyServiceStatusChange = NotifyServiceStatusChangeW
#ELSE
 MACRO NotifyServiceStatusChange = NotifyServiceStatusChangeA
#ENDIF
DECLARE FUNCTION ControlServiceExA LIB "advapi32.dll" ALIAS "ControlServiceExA" ( BYVAL hService AS QUAD , BYVAL dwControl AS QUAD , BYVAL dwInfoLevel AS QUAD , BYREF pControlParams AS ANY ) AS LONG
DECLARE FUNCTION ControlServiceExW LIB "advapi32.dll" ALIAS "ControlServiceExW" ( BYVAL hService AS QUAD
 , BYVAL dwControl AS DWORD
 , BYVAL dwInfoLevel AS DWORD
 , BYREF pControlParams AS ANY
 ) AS LONG
#IF %DEF(%UNICODE)
 MACRO ControlServiceEx = ControlServiceExW
#ELSE
 MACRO ControlServiceEx = ControlServiceExA
#ENDIF
'#endif // NTDDI_VERSION >= NTDDI_VISTA
#ENDIF
