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.

125 lines
4.5 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // Progress.h
  4. //
  5. // Progress dialog to Start, Stop, Pause and Resume a service.
  6. //
  7. // HISTORY
  8. // 03-Oct-95 t-danmo Creation of (sysmgmt\dsui\services\progress.cxx)
  9. // 01-Oct-96 t-danmo Renaming of progress.cxx and adaptation to slate.
  10. //
  11. #define SERVICE_CONTROL_RESTART 10 // Stop and then Start the service
  12. /////////////////////////////////////////////////////////////////////////////
  13. class CServiceControlProgress
  14. {
  15. protected:
  16. enum { IDD = IDD_SERVICE_CONTROL_PROGRESS }; // Id of the dialog used
  17. enum { ID_TIMER = 1 }; // Id of the timer
  18. enum { dwTimerTickIncrement = 400 }; // Length of a timer tick (in milliseconds)
  19. enum { dwTimerTimeout = 125000 }; // Timeout in milliseconds before aborting
  20. enum { dwTimerProgressDone = 5000 }; // Estimate of time to complete the operation
  21. protected:
  22. // Run-time UI variables
  23. HWND m_hWndParent; // Parent window of the dialog box
  24. HWND m_hctlActionMsg; // Handle of action static control
  25. HWND m_hctlServiceNameMsg; // Handle of service name static control
  26. HWND m_hctlProgress; // Handle of progress bar
  27. UINT m_iServiceAction; // Index of action to take (start, stop, pause or resume)
  28. UINT_PTR m_uTimerId; // Dynamic timer Id
  29. UINT m_dwTimerTicks; // Number of milliseconds the timer has been ticking
  30. // Variables needed for the threadproc
  31. HANDLE m_hThread;
  32. HANDLE m_hEvent;
  33. BOOL m_fCanQueryStatus;
  34. DWORD m_dwQueryState; // Service state to query when pooling
  35. SC_HANDLE m_hScManager; // Handle to service control manager database
  36. SC_HANDLE m_hService; // Handle of the opened service
  37. TCHAR m_szUiMachineName[256]; // Name of the computer in a friendly way
  38. TCHAR m_szServiceName[256]; // Service name
  39. TCHAR m_szServiceDisplayName[256]; // Display name of service
  40. DWORD m_dwDesiredAccess;
  41. // Variables used by ::StartService()
  42. DWORD m_dwNumServiceArgs; // Number of arguments
  43. LPCTSTR * m_lpServiceArgVectors; // Address of array of argument string pointers
  44. // Variables used by ::ControlService()
  45. DWORD m_dwControlCode; // Control code
  46. // Variables used by ::ControlService(SERVICE_CONTROL_STOP)
  47. BOOL m_fPulseEvent; // TRUE => Call PulseEvent() instead of closing the dialog
  48. BOOL m_fRestartService; // TRUE => Stop the service first, then start it again.
  49. INT m_iDependentServiceIter; // Index of the current dependent service
  50. INT m_cDependentServices; // Number of dependent services
  51. ENUM_SERVICE_STATUS * m_pargDependentServicesT; // Allocated array of dependent services
  52. ENUM_SERVICE_STATUS * m_pargServiceStop; // Allocated array of services to stop
  53. APIERR m_dwLastError; // Error code from GetLastError()
  54. public:
  55. CServiceControlProgress(); // Constructor
  56. ~CServiceControlProgress(); // Destructor
  57. BOOL M_FInit(
  58. HWND hwndParent,
  59. SC_HANDLE hScManager,
  60. LPCTSTR pszMachineName,
  61. LPCTSTR pszServiceName,
  62. LPCTSTR pszServiceDisplayName);
  63. protected:
  64. BOOL M_FDlgStopDependentServices();
  65. void M_UpdateDialogUI(LPCTSTR pszDisplayName);
  66. BOOL M_FGetNextService(OUT LPCTSTR * ppszServiceName, OUT LPCTSTR * ppszDisplayName);
  67. DWORD M_QueryCurrentServiceState();
  68. APIERR M_EControlService(DWORD dwControlCode);
  69. APIERR M_EDoExecuteServiceThread(void * pThreadProc);
  70. void M_ProcessErrorCode();
  71. void M_DoThreadCleanup();
  72. protected:
  73. static DWORD S_ThreadProcStartService(CServiceControlProgress * pThis);
  74. static DWORD S_ThreadProcStopService(CServiceControlProgress * pThis);
  75. static DWORD S_ThreadProcPauseResumeService(CServiceControlProgress * pThis);
  76. static BOOL CALLBACK S_DlgProcControlService(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  77. static BOOL CALLBACK S_DlgProcDependentServices(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  78. void M_OnInitDialog(HWND hdlg);
  79. void M_OnTimer(HWND hdlg);
  80. public:
  81. enum // Error codes for variable m_dwLastError (arbitrary chosen)
  82. {
  83. errCannotInitialize = 123456, // Failed to initialize object
  84. errUserCancelStopDependentServices, // User changed its mind (only used when stop service)
  85. errUserAbort, // User aborted operation
  86. };
  87. static APIERR S_EStartService(
  88. HWND hwndParent,
  89. SC_HANDLE hScManager,
  90. LPCTSTR pszMachineName,
  91. LPCTSTR pszServiceName,
  92. LPCTSTR pszServiceDisplayName,
  93. DWORD dwNumServiceArgs,
  94. LPCTSTR * lpServiceArgVectors);
  95. static APIERR S_EControlService(
  96. HWND hwndParent,
  97. SC_HANDLE hScManager,
  98. LPCTSTR pszMachineName,
  99. LPCTSTR pszServiceName,
  100. LPCTSTR pszServiceDisplayName,
  101. DWORD dwControlCode);
  102. }; // CServiceControlProgress