Leaked source code of windows server 2003
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.

71 lines
1.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: smartsvc.hxx
  7. //
  8. // Contents: Smart service controller
  9. //
  10. // History: 01 May 1997 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. //
  15. // smart pointer class for SC_HANDLEs
  16. //
  17. class CServiceHandle
  18. {
  19. public :
  20. CServiceHandle() { _h = 0; }
  21. CServiceHandle( SC_HANDLE hSC ) : _h( hSC ) {}
  22. ~CServiceHandle() { Free(); }
  23. void Set( SC_HANDLE h ) { _h = h; }
  24. SC_HANDLE Get() { return _h; }
  25. BOOL IsOk() { return (0 != _h); }
  26. void Free()
  27. {
  28. if ( IsOk() )
  29. CloseServiceHandle( _h );
  30. _h = 0;
  31. }
  32. private:
  33. SC_HANDLE _h;
  34. };
  35. //+-------------------------------------------------------------------------
  36. //
  37. // Function: WaitForSvc
  38. //
  39. // Synopsis: Stops a given service
  40. //
  41. // Arguments: xSC -- the service control manager
  42. // pwcSVC -- name of the service to stop
  43. //
  44. // Returns: TRUE if the service was stopped
  45. //
  46. // History: 8-Jan-97 dlee Created
  47. //
  48. //--------------------------------------------------------------------------
  49. inline BOOL WaitForSvc( CServiceHandle &x )
  50. {
  51. SERVICE_STATUS svcStatus;
  52. if ( QueryServiceStatus( x.Get(), &svcStatus ) )
  53. return SERVICE_STOP_PENDING == svcStatus.dwCurrentState ||
  54. SERVICE_RUNNING == svcStatus.dwCurrentState ||
  55. SERVICE_PAUSED == svcStatus.dwCurrentState;
  56. return FALSE;
  57. } //WaitForSvc