2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/servman/control
5 * PURPOSE: Stops, pauses and resumes a service
6 * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
13 Control(PMAIN_WND_INFO Info
,
19 SERVICE_STATUS_PROCESS ServiceStatus
;
20 SERVICE_STATUS Status
;
22 DWORD BytesNeeded
= 0;
23 DWORD dwStartTickCount
, dwOldCheckPoint
;
25 item
.mask
= LVIF_PARAM
;
26 item
.iItem
= Info
->SelectedItem
;
27 SendMessage(Info
->hListView
,
32 /* set the progress bar range and step */
33 hProgBar
= GetDlgItem(Info
->hProgDlg
,
34 IDC_SERVCON_PROGRESS
);
38 MAKELPARAM(0, PROGRESSRANGE
));
45 /* open handle to the SCM */
46 hSCManager
= OpenSCManager(NULL
,
48 SC_MANAGER_ALL_ACCESS
);
49 if (hSCManager
== NULL
)
55 /* open handle to the service */
56 hSc
= OpenService(hSCManager
,
57 Info
->CurrentService
->lpServiceName
,
58 SC_MANAGER_ALL_ACCESS
);
65 /* process requested action */
66 if (! ControlService(hSc
,
71 CloseServiceHandle(hSc
);
75 /* query the state of the service */
76 if (! QueryServiceStatusEx(hSc
,
77 SC_STATUS_PROCESS_INFO
,
78 (LPBYTE
)&ServiceStatus
,
79 sizeof(SERVICE_STATUS_PROCESS
),
86 /* Save the tick count and initial checkpoint. */
87 dwStartTickCount
= GetTickCount();
88 dwOldCheckPoint
= ServiceStatus
.dwCheckPoint
;
90 /* loop whilst service is not running */
91 /* FIXME: needs more control adding. 'Loop' is temparary */
92 while (ServiceStatus
.dwCurrentState
!= Control
)
96 dwWaitTime
= ServiceStatus
.dwWaitHint
/ 10;
100 else if (dwWaitTime
> 5000)
103 /* increment the progress bar */
104 SendMessage(hProgBar
,
109 /* wait before checking status */
112 /* check status again */
113 if (! QueryServiceStatusEx(hSc
,
114 SC_STATUS_PROCESS_INFO
,
115 (LPBYTE
)&ServiceStatus
,
116 sizeof(SERVICE_STATUS_PROCESS
),
123 if (ServiceStatus
.dwCheckPoint
> dwOldCheckPoint
)
125 /* The service is making progress. increment the progress bar */
126 SendMessage(hProgBar
,
130 dwStartTickCount
= GetTickCount();
131 dwOldCheckPoint
= ServiceStatus
.dwCheckPoint
;
135 if(GetTickCount() - dwStartTickCount
> ServiceStatus
.dwWaitHint
)
137 /* No progress made within the wait hint */
143 CloseServiceHandle(hSc
);
145 if (ServiceStatus
.dwCurrentState
== Control
)
147 SendMessage(hProgBar
,