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.

197 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. control.h
  5. Abstract:
  6. This file contains data structures and function prototypes for the
  7. Service Controller Control Interface.
  8. Author:
  9. Dan Lafferty (danl) 28-Mar-1991
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. 28-Mar-1991 danl
  14. created
  15. --*/
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //
  20. // Internal controls.
  21. // These must not be in the range or public controls ( 1-10)
  22. // or in the range of user-defined controls (0x00000080 - 0x000000ff)
  23. //
  24. //
  25. // Range for OEM defined control opcodes
  26. //
  27. #define OEM_LOWER_LIMIT 128
  28. #define OEM_UPPER_LIMIT 255
  29. //
  30. // Used to start a service that shares a process with other services.
  31. //
  32. #define SERVICE_CONTROL_START_SHARE 0x00000050 // INTERNAL
  33. //
  34. // Used to start a service that has its own process.
  35. //
  36. #define SERVICE_CONTROL_START_OWN 0x00000051 // INTERNAL
  37. //
  38. // Private access level for OpenService to get a context handle for SetServiceStatus.
  39. // This MUST NOT CONFLICT with the access levels in winsvc.h.
  40. //
  41. #define SERVICE_SET_STATUS 0x8000 // INTERNAL
  42. //
  43. // Service controls that can be passed to a non-EX control handler. Relies
  44. // on ordering/values of SERVICE_CONTROL_* constants in winsvc.h.
  45. //
  46. #define IS_NON_EX_CONTROL(dwControl) \
  47. ((dwControl >= SERVICE_CONTROL_STOP && dwControl <= SERVICE_CONTROL_NETBINDDISABLE) \
  48. || \
  49. (dwControl >= OEM_LOWER_LIMIT && dwControl <= OEM_UPPER_LIMIT))
  50. //
  51. // Data Structures
  52. //
  53. //
  54. // The control message has the following format:
  55. // [MessageHeader][ServiceNameString][CmdArg1Ptr][CmdArg2Ptr]
  56. // [...][CmdArgnPtr][CmdArg1String][CmdArg2String][...][CmdArgnString]
  57. //
  58. // Where CmdArg pointers are replaced with offsets that are relative to
  59. // the location of the 1st command arg pointer (the top of the argv list).
  60. //
  61. // In the header, the NumCmdArgs, StatusHandle, and ArgvOffset parameters
  62. // are only used when the SERVICE_START OpCode is passed in. They are
  63. // expected to be 0 at all other times. The ServiceNameOffset and the
  64. // ArgvOffset are relative to the top of the buffer containing the
  65. // message (ie. the header Count field). The Count field in the header
  66. // contains the number of bytes in the entire message (including the
  67. // header).
  68. //
  69. //
  70. typedef struct _CTRL_MSG_HEADER
  71. {
  72. DWORD Count; // num bytes in buffer.
  73. DWORD OpCode; // control opcode.
  74. DWORD NumCmdArgs; // number of command Args.
  75. DWORD ServiceNameOffset; // pointer to ServiceNameString
  76. DWORD ArgvOffset; // pointer to Argument Vectors.
  77. }
  78. CTRL_MSG_HEADER, *PCTRL_MSG_HEADER, *LPCTRL_MSG_HEADER;
  79. typedef struct _PIPE_RESPONSE_MSG
  80. {
  81. DWORD dwDispatcherStatus;
  82. DWORD dwHandlerRetVal;
  83. }
  84. PIPE_RESPONSE_MSG, *PPIPE_RESPONSE_MSG, *LPPIPE_RESPONSE_MSG;
  85. typedef struct _PNP_ARGUMENTS
  86. {
  87. DWORD dwEventType;
  88. DWORD dwEventDataSize;
  89. PVOID EventData;
  90. }
  91. PNP_ARGUMENTS, *PPNP_ARGUMENTS, *LPPNP_ARGUMENTS;
  92. //
  93. // Union to hold arguments to ScSendControl
  94. //
  95. typedef union _CONTROL_ARGS {
  96. LPWSTR *CmdArgs;
  97. PNP_ARGUMENTS PnPArgs;
  98. } CONTROL_ARGS, *PCONTROL_ARGS, *LPCONTROL_ARGS;
  99. //
  100. // Defines and Typedefs
  101. //
  102. #define CONTROL_PIPE_NAME L"\\\\.\\pipe\\net\\NtControlPipe"
  103. #define PID_LEN 10 // Max PID (DWORD_MAX) is 10 digits
  104. #define CONTROL_TIMEOUT 30000 // timeout for waiting for pipe.
  105. #define RESPONSE_WAIT_TIME 5000 // wait until service response.
  106. //
  107. // Function Prototypes
  108. //
  109. DWORD
  110. ScCreateControlInstance (
  111. OUT LPHANDLE PipeHandlePtr,
  112. IN DWORD dwProcessId,
  113. IN PSID pAccountSid
  114. );
  115. VOID
  116. ScDeleteControlInstance (
  117. IN HANDLE PipeHandle
  118. );
  119. DWORD
  120. ScWaitForConnect (
  121. IN HANDLE PipeHandle,
  122. IN HANDLE hProcess OPTIONAL,
  123. IN LPWSTR lpDisplayName,
  124. OUT LPDWORD ProcessIdPtr
  125. );
  126. DWORD
  127. ScSendControl (
  128. IN LPWSTR ServiceName,
  129. IN LPWSTR DisplayName,
  130. IN HANDLE PipeHandle,
  131. IN DWORD OpCode,
  132. IN LPCONTROL_ARGS lpControlArgs OPTIONAL,
  133. IN DWORD NumArgs,
  134. OUT LPDWORD lpdwHandlerRetVal OPTIONAL
  135. );
  136. VOID
  137. ScShutdownAllServices(
  138. VOID
  139. );
  140. DWORD
  141. ScSendPnPMessage(
  142. IN SERVICE_STATUS_HANDLE hServiceStatus,
  143. IN DWORD OpCode,
  144. IN DWORD dwEventType,
  145. IN LPARAM EventData,
  146. OUT LPDWORD lpdwHandlerRetVal
  147. );
  148. DWORD
  149. ScValidatePnPService(
  150. IN LPWSTR lpServiceName,
  151. OUT SERVICE_STATUS_HANDLE *lphServiceStatus
  152. );
  153. #ifdef __cplusplus
  154. }
  155. #endif