summaryrefslogtreecommitdiff
path: root/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx')
-rw-r--r--setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx154
1 files changed, 77 insertions, 77 deletions
diff --git a/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx b/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx
index 0b030b956570..d92c4a3ac056 100644
--- a/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx
+++ b/setup_native/source/win32/customactions/indexingfilter/restartindexingservice.cxx
@@ -2,7 +2,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -26,15 +26,15 @@
*
************************************************************************/
-/*
- After installation of the OOo filter for the indexing service
- it is necessary to restart the indexing service in order to
+/*
+ After installation of the OOo filter for the indexing service
+ it is necessary to restart the indexing service in order to
activate the filter. This is the most reliable way to get the
indexing service working. We only restart the service if it is
already running. If we have insufficient privileges to restart
- the service we do nothing.
+ the service we do nothing.
*/
-
+
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable warnings within system headers */
#endif
@@ -64,70 +64,70 @@ QueryServiceStatus_t QueryServiceStatus_ = NULL;
StartService_t StartService_ = NULL;
const LPTSTR INDEXING_SERVICE_NAME = TEXT("cisvc");
-
+
bool StopIndexingService(SC_HANDLE hService)
{
- SERVICE_STATUS status;
-
+ SERVICE_STATUS status;
+
if (ControlService_(hService, SERVICE_CONTROL_STOP, &status))
- {
- // Check the status until the service is no longer stop pending.
- if (QueryServiceStatus_(hService, &status))
- {
+ {
+ // Check the status until the service is no longer stop pending.
+ if (QueryServiceStatus_(hService, &status))
+ {
DWORD startTime = GetTickCount();
DWORD oldCheckPoint = status.dwCheckPoint;
- while (status.dwCurrentState == SERVICE_STOP_PENDING)
- {
- // Do not wait longer than the wait hint. A good interval is
- // one tenth the wait hint, but no less than 1 second and no
- // more than 10 seconds.
+ while (status.dwCurrentState == SERVICE_STOP_PENDING)
+ {
+ // Do not wait longer than the wait hint. A good interval is
+ // one tenth the wait hint, but no less than 1 second and no
+ // more than 10 seconds.
DWORD waitTime = status.dwWaitHint / 10;
-
+
if (waitTime < 1000)
waitTime = 1000;
else if (waitTime > 10000)
waitTime = 10000;
-
+
Sleep(waitTime);
- // Check the status again.
+ // Check the status again.
if (!QueryServiceStatus_(hService, &status) ||
- (status.dwCurrentState == SERVICE_STOPPED))
+ (status.dwCurrentState == SERVICE_STOPPED))
break;
-
+
if (status.dwCheckPoint > oldCheckPoint)
- {
+ {
startTime = GetTickCount();
oldCheckPoint = status.dwCheckPoint;
}
else if ((GetTickCount() - startTime) > status.dwWaitHint)
- {
+ {
break; // service doesn't react anymore
- }
+ }
}
}
- }
- return (status.dwCurrentState == SERVICE_STOPPED);
+ }
+ return (status.dwCurrentState == SERVICE_STOPPED);
}
void StartIndexingService(SC_HANDLE hService)
-{
+{
if (StartService_(hService, 0, NULL))
- {
- SERVICE_STATUS status;
+ {
+ SERVICE_STATUS status;
- // Check the status until the service is no longer stop pending.
- if (QueryServiceStatus_(hService, &status))
- {
+ // Check the status until the service is no longer stop pending.
+ if (QueryServiceStatus_(hService, &status))
+ {
DWORD startTime = GetTickCount();
DWORD oldCheckPoint = status.dwCheckPoint;
- while (status.dwCurrentState == SERVICE_START_PENDING)
- {
- // Do not wait longer than the wait hint. A good interval is
- // one tenth the wait hint, but no less than 1 second and no
- // more than 10 seconds.
+ while (status.dwCurrentState == SERVICE_START_PENDING)
+ {
+ // Do not wait longer than the wait hint. A good interval is
+ // one tenth the wait hint, but no less than 1 second and no
+ // more than 10 seconds.
DWORD waitTime = status.dwWaitHint / 10;
if (waitTime < 1000)
@@ -137,13 +137,13 @@ void StartIndexingService(SC_HANDLE hService)
Sleep(waitTime);
- // Check the status again.
+ // Check the status again.
if (!QueryServiceStatus_(hService, &status) ||
- (status.dwCurrentState == SERVICE_STOPPED))
+ (status.dwCurrentState == SERVICE_STOPPED))
break;
-
+
if (status.dwCheckPoint > oldCheckPoint)
- {
+ {
startTime = GetTickCount();
oldCheckPoint = status.dwCheckPoint;
}
@@ -151,60 +151,60 @@ void StartIndexingService(SC_HANDLE hService)
{
// service doesn't react anymore
break;
- }
+ }
}
}
- }
+ }
}
extern "C" UINT __stdcall RestartIndexingService(MSIHANDLE)
{
//MessageBox(NULL, TEXT("Restarting Indexing Service"), TEXT("Message"), MB_OK | MB_ICONINFORMATION);
-
+
HMODULE hAdvapi32 = LoadLibrary("advapi32.dll");
if (hAdvapi32)
{
CloseServiceHandle_ = reinterpret_cast<CloseServiceHandle_t>(GetProcAddress(hAdvapi32, "CloseServiceHandle"));
- ControlService_ = reinterpret_cast<ControlService_t>(GetProcAddress(hAdvapi32, "ControlService"));
+ ControlService_ = reinterpret_cast<ControlService_t>(GetProcAddress(hAdvapi32, "ControlService"));
OpenSCManager_ = reinterpret_cast<OpenSCManager_t>(GetProcAddress(hAdvapi32, "OpenSCManagerA"));
- OpenService_ = reinterpret_cast<OpenService_t>(GetProcAddress(hAdvapi32, "OpenServiceA"));
+ OpenService_ = reinterpret_cast<OpenService_t>(GetProcAddress(hAdvapi32, "OpenServiceA"));
QueryServiceStatus_ = reinterpret_cast<QueryServiceStatus_t>(GetProcAddress(hAdvapi32, "QueryServiceStatus"));
- StartService_ = reinterpret_cast<StartService_t>(GetProcAddress(hAdvapi32, "StartServiceA"));
+ StartService_ = reinterpret_cast<StartService_t>(GetProcAddress(hAdvapi32, "StartServiceA"));
}
-
- /* On systems other than Windows 2000/XP the service API
- functions might not be available */
- if (!hAdvapi32 ||
+
+ /* On systems other than Windows 2000/XP the service API
+ functions might not be available */
+ if (!hAdvapi32 ||
!(CloseServiceHandle_ && ControlService_ && OpenSCManager_ && OpenService_ && QueryServiceStatus_ && StartService_))
return ERROR_SUCCESS;
-
- SC_HANDLE hSCManager = OpenSCManager_(
- NULL, // local machine
- NULL, // ServicesActive database
- SC_MANAGER_ALL_ACCESS);
-
- if (hSCManager != NULL)
- {
- SC_HANDLE hIndexingService = OpenService_(
- hSCManager, INDEXING_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP);
-
+
+ SC_HANDLE hSCManager = OpenSCManager_(
+ NULL, // local machine
+ NULL, // ServicesActive database
+ SC_MANAGER_ALL_ACCESS);
+
+ if (hSCManager != NULL)
+ {
+ SC_HANDLE hIndexingService = OpenService_(
+ hSCManager, INDEXING_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START | SERVICE_STOP);
+
if (hIndexingService)
{
- SERVICE_STATUS status;
+ SERVICE_STATUS status;
ZeroMemory(&status, sizeof(status));
-
- if (QueryServiceStatus_(hIndexingService, &status) &&
- (status.dwCurrentState == SERVICE_RUNNING))
- {
- if (StopIndexingService(hIndexingService))
- StartIndexingService(hIndexingService);
- }
- CloseServiceHandle_(hIndexingService);
- }
- CloseServiceHandle_(hSCManager);
- }
- return ERROR_SUCCESS;
+
+ if (QueryServiceStatus_(hIndexingService, &status) &&
+ (status.dwCurrentState == SERVICE_RUNNING))
+ {
+ if (StopIndexingService(hIndexingService))
+ StartIndexingService(hIndexingService);
+ }
+ CloseServiceHandle_(hIndexingService);
+ }
+ CloseServiceHandle_(hSCManager);
+ }
+ return ERROR_SUCCESS;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */