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.

251 lines
7.0 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /**********************************************************************/
  5. /*
  6. scman.hxx
  7. Header file for SC manager class and SC service class.
  8. FILE HISTORY:
  9. terryk 05-May-1992 Created
  10. KeithMo 11-Nov-1992 Added DisplayName goodies.
  11. */
  12. #ifndef _SCMAN_HXX_
  13. #define _SCMAN_HXX_
  14. #include "base.hxx"
  15. #include "string.hxx"
  16. extern "C"
  17. {
  18. #include <winsvc.h>
  19. }
  20. //
  21. // SC Manager database selection: either Active or Failed database.
  22. //
  23. typedef enum
  24. {
  25. ACTIVE,
  26. FAILED
  27. } SERVICE_DATABASE;
  28. /*************************************************************************
  29. NAME: SERVICE_CONTROL
  30. SYNOPSIS: Parent class of SC_MANAGER and SC_SERVICE. It is used to
  31. handle the set and query handle.
  32. INTERFACE: SERVICE_CONTROL() - constructor
  33. APIERR Close() - close the handle
  34. SC_HANDLE QueryHandle() - return the handle.
  35. VOID SetHandle() - set the object handle.
  36. PARENT: BASE
  37. HISTORY:
  38. terryk 05-May-1992 Created
  39. **************************************************************************/
  40. DLL_CLASS SERVICE_CONTROL : public BASE
  41. {
  42. private:
  43. SC_HANDLE _hHandle;
  44. protected:
  45. BUFFER _buffer;
  46. VOID SetHandle( SC_HANDLE hHandle )
  47. { _hHandle = hHandle; };
  48. public:
  49. SERVICE_CONTROL();
  50. SC_HANDLE QueryHandle() const
  51. { return _hHandle; };
  52. const BUFFER & QueryBuffer( VOID ) const
  53. { return _buffer; }
  54. APIERR Close();
  55. };
  56. /*************************************************************************
  57. NAME: SC_MANAGER
  58. SYNOPSIS: Wrapper class for registry sc manager object.
  59. INTERFACE: SC_MANAGER() - constructor
  60. ~SC_MANAGER() - destructor
  61. APIERR Lock() - lock the current sc manager object
  62. APIERR Unlock() - unlock the current sc manager object
  63. APIERR QueryLockStatus() - get current lock information
  64. APIERR EnumServiceStatus() - enumerate services in the
  65. service control manager database along with the status of
  66. each service.
  67. APIERR UpdateLastKnownGood() - update the last-know-good
  68. configuration which the system was booted from.
  69. PARENT: SERVICE_CONTROL
  70. HISTORY:
  71. terryk 05-May-1992
  72. **************************************************************************/
  73. DLL_CLASS SC_MANAGER : public SERVICE_CONTROL
  74. {
  75. private:
  76. SC_LOCK _scLock;
  77. BOOL _fOwnerAlloc ;
  78. public:
  79. SC_MANAGER(
  80. const TCHAR * pszMachineName,
  81. UINT dwAccess,
  82. SERVICE_DATABASE database = ACTIVE );
  83. // Constructor using a preexisting SC_HANDLE
  84. SC_MANAGER ( SC_HANDLE hSvcCtrl ) ;
  85. // it will close the handle as well
  86. ~SC_MANAGER();
  87. // lock functions
  88. APIERR Lock();
  89. APIERR Unlock();
  90. APIERR QueryLockStatus(
  91. LPQUERY_SERVICE_LOCK_STATUS *ppLockStatus );
  92. //
  93. // NOTE: pszGroupName should only be used when enumerating the services
  94. // on the local machine (or if you know the remote machine is NT 4.0+
  95. // and supports the EnumServiceGroup() API.)
  96. //
  97. APIERR EnumServiceStatus(
  98. UINT dwServiceType,
  99. UINT dwServiceState,
  100. LPENUM_SERVICE_STATUS *ppServices,
  101. DWORD * lpServicesReturned,
  102. const TCHAR * pszGroupName = NULL );
  103. APIERR QueryServiceDisplayName( const TCHAR * pszKeyName,
  104. NLS_STR * pnlsDisplayName );
  105. APIERR QueryServiceKeyName( const TCHAR * pszDisplayName,
  106. NLS_STR * pnlsKeyName );
  107. #ifdef _BUILD_263_
  108. APIERR UpdateLastKnownGood();
  109. #endif
  110. };
  111. /*************************************************************************
  112. NAME: SC_SERVICE
  113. SYNOPSIS: wrapper class for service object in the registry SC manager
  114. database.
  115. INTERFACE: SC_SERVICE() - constructor
  116. ~SC_SERVICE() - destructor
  117. APIERR QueryConfig() - examine the service configuration
  118. parameters.
  119. APIERR ChangeConfig() - change the service configuration
  120. parameters
  121. APIERR QuerySecurity() - examine the security descriptor of a
  122. service object.
  123. APIERR SetSecurity() - modify the security descriptor of a
  124. service object.
  125. APIERR QueryStatus() - exmaind the service status
  126. APIERR Control() - sends a control to a serivce
  127. APIERR Start() - start the execution of a service
  128. APIERR Delete() - remove the service from the service control
  129. manager database.
  130. APIERR EnumDependent() - enumerate services that depend on the
  131. specified service.
  132. PARENT: SERVICE_CONTROL
  133. HISTORY:
  134. terryk 05-May-1992
  135. **************************************************************************/
  136. DLL_CLASS SC_SERVICE : public SERVICE_CONTROL
  137. {
  138. public:
  139. SC_SERVICE(
  140. const SC_MANAGER & scManager,
  141. const TCHAR *pszServiceName,
  142. UINT dwAccess = GENERIC_READ | GENERIC_EXECUTE );
  143. SC_SERVICE(
  144. const SC_MANAGER & scManager,
  145. const TCHAR *pszServiceName,
  146. const TCHAR *pszDisplayName,
  147. UINT dwServiceType,
  148. UINT dwStartType,
  149. UINT dwErrorControl,
  150. const TCHAR *pszBinaryPathName,
  151. const TCHAR *pszLoadOrderGroup,
  152. const TCHAR *pszDependencies,
  153. const TCHAR *pszServiceStartName,
  154. const TCHAR *pszPassword,
  155. UINT dwAccess = GENERIC_READ | GENERIC_EXECUTE );
  156. ~SC_SERVICE();
  157. // configuration methods
  158. APIERR ChangeConfig(
  159. UINT dwServiceType,
  160. UINT dwStartType,
  161. UINT dwErrorControl,
  162. const TCHAR *pszBinaryPathName = NULL,
  163. const TCHAR *pszLoadOrderGroup = NULL,
  164. const TCHAR *pszDependencies = NULL,
  165. const TCHAR *pszServiceStartName = NULL,
  166. const TCHAR *pszPassword = NULL,
  167. const TCHAR *pszDisplayName = NULL );
  168. APIERR QueryConfig(
  169. LPQUERY_SERVICE_CONFIG *ppServiceConfig );
  170. // security methods
  171. APIERR QuerySecurity(
  172. SECURITY_INFORMATION dwSecurityInformation,
  173. PSECURITY_DESCRIPTOR *ppSecurityDescriptor );
  174. APIERR SetSecurity(
  175. SECURITY_INFORMATION dwSecurityInformation,
  176. const PSECURITY_DESCRIPTOR lpSecurityDescriptor );
  177. // misc. methods
  178. APIERR QueryStatus( LPSERVICE_STATUS lpServiceStatus );
  179. APIERR Start(
  180. UINT dwNumServiceArgs,
  181. const TCHAR ** ppszServiceArgs );
  182. APIERR Delete();
  183. APIERR Control(
  184. UINT dwControl,
  185. LPSERVICE_STATUS lpServiceStatus );
  186. APIERR EnumDependent(
  187. UINT dwServiceState,
  188. LPENUM_SERVICE_STATUS *ppServiceStatus,
  189. DWORD * lpServiceReturned );
  190. };
  191. #endif // _SCMAN_HXX_