29#define WIN32_LEAN_AND_MEAN
37 SERVICE_STATUS status;
39 if (ControlService(hService, SERVICE_CONTROL_STOP, &status))
42 if (QueryServiceStatus(hService, &status))
44 DWORD startTime = GetTickCount();
45 DWORD oldCheckPoint = status.dwCheckPoint;
47 while (status.dwCurrentState == SERVICE_STOP_PENDING)
52 DWORD waitTime = status.dwWaitHint / 10;
56 else if (waitTime > 10000)
62 if (!QueryServiceStatus(hService, &status) ||
63 (status.dwCurrentState == SERVICE_STOPPED))
66 if (status.dwCheckPoint > oldCheckPoint)
68 startTime = GetTickCount();
69 oldCheckPoint = status.dwCheckPoint;
71 else if ((GetTickCount() - startTime) > status.dwWaitHint)
78 return (status.dwCurrentState == SERVICE_STOPPED);
83 if (StartServiceW(hService, 0,
nullptr))
85 SERVICE_STATUS status;
88 if (QueryServiceStatus(hService, &status))
90 DWORD startTime = GetTickCount();
91 DWORD oldCheckPoint = status.dwCheckPoint;
93 while (status.dwCurrentState == SERVICE_START_PENDING)
98 DWORD waitTime = status.dwWaitHint / 10;
102 else if (waitTime > 10000)
108 if (!QueryServiceStatus(hService, &status) ||
109 (status.dwCurrentState == SERVICE_STOPPED))
112 if (status.dwCheckPoint > oldCheckPoint)
114 startTime = GetTickCount();
115 oldCheckPoint = status.dwCheckPoint;
117 else if ((GetTickCount() - startTime) > status.dwWaitHint)
127extern "C" __declspec(dllexport) UINT __stdcall RestartIndexingService(MSIHANDLE)
129 SC_HANDLE hSCManager = OpenSCManagerW(
132 SC_MANAGER_ALL_ACCESS);
134 if (hSCManager !=
nullptr)
136 SC_HANDLE hIndexingService = OpenServiceW(
139 if (hIndexingService)
141 SERVICE_STATUS status;
142 ZeroMemory(&status,
sizeof(status));
144 if (QueryServiceStatus(hIndexingService, &status) &&
145 (status.dwCurrentState == SERVICE_RUNNING))
150 CloseServiceHandle(hIndexingService);
152 CloseServiceHandle(hSCManager);
154 return ERROR_SUCCESS;
static void StartIndexingService(SC_HANDLE hService)
const wchar_t *const INDEXING_SERVICE_NAME
static bool StopIndexingService(SC_HANDLE hService)
__declspec(dllexport) UINT __stdcall RestartIndexingService(MSIHANDLE)