3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #ifdef HAVE_NT_SERVICE_MANAGER
16 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv );
19 int main( int argc, LPTSTR *argv )
22 char filename[MAX_PATH], *fname_start;
25 * Because the service was registered as SERVICE_WIN32_OWN_PROCESS,
26 * the lpServiceName element of the SERVICE_TABLE_ENTRY will be
30 SERVICE_TABLE_ENTRY DispatchTable[] = {
31 { "", (LPSERVICE_MAIN_FUNCTION) ServiceMain },
36 * set the service's current directory to the installation directory
37 * for the service. this way we don't have to write absolute paths
38 * in the configuration files
40 GetModuleFileName( NULL, filename, sizeof( filename ) );
41 fname_start = strrchr( filename, *LDAP_DIRSEP );
44 if ( _stricmp( "install", argv[1] ) == 0 )
46 char *svcName = SERVICE_NAME;
47 char *displayName = "OpenLDAP Directory Service";
48 BOOL auto_start = FALSE;
50 if ( (argc > 2) && (argv[2] != NULL) )
53 if ( argc > 3 && argv[3])
54 displayName = argv[3];
56 if ( argc > 4 && stricmp(argv[4], "auto") == 0)
59 strcat(filename, " service");
60 if ( !lutil_srv_install(svcName, displayName, filename, auto_start) )
62 fputs( "service failed installation ...\n", stderr );
65 fputs( "service has been installed ...\n", stderr );
69 if ( _stricmp( "remove", argv[1] ) == 0 )
71 char *svcName = SERVICE_NAME;
72 if ( (argc > 2) && (argv[2] != NULL) )
74 if ( !lutil_srv_remove(svcName, filename) )
76 fputs( "failed to remove the service ...\n", stderr );
79 fputs( "service has been removed ...\n", stderr );
82 if ( _stricmp( "service", argv[1] ) == 0 )
86 SetCurrentDirectory( filename );
92 StartServiceCtrlDispatcher(DispatchTable);
95 ServiceMain( argc, argv );