home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Source / Rtl / Win / WINSVC.PAS < prev   
Pascal/Delphi Source File  |  1999-08-11  |  28KB  |  673 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Run-time Library                 }
  5. {       Win32 service API interface unit                }
  6. {                                                       }
  7. {       Copyright (c) 1985-1999, Microsoft Corporation  }
  8. {                                                       }
  9. {       Translator: Inprise Corporation                 }
  10. {                                                       }
  11. {*******************************************************}
  12.  
  13. unit WinSvc;
  14.  
  15. {$ALIGN ON}
  16. {$MINENUMSIZE 4}
  17. {$WEAKPACKAGEUNIT}
  18.  
  19. interface
  20.  
  21. uses Windows;
  22.  
  23. //
  24. // Constants
  25. //
  26.  
  27. const
  28.  
  29. //
  30. // Service database names
  31. //
  32.   {$EXTERNALSYM SERVICES_ACTIVE_DATABASEA}
  33.   SERVICES_ACTIVE_DATABASEA     = 'ServicesActive';
  34.   {$EXTERNALSYM SERVICES_ACTIVE_DATABASEW}
  35.   SERVICES_ACTIVE_DATABASEW     = 'ServicesActive';
  36.   {$EXTERNALSYM SERVICES_ACTIVE_DATABASE}
  37.   SERVICES_ACTIVE_DATABASE = SERVICES_ACTIVE_DATABASEA;
  38.   {$EXTERNALSYM SERVICES_FAILED_DATABASEA}
  39.   SERVICES_FAILED_DATABASEA     = 'ServicesFailed';
  40.   {$EXTERNALSYM SERVICES_FAILED_DATABASEW}
  41.   SERVICES_FAILED_DATABASEW     = 'ServicesFailed';
  42.   {$EXTERNALSYM SERVICES_FAILED_DATABASE}
  43.   SERVICES_FAILED_DATABASE = SERVICES_FAILED_DATABASEA;
  44.  
  45. //
  46. // Character to designate that a name is a group
  47. //
  48.   {$EXTERNALSYM SC_GROUP_IDENTIFIERA}
  49.   SC_GROUP_IDENTIFIERA          = '+';
  50.   {$EXTERNALSYM SC_GROUP_IDENTIFIERW}
  51.   SC_GROUP_IDENTIFIERW          = '+';
  52.   {$EXTERNALSYM SC_GROUP_IDENTIFIER}
  53.   SC_GROUP_IDENTIFIER = SC_GROUP_IDENTIFIERA;
  54.  
  55. //
  56. // Value to indicate no change to an optional parameter
  57. //
  58.   {$EXTERNALSYM SERVICE_NO_CHANGE}
  59.   SERVICE_NO_CHANGE              = $FFFFFFFF;
  60.  
  61. //
  62. // Service State -- for Enum Requests (Bit Mask)
  63. //
  64.   {$EXTERNALSYM SERVICE_ACTIVE}
  65.   SERVICE_ACTIVE                 = $00000001;
  66.   {$EXTERNALSYM SERVICE_INACTIVE}
  67.   SERVICE_INACTIVE               = $00000002;
  68.   {$EXTERNALSYM SERVICE_STATE_ALL}
  69.   SERVICE_STATE_ALL              = (SERVICE_ACTIVE   or
  70.                                     SERVICE_INACTIVE);
  71.  
  72. //
  73. // Controls
  74. //
  75.   {$EXTERNALSYM SERVICE_CONTROL_STOP}
  76.   SERVICE_CONTROL_STOP           = $00000001;
  77.   {$EXTERNALSYM SERVICE_CONTROL_PAUSE}
  78.   SERVICE_CONTROL_PAUSE          = $00000002;
  79.   {$EXTERNALSYM SERVICE_CONTROL_CONTINUE}
  80.   SERVICE_CONTROL_CONTINUE       = $00000003;
  81.   {$EXTERNALSYM SERVICE_CONTROL_INTERROGATE}
  82.   SERVICE_CONTROL_INTERROGATE    = $00000004;
  83.   {$EXTERNALSYM SERVICE_CONTROL_SHUTDOWN}
  84.   SERVICE_CONTROL_SHUTDOWN       = $00000005;
  85.  
  86. //
  87. // Service State -- for CurrentState
  88. //
  89.   {$EXTERNALSYM SERVICE_STOPPED}
  90.   SERVICE_STOPPED                = $00000001;
  91.   {$EXTERNALSYM SERVICE_START_PENDING}
  92.   SERVICE_START_PENDING          = $00000002;
  93.   {$EXTERNALSYM SERVICE_STOP_PENDING}
  94.   SERVICE_STOP_PENDING           = $00000003;
  95.   {$EXTERNALSYM SERVICE_RUNNING}
  96.   SERVICE_RUNNING                = $00000004;
  97.   {$EXTERNALSYM SERVICE_CONTINUE_PENDING}
  98.   SERVICE_CONTINUE_PENDING       = $00000005;
  99.   {$EXTERNALSYM SERVICE_PAUSE_PENDING}
  100.   SERVICE_PAUSE_PENDING          = $00000006;
  101.   {$EXTERNALSYM SERVICE_PAUSED}
  102.   SERVICE_PAUSED                 = $00000007;
  103.  
  104. //
  105. // Controls Accepted  (Bit Mask)
  106. //
  107.   {$EXTERNALSYM SERVICE_ACCEPT_STOP}
  108.   SERVICE_ACCEPT_STOP            = $00000001;
  109.   {$EXTERNALSYM SERVICE_ACCEPT_PAUSE_CONTINUE}
  110.   SERVICE_ACCEPT_PAUSE_CONTINUE  = $00000002;
  111.   {$EXTERNALSYM SERVICE_ACCEPT_SHUTDOWN}
  112.   SERVICE_ACCEPT_SHUTDOWN        = $00000004;
  113.  
  114. //
  115. // Service Control Manager object specific access types
  116. //
  117.   {$EXTERNALSYM SC_MANAGER_CONNECT}
  118.   SC_MANAGER_CONNECT             = $0001;
  119.   {$EXTERNALSYM SC_MANAGER_CREATE_SERVICE}
  120.   SC_MANAGER_CREATE_SERVICE      = $0002;
  121.   {$EXTERNALSYM SC_MANAGER_ENUMERATE_SERVICE}
  122.   SC_MANAGER_ENUMERATE_SERVICE   = $0004;
  123.   {$EXTERNALSYM SC_MANAGER_LOCK}
  124.   SC_MANAGER_LOCK                = $0008;
  125.   {$EXTERNALSYM SC_MANAGER_QUERY_LOCK_STATUS}
  126.   SC_MANAGER_QUERY_LOCK_STATUS   = $0010;
  127.   {$EXTERNALSYM SC_MANAGER_MODIFY_BOOT_CONFIG}
  128.   SC_MANAGER_MODIFY_BOOT_CONFIG  = $0020;
  129.  
  130.   {$EXTERNALSYM SC_MANAGER_ALL_ACCESS}
  131.   SC_MANAGER_ALL_ACCESS          = (STANDARD_RIGHTS_REQUIRED or
  132.                                     SC_MANAGER_CONNECT or
  133.                                     SC_MANAGER_CREATE_SERVICE or
  134.                                     SC_MANAGER_ENUMERATE_SERVICE or
  135.                                     SC_MANAGER_LOCK or
  136.                                     SC_MANAGER_QUERY_LOCK_STATUS or
  137.                                     SC_MANAGER_MODIFY_BOOT_CONFIG);
  138.  
  139. //
  140. // Service object specific access type
  141. //
  142.   {$EXTERNALSYM SERVICE_QUERY_CONFIG}
  143.   SERVICE_QUERY_CONFIG           = $0001;
  144.   {$EXTERNALSYM SERVICE_CHANGE_CONFIG}
  145.   SERVICE_CHANGE_CONFIG          = $0002;
  146.   {$EXTERNALSYM SERVICE_QUERY_STATUS}
  147.   SERVICE_QUERY_STATUS           = $0004;
  148.   {$EXTERNALSYM SERVICE_ENUMERATE_DEPENDENTS}
  149.   SERVICE_ENUMERATE_DEPENDENTS   = $0008;
  150.   {$EXTERNALSYM SERVICE_START}
  151.   SERVICE_START                  = $0010;
  152.   {$EXTERNALSYM SERVICE_STOP}
  153.   SERVICE_STOP                   = $0020;
  154.   {$EXTERNALSYM SERVICE_PAUSE_CONTINUE}
  155.   SERVICE_PAUSE_CONTINUE         = $0040;
  156.   {$EXTERNALSYM SERVICE_INTERROGATE}
  157.   SERVICE_INTERROGATE            = $0080;
  158.   {$EXTERNALSYM SERVICE_USER_DEFINED_CONTROL}
  159.   SERVICE_USER_DEFINED_CONTROL   = $0100;
  160.  
  161.   {$EXTERNALSYM SERVICE_ALL_ACCESS}
  162.   SERVICE_ALL_ACCESS             = (STANDARD_RIGHTS_REQUIRED or
  163.                                     SERVICE_QUERY_CONFIG or
  164.                                     SERVICE_CHANGE_CONFIG or
  165.                                     SERVICE_QUERY_STATUS or
  166.                                     SERVICE_ENUMERATE_DEPENDENTS or
  167.                                     SERVICE_START or
  168.                                     SERVICE_STOP or
  169.                                     SERVICE_PAUSE_CONTINUE or
  170.                                     SERVICE_INTERROGATE or
  171.                                     SERVICE_USER_DEFINED_CONTROL);
  172.  
  173.  
  174. //
  175. // Service Types (Bit Mask)
  176. //
  177.   {$EXTERNALSYM SERVICE_KERNEL_DRIVER}
  178.   SERVICE_KERNEL_DRIVER         = $00000001;
  179.   {$EXTERNALSYM SERVICE_FILE_SYSTEM_DRIVER}
  180.   SERVICE_FILE_SYSTEM_DRIVER    = $00000002;
  181.   {$EXTERNALSYM SERVICE_ADAPTER}
  182.   SERVICE_ADAPTER               = $00000004;
  183.   {$EXTERNALSYM SERVICE_RECOGNIZER_DRIVER}
  184.   SERVICE_RECOGNIZER_DRIVER     = $00000008;
  185.  
  186.   {$EXTERNALSYM SERVICE_DRIVER}
  187.   SERVICE_DRIVER                = (SERVICE_KERNEL_DRIVER or
  188.                                    SERVICE_FILE_SYSTEM_DRIVER or
  189.                                    SERVICE_RECOGNIZER_DRIVER);
  190.  
  191.   {$EXTERNALSYM SERVICE_WIN32_OWN_PROCESS}
  192.   SERVICE_WIN32_OWN_PROCESS     = $00000010;
  193.   {$EXTERNALSYM SERVICE_WIN32_SHARE_PROCESS}
  194.   SERVICE_WIN32_SHARE_PROCESS   = $00000020;
  195.   {$EXTERNALSYM SERVICE_WIN32}
  196.   SERVICE_WIN32                 = (SERVICE_WIN32_OWN_PROCESS or
  197.                                    SERVICE_WIN32_SHARE_PROCESS);
  198.  
  199.   {$EXTERNALSYM SERVICE_INTERACTIVE_PROCESS}
  200.   SERVICE_INTERACTIVE_PROCESS   = $00000100;
  201.  
  202.   {$EXTERNALSYM SERVICE_TYPE_ALL}
  203.   SERVICE_TYPE_ALL              = (SERVICE_WIN32 or
  204.                                   SERVICE_ADAPTER or
  205.                                   SERVICE_DRIVER or
  206.                                   SERVICE_INTERACTIVE_PROCESS);
  207.  
  208. //
  209. // Start Type
  210. //
  211.   {$EXTERNALSYM SERVICE_BOOT_START}
  212.   SERVICE_BOOT_START            = $00000000;
  213.   {$EXTERNALSYM SERVICE_SYSTEM_START}
  214.   SERVICE_SYSTEM_START          = $00000001;
  215.   {$EXTERNALSYM SERVICE_AUTO_START}
  216.   SERVICE_AUTO_START            = $00000002;
  217.   {$EXTERNALSYM SERVICE_DEMAND_START}
  218.   SERVICE_DEMAND_START          = $00000003;
  219.   {$EXTERNALSYM SERVICE_DISABLED}
  220.   SERVICE_DISABLED              = $00000004;
  221.  
  222. //
  223. // Error control type
  224. //
  225.   {$EXTERNALSYM SERVICE_ERROR_IGNORE}
  226.   SERVICE_ERROR_IGNORE          = $00000000;
  227.   {$EXTERNALSYM SERVICE_ERROR_NORMAL}
  228.   SERVICE_ERROR_NORMAL          = $00000001;
  229.   {$EXTERNALSYM SERVICE_ERROR_SEVERE}
  230.   SERVICE_ERROR_SEVERE          = $00000002;
  231.   {$EXTERNALSYM SERVICE_ERROR_CRITICAL}
  232.   SERVICE_ERROR_CRITICAL        = $00000003;
  233.  
  234. type
  235.  
  236. //
  237. // Handle Types
  238. //
  239.  
  240.   {$EXTERNALSYM SC_HANDLE}
  241.   SC_HANDLE = THandle;
  242.   {$EXTERNALSYM LPSC_HANDLE}
  243.   LPSC_HANDLE = ^SC_HANDLE;
  244.  
  245.   {$EXTERNALSYM SERVICE_STATUS_HANDLE}
  246.   SERVICE_STATUS_HANDLE = DWORD;
  247.  
  248. //
  249. // pointer to string pointer
  250. //
  251.  
  252.   PLPSTRA = ^PAnsiChar;
  253.   PLPWSTRW = ^PWideChar;
  254.   PLPSTR = PLPSTRA;
  255.  
  256. //
  257. // Service Status Structure
  258. //
  259.  
  260.   PServiceStatus = ^TServiceStatus;
  261.   {$EXTERNALSYM _SERVICE_STATUS}
  262.   _SERVICE_STATUS = record
  263.     dwServiceType: DWORD;
  264.     dwCurrentState: DWORD;
  265.     dwControlsAccepted: DWORD;
  266.     dwWin32ExitCode: DWORD;
  267.     dwServiceSpecificExitCode: DWORD;
  268.     dwCheckPoint: DWORD;
  269.     dwWaitHint: DWORD;
  270.   end;
  271.   {$EXTERNALSYM SERVICE_STATUS}
  272.   SERVICE_STATUS = _SERVICE_STATUS;
  273.   TServiceStatus = _SERVICE_STATUS;
  274.  
  275. //
  276. // Service Status Enumeration Structure
  277. //
  278.   PEnumServiceStatusA = ^TEnumServiceStatusA;
  279.   PEnumServiceStatusW = ^TEnumServiceStatusW;
  280.   PEnumServiceStatus = PEnumServiceStatusA;
  281.   {$EXTERNALSYM _ENUM_SERVICE_STATUSA}
  282.   _ENUM_SERVICE_STATUSA = record
  283.     lpServiceName: PAnsiChar;
  284.     lpDisplayName: PAnsiChar;
  285.     ServiceStatus: TServiceStatus;
  286.   end;
  287. {#BEGIN}
  288.   {$EXTERNALSYM ENUM_SERVICE_STATUSA}
  289.   ENUM_SERVICE_STATUSA = _ENUM_SERVICE_STATUSA;
  290.   {$EXTERNALSYM _ENUM_SERVICE_STATUSW}
  291.   _ENUM_SERVICE_STATUSW = record
  292.     lpServiceName: PWideChar;
  293.     lpDisplayName: PWideChar;
  294.     ServiceStatus: TServiceStatus;
  295.   end;
  296. {#BEGIN}
  297.   {$EXTERNALSYM ENUM_SERVICE_STATUSW}
  298.   ENUM_SERVICE_STATUSW = _ENUM_SERVICE_STATUSW;
  299.   {$EXTERNALSYM _ENUM_SERVICE_STATUS}
  300.   _ENUM_SERVICE_STATUS = _ENUM_SERVICE_STATUSA;
  301.   TEnumServiceStatusA = _ENUM_SERVICE_STATUSA;
  302.   TEnumServiceStatusW = _ENUM_SERVICE_STATUSW;
  303.   TEnumServiceStatus = TEnumServiceStatusA;
  304.  
  305. //
  306. // Structures for the Lock API functions
  307. //
  308.   SC_LOCK = Pointer;
  309.   {$EXTERNALSYM SC_LOCK}
  310.   
  311.   PQueryServiceLockStatusA = ^TQueryServiceLockStatusA;
  312.   PQueryServiceLockStatusW = ^TQueryServiceLockStatusW;
  313.   PQueryServiceLockStatus = PQueryServiceLockStatusA;
  314.   {$EXTERNALSYM _QUERY_SERVICE_LOCK_STATUSA}
  315.   _QUERY_SERVICE_LOCK_STATUSA = record
  316.     fIsLocked: DWORD;
  317.     lpLockOwner: PAnsiChar;
  318.     dwLockDuration: DWORD;
  319.   end;
  320.   {$EXTERNALSYM _QUERY_SERVICE_LOCK_STATUSW}
  321.   _QUERY_SERVICE_LOCK_STATUSW = record
  322.     fIsLocked: DWORD;
  323.     lpLockOwner: PWideChar;
  324.     dwLockDuration: DWORD;
  325.   end;
  326.   {$EXTERNALSYM _QUERY_SERVICE_LOCK_STATUS}
  327.   _QUERY_SERVICE_LOCK_STATUS = _QUERY_SERVICE_LOCK_STATUSA;
  328.   {$EXTERNALSYM QUERY_SERVICE_LOCK_STATUSA}
  329.   QUERY_SERVICE_LOCK_STATUSA = _QUERY_SERVICE_LOCK_STATUSA;
  330.   {$EXTERNALSYM QUERY_SERVICE_LOCK_STATUSW}
  331.   QUERY_SERVICE_LOCK_STATUSW = _QUERY_SERVICE_LOCK_STATUSW;
  332.   {$EXTERNALSYM QUERY_SERVICE_LOCK_STATUS}
  333.   QUERY_SERVICE_LOCK_STATUS = QUERY_SERVICE_LOCK_STATUSA;
  334.   TQueryServiceLockStatusA = _QUERY_SERVICE_LOCK_STATUSA;
  335.   TQueryServiceLockStatusW = _QUERY_SERVICE_LOCK_STATUSW;
  336.   TQueryServiceLockStatus = TQueryServiceLockStatusA;
  337.  
  338. //
  339. // Query Service Configuration Structure
  340. //
  341.   PQueryServiceConfigA = ^TQueryServiceConfigA;
  342.   PQueryServiceConfigW = ^TQueryServiceConfigW;
  343.   PQueryServiceConfig = PQueryServiceConfigA;
  344.   {$EXTERNALSYM _QUERY_SERVICE_CONFIGA}
  345.    _QUERY_SERVICE_CONFIGA = record
  346.     dwServiceType: DWORD;
  347.     dwStartType: DWORD;
  348.     dwErrorControl: DWORD;
  349.     lpBinaryPathName: PAnsiChar;
  350.     lpLoadOrderGroup: PAnsiChar;
  351.     dwTagId: DWORD;
  352.     lpDependencies: PAnsiChar;
  353.     lpServiceStartName: PAnsiChar;
  354.     lpDisplayName: PAnsiChar;
  355.   end;
  356.   {$EXTERNALSYM _QUERY_SERVICE_CONFIGW}
  357.    _QUERY_SERVICE_CONFIGW = record
  358.     dwServiceType: DWORD;
  359.     dwStartType: DWORD;
  360.     dwErrorControl: DWORD;
  361.     lpBinaryPathName: PWideChar;
  362.     lpLoadOrderGroup: PWideChar;
  363.     dwTagId: DWORD;
  364.     lpDependencies: PWideChar;
  365.     lpServiceStartName: PWideChar;
  366.     lpDisplayName: PWideChar;
  367.   end;
  368.   {$EXTERNALSYM _QUERY_SERVICE_CONFIG}
  369.   _QUERY_SERVICE_CONFIG = _QUERY_SERVICE_CONFIGA;
  370.   {$EXTERNALSYM QUERY_SERVICE_CONFIGA}
  371.   QUERY_SERVICE_CONFIGA = _QUERY_SERVICE_CONFIGA;
  372.   {$EXTERNALSYM QUERY_SERVICE_CONFIGW}
  373.   QUERY_SERVICE_CONFIGW = _QUERY_SERVICE_CONFIGW;
  374.   {$EXTERNALSYM QUERY_SERVICE_CONFIG}
  375.   QUERY_SERVICE_CONFIG = QUERY_SERVICE_CONFIGA;
  376.   TQueryServiceConfigA = _QUERY_SERVICE_CONFIGA;
  377.   TQueryServiceConfigW = _QUERY_SERVICE_CONFIGW;
  378.   TQueryServiceConfig = TQueryServiceConfigA;
  379.  
  380. //
  381. // Function Prototype for the Service Main Function
  382. //
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.   {$EXTERNALSYM LPSERVICE_MAIN_FUNCTIONA}
  394.   LPSERVICE_MAIN_FUNCTIONA = TFarProc;
  395.   {$EXTERNALSYM LPSERVICE_MAIN_FUNCTIONW}
  396.   LPSERVICE_MAIN_FUNCTIONW = TFarProc;
  397.   {$EXTERNALSYM LPSERVICE_MAIN_FUNCTION}
  398.   LPSERVICE_MAIN_FUNCTION = LPSERVICE_MAIN_FUNCTIONA;
  399.   TServiceMainFunctionA = LPSERVICE_MAIN_FUNCTIONA;
  400.   TServiceMainFunctionW = LPSERVICE_MAIN_FUNCTIONW;
  401.   TServiceMainFunction = TServiceMainFunctionA;
  402.  
  403. //
  404. // Service Start Table
  405. //
  406.   PServiceTableEntryA = ^TServiceTableEntryA;
  407.   PServiceTableEntryW = ^TServiceTableEntryW;
  408.   PServiceTableEntry = PServiceTableEntryA;
  409.   {$EXTERNALSYM _SERVICE_TABLE_ENTRYA}
  410.   _SERVICE_TABLE_ENTRYA = record
  411.     lpServiceName: PAnsiChar;
  412.     lpServiceProc: TServiceMainFunctionA;
  413.   end;
  414.   {$EXTERNALSYM _SERVICE_TABLE_ENTRYW}
  415.   _SERVICE_TABLE_ENTRYW = record
  416.     lpServiceName: PWideChar;
  417.     lpServiceProc: TServiceMainFunctionW;
  418.   end;
  419.   {$EXTERNALSYM _SERVICE_TABLE_ENTRY}
  420.   _SERVICE_TABLE_ENTRY = _SERVICE_TABLE_ENTRYA;
  421.   {$EXTERNALSYM SERVICE_TABLE_ENTRYA}
  422.   SERVICE_TABLE_ENTRYA = _SERVICE_TABLE_ENTRYA;
  423.   {$EXTERNALSYM SERVICE_TABLE_ENTRYW}
  424.   SERVICE_TABLE_ENTRYW = _SERVICE_TABLE_ENTRYW;
  425.   {$EXTERNALSYM SERVICE_TABLE_ENTRY}
  426.   SERVICE_TABLE_ENTRY = SERVICE_TABLE_ENTRYA;
  427.   TServiceTableEntryA = _SERVICE_TABLE_ENTRYA;
  428.   TServiceTableEntryW = _SERVICE_TABLE_ENTRYW;
  429.   TServiceTableEntry = TServiceTableEntryA;
  430.  
  431. //
  432. // Prototype for the Service Control Handler Function
  433. //
  434.  
  435.  
  436.  
  437.  
  438.   {$EXTERNALSYM LPHANDLER_FUNCTION}
  439.   LPHANDLER_FUNCTION = TFarProc;
  440.   THandlerFunction = LPHANDLER_FUNCTION;
  441.  
  442. ///////////////////////////////////////////////////////////////////////////
  443. // API Function Prototypes
  444. ///////////////////////////////////////////////////////////////////////////
  445.  
  446. {$EXTERNALSYM ChangeServiceConfigA}
  447. function ChangeServiceConfigA(hService: SC_HANDLE; dwServiceType, dwStartType,
  448.   dwErrorControl: DWORD; lpBinaryPathName, lpLoadOrderGroup: PAnsiChar;
  449.   lpdwTagId: LPDWORD; lpDependencies, lpServiceStartName, lpPassword,
  450.   lpDisplayName: PAnsiChar): BOOL; stdcall;
  451. {$EXTERNALSYM ChangeServiceConfigW}
  452. function ChangeServiceConfigW(hService: SC_HANDLE; dwServiceType, dwStartType,
  453.   dwErrorControl: DWORD; lpBinaryPathName, lpLoadOrderGroup: PWideChar;
  454.   lpdwTagId: LPDWORD; lpDependencies, lpServiceStartName, lpPassword,
  455.   lpDisplayName: PWideChar): BOOL; stdcall;
  456. {$EXTERNALSYM ChangeServiceConfig}
  457. function ChangeServiceConfig(hService: SC_HANDLE; dwServiceType, dwStartType,
  458.   dwErrorControl: DWORD; lpBinaryPathName, lpLoadOrderGroup: PChar;
  459.   lpdwTagId: LPDWORD; lpDependencies, lpServiceStartName, lpPassword,
  460.   lpDisplayName: PChar): BOOL; stdcall;
  461. {$EXTERNALSYM CloseServiceHandle}
  462. function CloseServiceHandle(hSCObject: SC_HANDLE): BOOL; stdcall;
  463. {$EXTERNALSYM ControlService}
  464. function ControlService(hService: SC_HANDLE; dwControl: DWORD;
  465.   var lpServiceStatus: TServiceStatus): BOOL; stdcall;
  466. {$EXTERNALSYM CreateServiceA}
  467. function CreateServiceA(hSCManager: SC_HANDLE; lpServiceName, lpDisplayName: PAnsiChar;
  468.   dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl: DWORD;
  469.   lpBinaryPathName, lpLoadOrderGroup: PAnsiChar; lpdwTagId: LPDWORD; lpDependencies,
  470.   lpServiceStartName, lpPassword: PAnsiChar): SC_HANDLE; stdcall;
  471. {$EXTERNALSYM CreateServiceW}
  472. function CreateServiceW(hSCManager: SC_HANDLE; lpServiceName, lpDisplayName: PWideChar;
  473.   dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl: DWORD;
  474.   lpBinaryPathName, lpLoadOrderGroup: PWideChar; lpdwTagId: LPDWORD; lpDependencies,
  475.   lpServiceStartName, lpPassword: PWideChar): SC_HANDLE; stdcall;
  476. {$EXTERNALSYM CreateService}
  477. function CreateService(hSCManager: SC_HANDLE; lpServiceName, lpDisplayName: PChar;
  478.   dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl: DWORD;
  479.   lpBinaryPathName, lpLoadOrderGroup: PChar; lpdwTagId: LPDWORD; lpDependencies,
  480.   lpServiceStartName, lpPassword: PChar): SC_HANDLE; stdcall;
  481. {$EXTERNALSYM DeleteService}
  482. function DeleteService(hService: SC_HANDLE): BOOL; stdcall;
  483. {$EXTERNALSYM EnumDependentServicesA}
  484. function EnumDependentServicesA(hService: SC_HANDLE; dwServiceState: DWORD;
  485.   var lpServices: TEnumServiceStatusA; cbBufSize: DWORD; var pcbBytesNeeded,
  486.   lpServicesReturned : DWORD): BOOL; stdcall;
  487. {$EXTERNALSYM EnumDependentServicesW}
  488. function EnumDependentServicesW(hService: SC_HANDLE; dwServiceState: DWORD;
  489.   var lpServices: TEnumServiceStatusW; cbBufSize: DWORD; var pcbBytesNeeded,
  490.   lpServicesReturned : DWORD): BOOL; stdcall;
  491. {$EXTERNALSYM EnumDependentServices}
  492. function EnumDependentServices(hService: SC_HANDLE; dwServiceState: DWORD;
  493.   var lpServices: TEnumServiceStatus; cbBufSize: DWORD; var pcbBytesNeeded,
  494.   lpServicesReturned : DWORD): BOOL; stdcall;
  495. {$EXTERNALSYM EnumServicesStatusA}
  496. function EnumServicesStatusA(hSCManager: SC_HANDLE; dwServiceType,
  497.   dwServiceState: DWORD; var lpServices: TEnumServiceStatusA; cbBufSize: DWORD;
  498.   var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD): BOOL; stdcall;
  499. {$EXTERNALSYM EnumServicesStatusW}
  500. function EnumServicesStatusW(hSCManager: SC_HANDLE; dwServiceType,
  501.   dwServiceState: DWORD; var lpServices: TEnumServiceStatusW; cbBufSize: DWORD;
  502.   var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD): BOOL; stdcall;
  503. {$EXTERNALSYM EnumServicesStatus}
  504. function EnumServicesStatus(hSCManager: SC_HANDLE; dwServiceType,
  505.   dwServiceState: DWORD; var lpServices: TEnumServiceStatus; cbBufSize: DWORD;
  506.   var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD): BOOL; stdcall;
  507. {$EXTERNALSYM GetServiceKeyNameA}
  508. function GetServiceKeyNameA(hSCManager: SC_HANDLE; lpDisplayName,
  509.   lpServiceName: PAnsiChar; var lpcchBuffer: DWORD): BOOL; stdcall;
  510. {$EXTERNALSYM GetServiceKeyNameW}
  511. function GetServiceKeyNameW(hSCManager: SC_HANDLE; lpDisplayName,
  512.   lpServiceName: PWideChar; var lpcchBuffer: DWORD): BOOL; stdcall;
  513. {$EXTERNALSYM GetServiceKeyName}
  514. function GetServiceKeyName(hSCManager: SC_HANDLE; lpDisplayName,
  515.   lpServiceName: PChar; var lpcchBuffer: DWORD): BOOL; stdcall;
  516. {$EXTERNALSYM GetServiceDisplayNameA}
  517. function GetServiceDisplayNameA(hSCManager: SC_HANDLE; lpServiceName,
  518.   lpDisplayName: PAnsiChar; var lpcchBuffer: DWORD): BOOL; stdcall;
  519. {$EXTERNALSYM GetServiceDisplayNameW}
  520. function GetServiceDisplayNameW(hSCManager: SC_HANDLE; lpServiceName,
  521.   lpDisplayName: PWideChar; var lpcchBuffer: DWORD): BOOL; stdcall;
  522. {$EXTERNALSYM GetServiceDisplayName}
  523. function GetServiceDisplayName(hSCManager: SC_HANDLE; lpServiceName,
  524.   lpDisplayName: PChar; var lpcchBuffer: DWORD): BOOL; stdcall;
  525. {$EXTERNALSYM LockServiceDatabase}
  526. function LockServiceDatabase(hSCManager: SC_HANDLE): SC_LOCK; stdcall;
  527. {$EXTERNALSYM NotifyBootConfigStatus}
  528. function NotifyBootConfigStatus(BootAcceptable: BOOL): BOOL; stdcall;
  529. {$EXTERNALSYM OpenSCManagerA}
  530. function OpenSCManagerA(lpMachineName, lpDatabaseName: PAnsiChar;
  531.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  532. {$EXTERNALSYM OpenSCManagerW}
  533. function OpenSCManagerW(lpMachineName, lpDatabaseName: PWideChar;
  534.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  535. {$EXTERNALSYM OpenSCManager}
  536. function OpenSCManager(lpMachineName, lpDatabaseName: PChar;
  537.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  538. {$EXTERNALSYM OpenServiceA}
  539. function OpenServiceA(hSCManager: SC_HANDLE; lpServiceName: PAnsiChar;
  540.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  541. {$EXTERNALSYM OpenServiceW}
  542. function OpenServiceW(hSCManager: SC_HANDLE; lpServiceName: PWideChar;
  543.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  544. {$EXTERNALSYM OpenService}
  545. function OpenService(hSCManager: SC_HANDLE; lpServiceName: PChar;
  546.   dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
  547. {$EXTERNALSYM QueryServiceConfigA}
  548. function QueryServiceConfigA(hService: SC_HANDLE;
  549.   lpServiceConfig: PQueryServiceConfigA; cbBufSize: DWORD;
  550.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  551. {$EXTERNALSYM QueryServiceConfigW}
  552. function QueryServiceConfigW(hService: SC_HANDLE;
  553.   lpServiceConfig: PQueryServiceConfigW; cbBufSize: DWORD;
  554.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  555. {$EXTERNALSYM QueryServiceConfig}
  556. function QueryServiceConfig(hService: SC_HANDLE;
  557.   lpServiceConfig: PQueryServiceConfig; cbBufSize: DWORD;
  558.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  559. {$EXTERNALSYM QueryServiceLockStatusA}
  560. function QueryServiceLockStatusA(hSCManager: SC_HANDLE;
  561.   var lpLockStatus: TQueryServiceLockStatusA; cbBufSize: DWORD;
  562.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  563. {$EXTERNALSYM QueryServiceLockStatusW}
  564. function QueryServiceLockStatusW(hSCManager: SC_HANDLE;
  565.   var lpLockStatus: TQueryServiceLockStatusW; cbBufSize: DWORD;
  566.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  567. {$EXTERNALSYM QueryServiceLockStatus}
  568. function QueryServiceLockStatus(hSCManager: SC_HANDLE;
  569.   var lpLockStatus: TQueryServiceLockStatus; cbBufSize: DWORD;
  570.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  571. {$EXTERNALSYM QueryServiceObjectSecurity}
  572. function QueryServiceObjectSecurity(hService: SC_HANDLE;
  573.   dwSecurityInformation: SECURITY_INFORMATION;
  574.   lpSecurityDescriptor: PSECURITY_DESCRIPTOR; cbBufSize: DWORD;
  575.   var pcbBytesNeeded: DWORD): BOOL; stdcall;
  576. {$EXTERNALSYM QueryServiceStatus}
  577. function QueryServiceStatus(hService: SC_HANDLE; var
  578.   lpServiceStatus: TServiceStatus): BOOL; stdcall;
  579. {$EXTERNALSYM RegisterServiceCtrlHandlerA}
  580. function RegisterServiceCtrlHandlerA(lpServiceName: PAnsiChar;
  581.   lpHandlerProc: ThandlerFunction): SERVICE_STATUS_HANDLE; stdcall;
  582. {$EXTERNALSYM RegisterServiceCtrlHandlerW}
  583. function RegisterServiceCtrlHandlerW(lpServiceName: PWideChar;
  584.   lpHandlerProc: ThandlerFunction): SERVICE_STATUS_HANDLE; stdcall;
  585. {$EXTERNALSYM RegisterServiceCtrlHandler}
  586. function RegisterServiceCtrlHandler(lpServiceName: PChar;
  587.   lpHandlerProc: ThandlerFunction): SERVICE_STATUS_HANDLE; stdcall;
  588. {$EXTERNALSYM SetServiceObjectSecurity}
  589. function SetServiceObjectSecurity(hService: SC_HANDLE;
  590.   dwSecurityInformation: SECURITY_INFORMATION;
  591.   lpSecurityDescriptor: PSECURITY_DESCRIPTOR): BOOL; stdcall;
  592. {$EXTERNALSYM SetServiceStatus}
  593. function SetServiceStatus(hServiceStatus: SERVICE_STATUS_HANDLE;
  594.   var lpServiceStatus: TServiceStatus): BOOL; stdcall;
  595. {$EXTERNALSYM StartServiceCtrlDispatcherA}
  596. function StartServiceCtrlDispatcherA(
  597.   var lpServiceStartTable: TServiceTableEntryA): BOOL; stdcall;
  598. {$EXTERNALSYM StartServiceCtrlDispatcherW}
  599. function StartServiceCtrlDispatcherW(
  600.   var lpServiceStartTable: TServiceTableEntryW): BOOL; stdcall;
  601. {$EXTERNALSYM StartServiceCtrlDispatcher}
  602. function StartServiceCtrlDispatcher(
  603.   var lpServiceStartTable: TServiceTableEntry): BOOL; stdcall;
  604. {$EXTERNALSYM StartServiceA}
  605. function StartServiceA(hService: SC_HANDLE; dwNumServiceArgs: DWORD;
  606.   var lpServiceArgVectors: PAnsiChar): BOOL; stdcall;
  607. {$EXTERNALSYM StartServiceW}
  608. function StartServiceW(hService: SC_HANDLE; dwNumServiceArgs: DWORD;
  609.   var lpServiceArgVectors: PWideChar): BOOL; stdcall;
  610. {$EXTERNALSYM StartService}
  611. function StartService(hService: SC_HANDLE; dwNumServiceArgs: DWORD;
  612.   var lpServiceArgVectors: PChar): BOOL; stdcall;
  613. {$EXTERNALSYM UnlockServiceDatabase}
  614. function UnlockServiceDatabase(ScLock: SC_LOCK): BOOL; stdcall;
  615.  
  616. implementation
  617.  
  618. const
  619.   advapi32 = 'advapi32.dll';
  620.  
  621. function ChangeServiceConfigA;   external advapi32 name 'ChangeServiceConfigA';
  622. function ChangeServiceConfigW;   external advapi32 name 'ChangeServiceConfigW';
  623. function ChangeServiceConfig;   external advapi32 name 'ChangeServiceConfigA';
  624. function CloseServiceHandle;       external advapi32 name 'CloseServiceHandle';
  625. function ControlService;           external advapi32 name 'ControlService';
  626. function CreateServiceA;         external advapi32 name 'CreateServiceA';
  627. function CreateServiceW;         external advapi32 name 'CreateServiceW';
  628. function CreateService;         external advapi32 name 'CreateServiceA';
  629. function DeleteService;            external advapi32 name 'DeleteService';
  630. function EnumDependentServicesA; external advapi32 name 'EnumDependentServicesA';
  631. function EnumDependentServicesW; external advapi32 name 'EnumDependentServicesW';
  632. function EnumDependentServices; external advapi32 name 'EnumDependentServicesA';
  633. function EnumServicesStatusA;    external advapi32 name 'EnumServicesStatusA';
  634. function EnumServicesStatusW;    external advapi32 name 'EnumServicesStatusW';
  635. function EnumServicesStatus;    external advapi32 name 'EnumServicesStatusA';
  636. function GetServiceKeyNameA;     external advapi32 name 'GetServiceKeyNameA';
  637. function GetServiceKeyNameW;     external advapi32 name 'GetServiceKeyNameW';
  638. function GetServiceKeyName;     external advapi32 name 'GetServiceKeyNameA';
  639. function GetServiceDisplayNameA; external advapi32 name 'GetServiceDisplayNameA';
  640. function GetServiceDisplayNameW; external advapi32 name 'GetServiceDisplayNameW';
  641. function GetServiceDisplayName; external advapi32 name 'GetServiceDisplayNameA';
  642. function LockServiceDatabase;      external advapi32 name 'LockServiceDatabase';
  643. function NotifyBootConfigStatus;   external advapi32 name 'NotifyBootConfigStatus';
  644. function OpenSCManagerA;         external advapi32 name 'OpenSCManagerA';
  645. function OpenSCManagerW;         external advapi32 name 'OpenSCManagerW';
  646. function OpenSCManager;         external advapi32 name 'OpenSCManagerA';
  647. function OpenServiceA;           external advapi32 name 'OpenServiceA';
  648. function OpenServiceW;           external advapi32 name 'OpenServiceW';
  649. function OpenService;           external advapi32 name 'OpenServiceA';
  650. function QueryServiceConfigA;    external advapi32 name 'QueryServiceConfigA';
  651. function QueryServiceConfigW;    external advapi32 name 'QueryServiceConfigW';
  652. function QueryServiceConfig;    external advapi32 name 'QueryServiceConfigA';
  653. function QueryServiceLockStatusA;external advapi32 name 'QueryServiceLockStatusA';
  654. function QueryServiceLockStatusW;external advapi32 name 'QueryServiceLockStatusW';
  655. function QueryServiceLockStatus;external advapi32 name 'QueryServiceLockStatusA';
  656. function QueryServiceObjectSecurity;external advapi32 name 'QueryServiceObjectSecurity';
  657. function QueryServiceStatus;       external advapi32 name 'QueryServiceStatus';
  658. function RegisterServiceCtrlHandlerA;external advapi32 name 'RegisterServiceCtrlHandlerA';
  659. function RegisterServiceCtrlHandlerW;external advapi32 name 'RegisterServiceCtrlHandlerW';
  660. function RegisterServiceCtrlHandler;external advapi32 name 'RegisterServiceCtrlHandlerA';
  661. function SetServiceObjectSecurity; external advapi32 name 'SetServiceObjectSecurity';
  662. function SetServiceStatus;         external advapi32 name 'SetServiceStatus';
  663. function StartServiceCtrlDispatcherA;external advapi32 name 'StartServiceCtrlDispatcherA';
  664. function StartServiceCtrlDispatcherW;external advapi32 name 'StartServiceCtrlDispatcherW';
  665. function StartServiceCtrlDispatcher;external advapi32 name 'StartServiceCtrlDispatcherA';
  666. function StartServiceA;          external advapi32 name 'StartServiceA';
  667. function StartServiceW;          external advapi32 name 'StartServiceW';
  668. function StartService;          external advapi32 name 'StartServiceA';
  669. function UnlockServiceDatabase;    external advapi32 name 'UnlockServiceDatabase';
  670.  
  671. end.
  672.  
  673.