jfclere     02/02/10 14:45:26

  Modified:    native/winnt README
               native/winnt/service instmain.cpp
  Log:
  Add win95/98 support.
  
  Revision  Changes    Path
  1.2       +0 -1      jakarta-tomcat-service/native/winnt/README
  
  Index: README
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-service/native/winnt/README,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- README    9 Aug 2001 16:32:23 -0000       1.1
  +++ README    10 Feb 2002 22:45:26 -0000      1.2
  @@ -9,7 +9,6 @@
   - executables/vdmonisvc: project files for the sevice wrapper.
   - lib: contains the common include file.
   - moni: contains sources of the vdmoniadm and vdmonisvc.
  -- moni_nt: contains sources of the service low level routines.
   - service: contains the sources and the project for the test installer.
   - signals: contains the kill() emulation logic.
   - supcalls_nt: contains the environment emulation logic.
  
  
  
  1.3       +145 -14   jakarta-tomcat-service/native/winnt/service/instmain.cpp
  
  Index: instmain.cpp
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-service/native/winnt/service/instmain.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- instmain.cpp      9 Aug 2001 17:14:51 -0000       1.2
  +++ instmain.cpp      10 Feb 2002 22:45:26 -0000      1.3
  @@ -25,9 +25,30 @@
       cout << "\r\n";
        return;
   }
  -
  -
  -BOOL RemoveSvc (VOID)
  +
  +/* from src/os/win32/service.c (httpd-1.3!) */
  +
  +BOOL isWindowsNT(void)
  +{
  +    static BOOL once = FALSE;
  +    static BOOL isNT = FALSE;
  + 
  +    if (!once)
  +    {
  +        OSVERSIONINFO osver;
  +        osver.dwOSVersionInfoSize = sizeof(osver);
  +        if (GetVersionEx(&osver))
  +            if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
  +                isNT = TRUE;
  +        once = TRUE;
  +    }
  +    return isNT;
  +}                                                                               
  +
  +
  +/* remove the service (first stop it!) NT version */
  +
  +BOOL RemoveSvcNT (VOID)
   {
        BOOL                    removed;
        SC_HANDLE               hManager;
  @@ -75,9 +96,44 @@
        }
        return removed;
   } /* RemoveSvc */
  -
  -
  -BOOL InstallSvc (CHAR *svcExePath)
  +
  +/* remove service (non NT) stopping it looks ugly!!! */
  +BOOL RemoveSvc (VOID)
  +{
  +     HKEY hkey;
  +     DWORD rv;
  +
  +     rv = RegOpenKey(HKEY_LOCAL_MACHINE,
  +             "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices",
  +             &hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not open the RunServices registry key.\r\n";
  +             return FALSE;
  +     }
  +     rv = RegDeleteValue(hkey, SZSERVICENAME);
  +     RegCloseKey(hkey);
  +     if (rv != ERROR_SUCCESS)
  +             cout << "Could not delete the RunServices entry.\r\n";
  +
  +     rv = RegOpenKey(HKEY_LOCAL_MACHINE,
  +             "SYSTEM\\CurrentControlSet\\Services", &hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not open the Services registry key.\r\n";
  +             return FALSE;
  +     }
  +     rv = RegDeleteKey(hkey, SZSERVICENAME);
  +     RegCloseKey(hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not delete the Services registry key.\r\n";
  +             return FALSE;
  +     }
  +     return TRUE;
  +}
  +
  +
  +/* Install service (NT version) */
  +
  +BOOL InstallSvcNT (CHAR *svcExePath)
   {
        BOOL            installed;
        SC_HANDLE       hManager;
  @@ -106,9 +162,69 @@
                        CloseServiceHandle(hService);
                        installed = TRUE;
                }
  -     }
  +     } else {
  +             cout << "OpenSCManager failed\r\n";
  +     }
        return installed;
  -} /* InstallSvc */
  +}
  +
  +/* Install service */
  +
  +BOOL InstallSvc (CHAR *svcExePath)
  +{
  +     HKEY            hkey;
  +     DWORD rv;
  +     char szPath[MAX_PATH];
  +
  +     cout << "InstallSvc for non-NT\r\n";
  +
  +     rv = RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows"
  +                       "\\CurrentVersion\\RunServices", &hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not open the RunServices registry key\r\n";
  +             return FALSE;
  +     }
  +        rv = RegSetValueEx(hkey, SZSERVICENAME, 0, REG_SZ,
  +                        (unsigned char *) svcExePath,
  +                        strlen(svcExePath) + 1);
  +     RegCloseKey(hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not add ";
  +             cout << SZSERVICENAME;
  +             cout << ":";
  +             cout << svcExePath;
  +             cout << "to RunServices Registry Key\r\n";
  +             return FALSE;
  +     }
  +
  +     strcpy(szPath,
  +              "SYSTEM\\CurrentControlSet\\Services\\");
  +     strcat(szPath,SZSERVICENAME);
  +     rv = RegCreateKey(HKEY_LOCAL_MACHINE, szPath, &hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not create/open the ";
  +             cout << szPath;
  +             cout << " registry key\r\n";
  +             return FALSE;
  +     }
  +     rv = RegSetValueEx(hkey, "ImagePath", 0, REG_SZ,
  +                        (unsigned char *) svcExePath,
  +                        strlen(svcExePath) + 1);
  +     if (rv != ERROR_SUCCESS) {
  +             RegCloseKey(hkey);
  +             cout << "Could not add ImagePath to our Registry Key\r\n";
  +             return FALSE;
  +     }
  +     rv = RegSetValueEx(hkey, "DisplayName", 0, REG_SZ,
  +                        (unsigned char *) SZSERVICEDISPLAYNAME,
  +                        strlen(SZSERVICEDISPLAYNAME) + 1);
  +     RegCloseKey(hkey);
  +     if (rv != ERROR_SUCCESS) {
  +             cout << "Could not add DisplayName to our Registry Key\r\n";
  +             return FALSE;
  +     }
  +     return TRUE;
  +}
   
   /*
    * Fill the registry with the environment variables
  @@ -126,8 +242,8 @@
                        // key is created or opened
                        RegSetValueEx(hKey,var,0,REG_SZ,(BYTE 
*)value,lstrlen(value)+1);
                        RegCloseKey(hKey);
  -                     }
                        installed = TRUE;
  +                     }
        return installed;
   } /* InstallEnv */
   
  @@ -139,11 +255,22 @@
   
   INT main (INT argc, CHAR *argv[])
   {
  -
  -  cout << "\r\n - Copyright (C) 1998 by Siemens Nixdorf Informationssystem 
AG\r\n\r\n";
  +  BOOL done;
  +
  +  cout << "\r\n - Copyright (c) 2001 The Apache Software Foundation. \r\n";
  +  cout << "\r\n";
  +
     if (argc==1) {
        /* install jsvcservice.exe as a service */
  -     InstallSvc(SZDEFMONISVCPATH);
  +     if (isWindowsNT())
  +             done = InstallSvcNT(SZDEFMONISVCPATH);
  +     else
  +             done = InstallSvc(SZDEFMONISVCPATH);
  +
  +     if (done)
  +             cout << "InstallSvc done\r\n";
  +     else
  +             cout << "InstallSvc failed\r\n";
   
        /* install the environment variable in registry */
        InstallEnv("JAKARTA_HOME",SZJAKARTA_HOME);
  @@ -158,8 +285,12 @@
   
     if (argc==2 && strcmp(argv[1],"-REMOVE")==0) {
        // remove the  service. removing the keys not yet done!!!
  -     cout << "\r\n - removing Java Service...\r\n\r\n"; 
  -     if (RemoveSvc()) {
  +     cout << "\r\n - removing Java Service...\r\n\r\n";
  +     if (isWindowsNT())
  +             done = RemoveSvcNT();
  +     else
  +             done = RemoveSvc();
  +     if (!done) {
                cout << "\r\n - REMOVE FAILED....\r\n\r\n"; 
                return(2);
                }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to