LVITEM item;\r
DWORD BytesNeeded = 0;\r
DWORD Loop = 5; //FIXME: testing value. needs better control\r
+ DWORD dwStartTickCount, dwOldCheckPoint;\r
\r
item.mask = LVIF_PARAM;\r
item.iItem = GetSelectedItem();\r
return FALSE;\r
}\r
\r
+ /* Save the tick count and initial checkpoint. */\r
+ dwStartTickCount = GetTickCount();\r
+ dwOldCheckPoint = ServiceStatus.dwCheckPoint;\r
+\r
/* loop whilst service is not running */\r
/* FIXME: needs more control adding. 'Loop' is temparary */\r
while (ServiceStatus.dwCurrentState != Control || !Loop)\r
{\r
+ DWORD dwWaitTime;\r
+\r
+ dwWaitTime = ServiceStatus.dwWaitHint / 10;\r
+\r
+ if( dwWaitTime < 500 )\r
+ dwWaitTime = 500;\r
+ else if ( dwWaitTime > 5000 )\r
+ dwWaitTime = 5000;\r
+\r
/* increment the progress bar */\r
SendMessage(hProgBar, PBM_STEPIT, 0, 0);\r
\r
/* wait before checking status */\r
- Sleep(ServiceStatus.dwWaitHint / 8);\r
+ Sleep(dwWaitTime);\r
\r
/* check status again */\r
if (! QueryServiceStatusEx(\r
GetError(0);\r
return FALSE;\r
}\r
- Loop--;\r
+ \r
+ if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)\r
+ {\r
+ /* The service is making progress. increment the progress bar */\r
+ SendMessage(hProgBar, PBM_STEPIT, 0, 0);\r
+ dwStartTickCount = GetTickCount();\r
+ dwOldCheckPoint = ServiceStatus.dwCheckPoint;\r
+ }\r
+ else\r
+ {\r
+ if(GetTickCount() - dwStartTickCount > ServiceStatus.dwWaitHint)\r
+ {\r
+ /* No progress made within the wait hint */\r
+ break;\r
+ }\r
+ }\r
}\r
\r
CloseServiceHandle(hSc);\r
SC_HANDLE hSc = NULL;\r
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;\r
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;\r
- LVITEM item;\r
DWORD BytesNeeded = 0;\r
\r
- item.mask = LVIF_PARAM;\r
- item.iItem = GetSelectedItem();\r
- SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);\r
-\r
/* copy pointer to selected service */\r
- Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;\r
+ Service = GetSelectedService();\r
\r
/* open handle to the SCM */\r
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);\r
SC_HANDLE hSc;\r
SERVICE_STATUS_PROCESS ServiceStatus;\r
ENUM_SERVICE_STATUS_PROCESS *Service = NULL;\r
- LVITEM item;\r
DWORD BytesNeeded = 0;\r
INT ArgCount = 0;\r
DWORD Loop = 5; //FIXME: testing value. needs better control\r
-\r
- item.mask = LVIF_PARAM;\r
- item.iItem = GetSelectedItem();\r
- SendMessage(hListView, LVM_GETITEM, 0, (LPARAM)&item);\r
+ DWORD dwStartTickCount, dwOldCheckPoint;\r
\r
/* copy pointer to selected service */\r
- Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam;\r
+ Service = GetSelectedService();\r
\r
/* set the progress bar range and step */\r
hProgBar = GetDlgItem(hProgDlg, IDC_SERVCON_PROGRESS);\r
return FALSE;\r
}\r
\r
+ /* Save the tick count and initial checkpoint. */\r
+ dwStartTickCount = GetTickCount();\r
+ dwOldCheckPoint = ServiceStatus.dwCheckPoint;\r
+\r
/* loop whilst service is not running */\r
/* FIXME: needs more control adding. 'Loop' is temparary */\r
while (ServiceStatus.dwCurrentState != SERVICE_RUNNING || !Loop)\r
{\r
+ DWORD dwWaitTime;\r
+\r
+ dwWaitTime = ServiceStatus.dwWaitHint / 10;\r
+\r
+ if( dwWaitTime < 500 )\r
+ dwWaitTime = 500;\r
+ else if ( dwWaitTime > 5000 )\r
+ dwWaitTime = 5000;\r
+\r
/* increment the progress bar */\r
SendMessage(hProgBar, PBM_STEPIT, 0, 0);\r
\r
GetError(0);\r
return FALSE;\r
}\r
- Loop--;\r
+ \r
+ if (ServiceStatus.dwCheckPoint > dwOldCheckPoint)\r
+ {\r
+ /* The service is making progress. increment the progress bar */\r
+ SendMessage(hProgBar, PBM_STEPIT, 0, 0);\r
+ dwStartTickCount = GetTickCount();\r
+ dwOldCheckPoint = ServiceStatus.dwCheckPoint;\r
+ }\r
+ else\r
+ {\r
+ if(GetTickCount() - dwStartTickCount > ServiceStatus.dwWaitHint)\r
+ {\r
+ /* No progress made within the wait hint */\r
+ break;\r
+ }\r
+ }\r
}\r
\r
CloseServiceHandle(hSc);\r