}
+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 )
{
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 )
{
}
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 );