Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

654 lines
15 KiB

  1. /*++ BUILD Version: 0010 // Increment this if a change has global effects
  2. Copyright (c) 1995-1998 Microsoft Corporation
  3. Module Name:
  4. winsvc.h
  5. Abstract:
  6. Header file for the Service Control Manager
  7. Environment:
  8. User Mode - Win32
  9. --*/
  10. #ifndef _WINSVC_
  11. #define _WINSVC_
  12. //
  13. // Define API decoration for direct importing of DLL references.
  14. //
  15. #if !defined(WINADVAPI)
  16. #if !defined(_ADVAPI32_)
  17. #define WINADVAPI DECLSPEC_IMPORT
  18. #else
  19. #define WINADVAPI
  20. #endif
  21. #endif
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. //
  26. // Constants
  27. //
  28. //
  29. // Service database names
  30. //
  31. #define SERVICES_ACTIVE_DATABASEW L"ServicesActive"
  32. #define SERVICES_FAILED_DATABASEW L"ServicesFailed"
  33. #define SERVICES_ACTIVE_DATABASEA "ServicesActive"
  34. #define SERVICES_FAILED_DATABASEA "ServicesFailed"
  35. //
  36. // Character to designate that a name is a group
  37. //
  38. #define SC_GROUP_IDENTIFIERW L'+'
  39. #define SC_GROUP_IDENTIFIERA '+'
  40. #ifdef UNICODE
  41. #define SERVICES_ACTIVE_DATABASE SERVICES_ACTIVE_DATABASEW
  42. #define SERVICES_FAILED_DATABASE SERVICES_FAILED_DATABASEW
  43. #define SC_GROUP_IDENTIFIER SC_GROUP_IDENTIFIERW
  44. #else // ndef UNICODE
  45. #define SERVICES_ACTIVE_DATABASE SERVICES_ACTIVE_DATABASEA
  46. #define SERVICES_FAILED_DATABASE SERVICES_FAILED_DATABASEA
  47. #define SC_GROUP_IDENTIFIER SC_GROUP_IDENTIFIERA
  48. #endif // ndef UNICODE
  49. //
  50. // Value to indicate no change to an optional parameter
  51. //
  52. #define SERVICE_NO_CHANGE 0xffffffff
  53. //
  54. // Service State -- for Enum Requests (Bit Mask)
  55. //
  56. #define SERVICE_ACTIVE 0x00000001
  57. #define SERVICE_INACTIVE 0x00000002
  58. #define SERVICE_STATE_ALL (SERVICE_ACTIVE | \
  59. SERVICE_INACTIVE)
  60. //
  61. // Controls
  62. //
  63. #define SERVICE_CONTROL_STOP 0x00000001
  64. #define SERVICE_CONTROL_PAUSE 0x00000002
  65. #define SERVICE_CONTROL_CONTINUE 0x00000003
  66. #define SERVICE_CONTROL_INTERROGATE 0x00000004
  67. #define SERVICE_CONTROL_SHUTDOWN 0x00000005
  68. #define SERVICE_CONTROL_PARAMCHANGE 0x00000006
  69. #define SERVICE_CONTROL_NETBINDADD 0x00000007
  70. #define SERVICE_CONTROL_NETBINDREMOVE 0x00000008
  71. #define SERVICE_CONTROL_NETBINDENABLE 0x00000009
  72. #define SERVICE_CONTROL_NETBINDDISABLE 0x0000000A
  73. #define SERVICE_CONTROL_DEVICEEVENT 0x0000000B
  74. #define SERVICE_CONTROL_HARDWAREPROFILECHANGE 0x0000000C
  75. #define SERVICE_CONTROL_POWEREVENT 0x0000000D
  76. #define SERVICE_CONTROL_SESSIONCHANGE 0x0000000E
  77. //
  78. // Service State -- for CurrentState
  79. //
  80. #define SERVICE_STOPPED 0x00000001
  81. #define SERVICE_START_PENDING 0x00000002
  82. #define SERVICE_STOP_PENDING 0x00000003
  83. #define SERVICE_RUNNING 0x00000004
  84. #define SERVICE_CONTINUE_PENDING 0x00000005
  85. #define SERVICE_PAUSE_PENDING 0x00000006
  86. #define SERVICE_PAUSED 0x00000007
  87. //
  88. // Controls Accepted (Bit Mask)
  89. //
  90. #define SERVICE_ACCEPT_STOP 0x00000001
  91. #define SERVICE_ACCEPT_PAUSE_CONTINUE 0x00000002
  92. #define SERVICE_ACCEPT_SHUTDOWN 0x00000004
  93. #define SERVICE_ACCEPT_PARAMCHANGE 0x00000008
  94. #define SERVICE_ACCEPT_NETBINDCHANGE 0x00000010
  95. #define SERVICE_ACCEPT_HARDWAREPROFILECHANGE 0x00000020
  96. #define SERVICE_ACCEPT_POWEREVENT 0x00000040
  97. #define SERVICE_ACCEPT_SESSIONCHANGE 0x00000080
  98. //
  99. // Service Control Manager object specific access types
  100. //
  101. #define SC_MANAGER_CONNECT 0x0001
  102. #define SC_MANAGER_CREATE_SERVICE 0x0002
  103. #define SC_MANAGER_ENUMERATE_SERVICE 0x0004
  104. #define SC_MANAGER_LOCK 0x0008
  105. #define SC_MANAGER_QUERY_LOCK_STATUS 0x0010
  106. #define SC_MANAGER_MODIFY_BOOT_CONFIG 0x0020
  107. #define SC_MANAGER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
  108. SC_MANAGER_CONNECT | \
  109. SC_MANAGER_CREATE_SERVICE | \
  110. SC_MANAGER_ENUMERATE_SERVICE | \
  111. SC_MANAGER_LOCK | \
  112. SC_MANAGER_QUERY_LOCK_STATUS | \
  113. SC_MANAGER_MODIFY_BOOT_CONFIG)
  114. //
  115. // Service object specific access type
  116. //
  117. #define SERVICE_QUERY_CONFIG 0x0001
  118. #define SERVICE_CHANGE_CONFIG 0x0002
  119. #define SERVICE_QUERY_STATUS 0x0004
  120. #define SERVICE_ENUMERATE_DEPENDENTS 0x0008
  121. #define SERVICE_START 0x0010
  122. #define SERVICE_STOP 0x0020
  123. #define SERVICE_PAUSE_CONTINUE 0x0040
  124. #define SERVICE_INTERROGATE 0x0080
  125. #define SERVICE_USER_DEFINED_CONTROL 0x0100
  126. #define SERVICE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
  127. SERVICE_QUERY_CONFIG | \
  128. SERVICE_CHANGE_CONFIG | \
  129. SERVICE_QUERY_STATUS | \
  130. SERVICE_ENUMERATE_DEPENDENTS | \
  131. SERVICE_START | \
  132. SERVICE_STOP | \
  133. SERVICE_PAUSE_CONTINUE | \
  134. SERVICE_INTERROGATE | \
  135. SERVICE_USER_DEFINED_CONTROL)
  136. //
  137. // Service flags for QueryServiceStatusEx
  138. //
  139. #define SERVICE_RUNS_IN_SYSTEM_PROCESS 0x00000001
  140. //
  141. // Info levels for ChangeServiceConfig2 and QueryServiceConfig2
  142. //
  143. #define SERVICE_CONFIG_DESCRIPTION 1
  144. #define SERVICE_CONFIG_FAILURE_ACTIONS 2
  145. //
  146. // Service description string
  147. //
  148. typedef struct _SERVICE_DESCRIPTION% {
  149. LPTSTR% lpDescription;
  150. } SERVICE_DESCRIPTION%, *LPSERVICE_DESCRIPTION%;
  151. //
  152. // Actions to take on service failure
  153. //
  154. typedef enum _SC_ACTION_TYPE {
  155. SC_ACTION_NONE = 0,
  156. SC_ACTION_RESTART = 1,
  157. SC_ACTION_REBOOT = 2,
  158. SC_ACTION_RUN_COMMAND = 3
  159. } SC_ACTION_TYPE;
  160. typedef struct _SC_ACTION {
  161. SC_ACTION_TYPE Type;
  162. DWORD Delay;
  163. } SC_ACTION, *LPSC_ACTION;
  164. typedef struct _SERVICE_FAILURE_ACTIONS% {
  165. DWORD dwResetPeriod;
  166. LPTSTR% lpRebootMsg;
  167. LPTSTR% lpCommand;
  168. DWORD cActions;
  169. #ifdef MIDL_PASS
  170. [size_is(cActions)]
  171. #endif
  172. SC_ACTION * lpsaActions;
  173. } SERVICE_FAILURE_ACTIONS%, *LPSERVICE_FAILURE_ACTIONS%;
  174. //
  175. // Handle Types
  176. //
  177. DECLARE_HANDLE(SC_HANDLE);
  178. typedef SC_HANDLE *LPSC_HANDLE;
  179. DECLARE_HANDLE(SERVICE_STATUS_HANDLE);
  180. //
  181. // Info levels for QueryServiceStatusEx
  182. //
  183. typedef enum _SC_STATUS_TYPE {
  184. SC_STATUS_PROCESS_INFO = 0
  185. } SC_STATUS_TYPE;
  186. //
  187. // Info levels for EnumServicesStatusEx
  188. //
  189. typedef enum _SC_ENUM_TYPE {
  190. SC_ENUM_PROCESS_INFO = 0
  191. } SC_ENUM_TYPE;
  192. //
  193. // Service Status Structures
  194. //
  195. typedef struct _SERVICE_STATUS {
  196. DWORD dwServiceType;
  197. DWORD dwCurrentState;
  198. DWORD dwControlsAccepted;
  199. DWORD dwWin32ExitCode;
  200. DWORD dwServiceSpecificExitCode;
  201. DWORD dwCheckPoint;
  202. DWORD dwWaitHint;
  203. } SERVICE_STATUS, *LPSERVICE_STATUS;
  204. typedef struct _SERVICE_STATUS_PROCESS {
  205. DWORD dwServiceType;
  206. DWORD dwCurrentState;
  207. DWORD dwControlsAccepted;
  208. DWORD dwWin32ExitCode;
  209. DWORD dwServiceSpecificExitCode;
  210. DWORD dwCheckPoint;
  211. DWORD dwWaitHint;
  212. DWORD dwProcessId;
  213. DWORD dwServiceFlags;
  214. } SERVICE_STATUS_PROCESS, *LPSERVICE_STATUS_PROCESS;
  215. //
  216. // Service Status Enumeration Structure
  217. //
  218. typedef struct _ENUM_SERVICE_STATUS% {
  219. LPTSTR% lpServiceName;
  220. LPTSTR% lpDisplayName;
  221. SERVICE_STATUS ServiceStatus;
  222. } ENUM_SERVICE_STATUS%, *LPENUM_SERVICE_STATUS%;
  223. typedef struct _ENUM_SERVICE_STATUS_PROCESS% {
  224. LPTSTR% lpServiceName;
  225. LPTSTR% lpDisplayName;
  226. SERVICE_STATUS_PROCESS ServiceStatusProcess;
  227. } ENUM_SERVICE_STATUS_PROCESS%, *LPENUM_SERVICE_STATUS_PROCESS%;
  228. //
  229. // Structures for the Lock API functions
  230. //
  231. typedef LPVOID SC_LOCK;
  232. typedef struct _QUERY_SERVICE_LOCK_STATUS% {
  233. DWORD fIsLocked;
  234. LPTSTR% lpLockOwner;
  235. DWORD dwLockDuration;
  236. } QUERY_SERVICE_LOCK_STATUS%, *LPQUERY_SERVICE_LOCK_STATUS%;
  237. //
  238. // Query Service Configuration Structure
  239. //
  240. typedef struct _QUERY_SERVICE_CONFIG% {
  241. DWORD dwServiceType;
  242. DWORD dwStartType;
  243. DWORD dwErrorControl;
  244. LPTSTR% lpBinaryPathName;
  245. LPTSTR% lpLoadOrderGroup;
  246. DWORD dwTagId;
  247. LPTSTR% lpDependencies;
  248. LPTSTR% lpServiceStartName;
  249. LPTSTR% lpDisplayName;
  250. } QUERY_SERVICE_CONFIG%, *LPQUERY_SERVICE_CONFIG%;
  251. //
  252. // Function Prototype for the Service Main Function
  253. //
  254. typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONW)(
  255. DWORD dwNumServicesArgs,
  256. LPWSTR *lpServiceArgVectors
  257. );
  258. typedef VOID (WINAPI *LPSERVICE_MAIN_FUNCTIONA)(
  259. DWORD dwNumServicesArgs,
  260. LPSTR *lpServiceArgVectors
  261. );
  262. #ifdef UNICODE
  263. #define LPSERVICE_MAIN_FUNCTION LPSERVICE_MAIN_FUNCTIONW
  264. #else
  265. #define LPSERVICE_MAIN_FUNCTION LPSERVICE_MAIN_FUNCTIONA
  266. #endif //UNICODE
  267. //
  268. // Service Start Table
  269. //
  270. typedef struct _SERVICE_TABLE_ENTRY% {
  271. LPTSTR% lpServiceName;
  272. LPSERVICE_MAIN_FUNCTION% lpServiceProc;
  273. }SERVICE_TABLE_ENTRY%, *LPSERVICE_TABLE_ENTRY%;
  274. //
  275. // Prototype for the Service Control Handler Function
  276. //
  277. typedef VOID (WINAPI *LPHANDLER_FUNCTION)(
  278. DWORD dwControl
  279. );
  280. typedef DWORD (WINAPI *LPHANDLER_FUNCTION_EX)(
  281. DWORD dwControl,
  282. DWORD dwEventType,
  283. LPVOID lpEventData,
  284. LPVOID lpContext
  285. );
  286. ///////////////////////////////////////////////////////////////////////////
  287. // API Function Prototypes
  288. ///////////////////////////////////////////////////////////////////////////
  289. WINADVAPI
  290. BOOL
  291. WINAPI
  292. ChangeServiceConfig%(
  293. SC_HANDLE hService,
  294. DWORD dwServiceType,
  295. DWORD dwStartType,
  296. DWORD dwErrorControl,
  297. LPCTSTR% lpBinaryPathName,
  298. LPCTSTR% lpLoadOrderGroup,
  299. LPDWORD lpdwTagId,
  300. LPCTSTR% lpDependencies,
  301. LPCTSTR% lpServiceStartName,
  302. LPCTSTR% lpPassword,
  303. LPCTSTR% lpDisplayName
  304. );
  305. WINADVAPI
  306. BOOL
  307. WINAPI
  308. ChangeServiceConfig2%(
  309. SC_HANDLE hService,
  310. DWORD dwInfoLevel,
  311. LPVOID lpInfo
  312. );
  313. WINADVAPI
  314. BOOL
  315. WINAPI
  316. CloseServiceHandle(
  317. SC_HANDLE hSCObject
  318. );
  319. WINADVAPI
  320. BOOL
  321. WINAPI
  322. ControlService(
  323. SC_HANDLE hService,
  324. DWORD dwControl,
  325. LPSERVICE_STATUS lpServiceStatus
  326. );
  327. WINADVAPI
  328. SC_HANDLE
  329. WINAPI
  330. CreateService%(
  331. SC_HANDLE hSCManager,
  332. LPCTSTR% lpServiceName,
  333. LPCTSTR% lpDisplayName,
  334. DWORD dwDesiredAccess,
  335. DWORD dwServiceType,
  336. DWORD dwStartType,
  337. DWORD dwErrorControl,
  338. LPCTSTR% lpBinaryPathName,
  339. LPCTSTR% lpLoadOrderGroup,
  340. LPDWORD lpdwTagId,
  341. LPCTSTR% lpDependencies,
  342. LPCTSTR% lpServiceStartName,
  343. LPCTSTR% lpPassword
  344. );
  345. WINADVAPI
  346. BOOL
  347. WINAPI
  348. DeleteService(
  349. SC_HANDLE hService
  350. );
  351. WINADVAPI
  352. BOOL
  353. WINAPI
  354. EnumDependentServices%(
  355. SC_HANDLE hService,
  356. DWORD dwServiceState,
  357. LPENUM_SERVICE_STATUS% lpServices,
  358. DWORD cbBufSize,
  359. LPDWORD pcbBytesNeeded,
  360. LPDWORD lpServicesReturned
  361. );
  362. WINADVAPI
  363. BOOL
  364. WINAPI
  365. EnumServicesStatus%(
  366. SC_HANDLE hSCManager,
  367. DWORD dwServiceType,
  368. DWORD dwServiceState,
  369. LPENUM_SERVICE_STATUS% lpServices,
  370. DWORD cbBufSize,
  371. LPDWORD pcbBytesNeeded,
  372. LPDWORD lpServicesReturned,
  373. LPDWORD lpResumeHandle
  374. );
  375. WINADVAPI
  376. BOOL
  377. WINAPI
  378. EnumServicesStatusEx%(
  379. SC_HANDLE hSCManager,
  380. SC_ENUM_TYPE InfoLevel,
  381. DWORD dwServiceType,
  382. DWORD dwServiceState,
  383. LPBYTE lpServices,
  384. DWORD cbBufSize,
  385. LPDWORD pcbBytesNeeded,
  386. LPDWORD lpServicesReturned,
  387. LPDWORD lpResumeHandle,
  388. LPCTSTR% pszGroupName
  389. );
  390. WINADVAPI
  391. BOOL
  392. WINAPI
  393. GetServiceKeyName%(
  394. SC_HANDLE hSCManager,
  395. LPCTSTR% lpDisplayName,
  396. LPTSTR% lpServiceName,
  397. LPDWORD lpcchBuffer
  398. );
  399. WINADVAPI
  400. BOOL
  401. WINAPI
  402. GetServiceDisplayName%(
  403. SC_HANDLE hSCManager,
  404. LPCTSTR% lpServiceName,
  405. LPTSTR% lpDisplayName,
  406. LPDWORD lpcchBuffer
  407. );
  408. WINADVAPI
  409. SC_LOCK
  410. WINAPI
  411. LockServiceDatabase(
  412. SC_HANDLE hSCManager
  413. );
  414. WINADVAPI
  415. BOOL
  416. WINAPI
  417. NotifyBootConfigStatus(
  418. BOOL BootAcceptable
  419. );
  420. WINADVAPI
  421. SC_HANDLE
  422. WINAPI
  423. OpenSCManager%(
  424. LPCTSTR% lpMachineName,
  425. LPCTSTR% lpDatabaseName,
  426. DWORD dwDesiredAccess
  427. );
  428. WINADVAPI
  429. SC_HANDLE
  430. WINAPI
  431. OpenService%(
  432. SC_HANDLE hSCManager,
  433. LPCTSTR% lpServiceName,
  434. DWORD dwDesiredAccess
  435. );
  436. WINADVAPI
  437. BOOL
  438. WINAPI
  439. QueryServiceConfig%(
  440. SC_HANDLE hService,
  441. LPQUERY_SERVICE_CONFIG% lpServiceConfig,
  442. DWORD cbBufSize,
  443. LPDWORD pcbBytesNeeded
  444. );
  445. WINADVAPI
  446. BOOL
  447. WINAPI
  448. QueryServiceConfig2%(
  449. SC_HANDLE hService,
  450. DWORD dwInfoLevel,
  451. LPBYTE lpBuffer,
  452. DWORD cbBufSize,
  453. LPDWORD pcbBytesNeeded
  454. );
  455. WINADVAPI
  456. BOOL
  457. WINAPI
  458. QueryServiceLockStatus%(
  459. SC_HANDLE hSCManager,
  460. LPQUERY_SERVICE_LOCK_STATUS% lpLockStatus,
  461. DWORD cbBufSize,
  462. LPDWORD pcbBytesNeeded
  463. );
  464. WINADVAPI
  465. BOOL
  466. WINAPI
  467. QueryServiceObjectSecurity(
  468. SC_HANDLE hService,
  469. SECURITY_INFORMATION dwSecurityInformation,
  470. PSECURITY_DESCRIPTOR lpSecurityDescriptor,
  471. DWORD cbBufSize,
  472. LPDWORD pcbBytesNeeded
  473. );
  474. WINADVAPI
  475. BOOL
  476. WINAPI
  477. QueryServiceStatus(
  478. SC_HANDLE hService,
  479. LPSERVICE_STATUS lpServiceStatus
  480. );
  481. WINADVAPI
  482. BOOL
  483. WINAPI
  484. QueryServiceStatusEx(
  485. SC_HANDLE hService,
  486. SC_STATUS_TYPE InfoLevel,
  487. LPBYTE lpBuffer,
  488. DWORD cbBufSize,
  489. LPDWORD pcbBytesNeeded
  490. );
  491. WINADVAPI
  492. SERVICE_STATUS_HANDLE
  493. WINAPI
  494. RegisterServiceCtrlHandler%(
  495. LPCTSTR% lpServiceName,
  496. LPHANDLER_FUNCTION lpHandlerProc
  497. );
  498. WINADVAPI
  499. SERVICE_STATUS_HANDLE
  500. WINAPI
  501. RegisterServiceCtrlHandlerEx%(
  502. LPCTSTR% lpServiceName,
  503. LPHANDLER_FUNCTION_EX lpHandlerProc,
  504. LPVOID lpContext
  505. );
  506. WINADVAPI
  507. BOOL
  508. WINAPI
  509. SetServiceObjectSecurity(
  510. SC_HANDLE hService,
  511. SECURITY_INFORMATION dwSecurityInformation,
  512. PSECURITY_DESCRIPTOR lpSecurityDescriptor
  513. );
  514. WINADVAPI
  515. BOOL
  516. WINAPI
  517. SetServiceStatus(
  518. SERVICE_STATUS_HANDLE hServiceStatus,
  519. LPSERVICE_STATUS lpServiceStatus
  520. );
  521. WINADVAPI
  522. BOOL
  523. WINAPI
  524. StartServiceCtrlDispatcher%(
  525. CONST SERVICE_TABLE_ENTRY% *lpServiceStartTable
  526. );
  527. WINADVAPI
  528. BOOL
  529. WINAPI
  530. StartService%(
  531. SC_HANDLE hService,
  532. DWORD dwNumServiceArgs,
  533. LPCTSTR% *lpServiceArgVectors
  534. );
  535. WINADVAPI
  536. BOOL
  537. WINAPI
  538. UnlockServiceDatabase(
  539. SC_LOCK ScLock
  540. );
  541. #ifdef __cplusplus
  542. }
  543. #endif
  544. #endif // _WINSVC_