mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-15 03:01:09 +08:00
Check if process is installed/running as service on NT beofre trying t
o start it as a service (gets around an annoying pause when starting u p as a non-service).
This commit is contained in:
parent
f770dc16ab
commit
9c7127cd81
@ -150,6 +150,57 @@ int srv_remove(LPCTSTR lpszServiceName, LPCTSTR lpszBinaryPathName)
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
svc_installed (LPTSTR lpszServiceName, LPTSTR lpszBinaryPathName)
|
||||
{
|
||||
char buf[256];
|
||||
HKEY key;
|
||||
DWORD rc;
|
||||
DWORD type;
|
||||
long len;
|
||||
|
||||
strcpy(buf, TEXT("SYSTEM\\CurrentControlSet\\Services\\"));
|
||||
strcat(buf, lpszServiceName);
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, buf, 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
|
||||
return(-1);
|
||||
|
||||
rc = 0;
|
||||
if (lpszBinaryPathName) {
|
||||
len = sizeof(buf);
|
||||
if (RegQueryValueEx(key, "ImagePath", NULL, &type, buf, &len) == ERROR_SUCCESS) {
|
||||
if (strcmp(lpszBinaryPathName, buf))
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
RegCloseKey(key);
|
||||
return(rc);
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
svc_running (LPTSTR lpszServiceName)
|
||||
{
|
||||
SC_HANDLE service;
|
||||
SC_HANDLE scm;
|
||||
DWORD rc;
|
||||
SERVICE_STATUS ss;
|
||||
|
||||
if (!(scm = OpenSCManager(NULL, NULL, GENERIC_READ)))
|
||||
return(GetLastError());
|
||||
|
||||
rc = 1;
|
||||
service = OpenService(scm, lpszServiceName, SERVICE_QUERY_STATUS);
|
||||
if (service) {
|
||||
if (!QueryServiceStatus(service, &ss))
|
||||
rc = GetLastError();
|
||||
else if (ss.dwCurrentState != SERVICE_STOPPED)
|
||||
rc = 0;
|
||||
CloseServiceHandle(service);
|
||||
}
|
||||
CloseServiceHandle(scm);
|
||||
return(rc);
|
||||
}
|
||||
|
||||
|
||||
static void *start_status_routine( void *ptr )
|
||||
{
|
||||
|
@ -18,6 +18,8 @@ void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
|
||||
int srv_install( char* service, char * displayName, char* filename,
|
||||
BOOL auto_start );
|
||||
int srv_remove ( char* service, char* filename );
|
||||
DWORD svc_installed (LPTSTR lpszServiceName, LPTSTR lpszBinaryPathName);
|
||||
DWORD svc_running (LPTSTR lpszServiceName);
|
||||
|
||||
int main( int argc, LPTSTR *argv )
|
||||
{
|
||||
@ -99,7 +101,9 @@ int main( int argc, LPTSTR *argv )
|
||||
}
|
||||
|
||||
puts( "starting slapd..." );
|
||||
if ( !StartServiceCtrlDispatcher(DispatchTable) )
|
||||
if (svc_installed(SERVICE_NAME, NULL) != 0
|
||||
|| svc_running(SERVICE_NAME) == 1
|
||||
|| StartServiceCtrlDispatcher(DispatchTable) != 0 )
|
||||
{
|
||||
is_NT_Service = 0;
|
||||
ServiceMain( argc, argv );
|
||||
|
Loading…
Reference in New Issue
Block a user