* Multiple improvements to the Windows Installer
  - https://issues.apache.org/bugzilla/show_bug.cgi?id=33262
    Install monitor to auto-start for current user only rather than all users to
    be consistent with menu item creation.
  - Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=40510
    Provide an option to install shortcuts for the current user or all users.
    Also ensure registry is correctly cleaned on uninstall for 64-bit platforms.
  - Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50949
    Provide the ability to specify the AJP port and service name when installing
    Tomcat using the Windows installer. This permits multiple instances of the
    same Tomcat version to be installed side-by-side.
  - Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51135
    Fix auto-detection of JAVA_HOME for 64-bit Windows platforms that only have
    a 32-bit JVM installed.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc5.5.x/trunk@1160313 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/STATUS.txt b/STATUS.txt
index 54ed132..3a226f5 100644
--- a/STATUS.txt
+++ b/STATUS.txt
@@ -25,33 +25,6 @@
 PATCHES PROPOSED TO BACKPORT:
   [ New proposals should be added at the end of the list ]
 
-* Multiple improvements to the Windows Installer
-  - https://issues.apache.org/bugzilla/show_bug.cgi?id=33262
-    Install monitor to auto-start for current user only rather than all users to
-    be consistent with menu item creation.
-  - Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=40510
-    Provide an option to install shortcuts for the current user or all users.
-    Also ensure registry is correctly cleaned on uninstall for 64-bit platforms.
-  - Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50949
-    Provide the ability to specify the AJP port and service name when installing
-    Tomcat using the Windows installer. This permits multiple instances of the
-    same Tomcat version to be installed side-by-side.
-  - Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51135
-    Fix auto-detection of JAVA_HOME for 64-bit Windows platforms that only have
-    a 32-bit JVM installed.
-  http://people.apache.org/~markt/patches/2011-08-22-windows-installer-tc55.patch
-  Plus
-    svn rm build/resources/confinstall/server_1.xml
-    svn rm build/resources/confinstall/server_2.xml
-    svn rm build/resources/tickno.bmp
-    svn rm build/resources/tickyes.bmp
-    svn rm build/resources/main.ico
-    svn rm build/resources/uninst.ico
-  +1: markt, jim, kkolinko
-  -1:
-    kkolinko: Noted a typo in a message displayed by uninstaller:
-     s/with -serviceName/with -ServiceName/
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51550
   Display error page rather than an empty response for an IllegalStateException
   https://issues.apache.org/bugzilla/attachment.cgi?id=27421
diff --git a/build/resources/confinstall/server_1.xml b/build/resources/confinstall/server_1.xml
deleted file mode 100644
index d2a5a48..0000000
--- a/build/resources/confinstall/server_1.xml
+++ /dev/null
@@ -1,94 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<!-- Example Server Configuration File -->
-<!-- Note that component elements are nested corresponding to their
-     parent-child relationships with each other -->
-
-<!-- A "Server" is a singleton element that represents the entire JVM,
-     which may contain one or more "Service" instances.  The Server
-     listens for a shutdown command on the indicated port.
-
-     Note:  A "Server" is not itself a "Container", so you may not
-     define subcomponents such as "Valves" or "Loggers" at this level.
- -->
-
-<Server port="8005" shutdown="SHUTDOWN">
-
-  <!-- Comment these entries out to disable JMX MBeans support used for the 
-       administration web application -->
-  <Listener className="org.apache.catalina.core.AprLifecycleListener" />
-  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
-  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
-  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
-
-  <!-- Global JNDI resources -->
-  <GlobalNamingResources>
-
-    <!-- Test entry for demonstration purposes -->
-    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
-
-    <!-- Editable user database that can also be used by
-         UserDatabaseRealm to authenticate users -->
-    <Resource name="UserDatabase" auth="Container"
-              type="org.apache.catalina.UserDatabase"
-       description="User database that can be updated and saved"
-           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
-          pathname="conf/tomcat-users.xml" />
-
-  </GlobalNamingResources>
-
-  <!-- A "Service" is a collection of one or more "Connectors" that share
-       a single "Container" (and therefore the web applications visible
-       within that Container).  Normally, that Container is an "Engine",
-       but this is not required.
-
-       Note:  A "Service" is not itself a "Container", so you may not
-       define subcomponents such as "Valves" or "Loggers" at this level.
-   -->
-
-  <!-- Define the Tomcat Stand-Alone Service -->
-  <Service name="Catalina">
-
-    <!-- A "Connector" represents an endpoint by which requests are received
-         and responses are returned.  Each Connector passes requests on to the
-         associated "Container" (normally an Engine) for processing.
-
-         By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
-         You can also enable an SSL HTTP/1.1 Connector on port 8443 by
-         following the instructions below and uncommenting the second Connector
-         entry.  SSL support requires the following steps (see the SSL Config
-         HOWTO in the Tomcat 5 documentation bundle for more detailed
-         instructions):
-         * If your JDK version 1.3 or prior, download and install JSSE 1.0.2 or
-           later, and put the JAR files into "$JAVA_HOME/jre/lib/ext".
-         * Execute:
-             %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
-             $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA  (Unix)
-           with a password value of "changeit" for both the certificate and
-           the keystore itself.
-
-         By default, DNS lookups are enabled when a web application calls
-         request.getRemoteHost().  This can have an adverse impact on
-         performance, so you can disable it by setting the
-         "enableLookups" attribute to "false".  When DNS lookups are disabled,
-         request.getRemoteHost() will return the String version of the
-         IP address of the remote client.
-    -->
-
-    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
-    <Connector 
\ No newline at end of file
diff --git a/build/resources/confinstall/server_2.xml b/build/resources/confinstall/server_2.xml
deleted file mode 100644
index 2db169f..0000000
--- a/build/resources/confinstall/server_2.xml
+++ /dev/null
@@ -1,298 +0,0 @@
- maxHttpHeaderSize="8192"
-               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
-               enableLookups="false" redirectPort="8443" acceptCount="100"
-               connectionTimeout="20000" disableUploadTimeout="true" />
-    <!-- Note : To disable connection timeouts, set connectionTimeout value
-     to 0 -->
-	
-	<!-- Note : To use gzip compression you could set the following properties :
-	
-			   compression="on" 
-			   compressionMinSize="2048" 
-			   noCompressionUserAgents="gozilla, traviata" 
-			   compressableMimeType="text/html,text/xml"
-	-->
-
-    <!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
-    <!--
-    <Connector port="8443" maxHttpHeaderSize="8192"
-               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
-               enableLookups="false" disableUploadTimeout="true"
-               acceptCount="100" scheme="https" secure="true"
-               clientAuth="false" sslProtocol="TLS" />
-    -->
-
-    <!-- Define an AJP 1.3 Connector on port 8009 -->
-    <Connector port="8009" 
-               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
-
-    <!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
-    <!-- See proxy documentation for more information about using this. -->
-    <!--
-    <Connector port="8082" 
-               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
-               enableLookups="false" acceptCount="100" connectionTimeout="20000"
-               proxyPort="80" disableUploadTimeout="true" />
-    -->
-
-    <!-- An Engine represents the entry point (within Catalina) that processes
-         every request.  The Engine implementation for Tomcat stand alone
-         analyzes the HTTP headers included with the request, and passes them
-         on to the appropriate Host (virtual host). -->
-
-    <!-- You should set jvmRoute to support load-balancing via AJP ie :
-    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
-    --> 
-         
-    <!-- Define the top level container in our container hierarchy -->
-    <Engine name="Catalina" defaultHost="localhost">
-
-      <!-- The request dumper valve dumps useful debugging information about
-           the request headers and cookies that were received, and the response
-           headers and cookies that were sent, for all requests received by
-           this instance of Tomcat.  If you care only about requests to a
-           particular virtual host, or a particular application, nest this
-           element inside the corresponding <Host> or <Context> entry instead.
-
-           For a similar mechanism that is portable to all Servlet 2.4
-           containers, check out the "RequestDumperFilter" Filter in the
-           example application (the source for this filter may be found in
-           "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
-
-           Note that this Valve uses the platform's default character encoding.
-           This may cause problems for developers in another encoding, e.g.
-           UTF-8.  Use the RequestDumperFilter instead.
-
-           Also note that enabling this Valve will write a ton of stuff to your
-           logs.  They are likely to grow quite large.  This extensive log writing
-           will definitely slow down your server.
-
-           Request dumping is disabled by default.  Uncomment the following
-           element to enable it. -->
-      <!--
-      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-      -->
-
-      <!-- Because this Realm is here, an instance will be shared globally -->
-
-      <!-- This Realm uses the UserDatabase configured in the global JNDI
-           resources under the key "UserDatabase".  Any edits
-           that are performed against this UserDatabase are immediately
-           available for use by the Realm.  -->
-      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
-             resourceName="UserDatabase"/>
-
-      <!-- Comment out the old realm but leave here for now in case we
-           need to go back quickly -->
-      <!--
-      <Realm className="org.apache.catalina.realm.MemoryRealm" />
-      -->
-
-      <!-- Replace the above Realm with one of the following to get a Realm
-           stored in a database and accessed via JDBC -->
-
-      <!--
-      <Realm  className="org.apache.catalina.realm.JDBCRealm"
-             driverName="org.gjt.mm.mysql.Driver"
-          connectionURL="jdbc:mysql://localhost/authority"
-         connectionName="test" connectionPassword="test"
-              userTable="users" userNameCol="user_name" userCredCol="user_pass"
-          userRoleTable="user_roles" roleNameCol="role_name" />
-      -->
-
-      <!--
-      <Realm  className="org.apache.catalina.realm.JDBCRealm"
-             driverName="oracle.jdbc.driver.OracleDriver"
-          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
-         connectionName="scott" connectionPassword="tiger"
-              userTable="users" userNameCol="user_name" userCredCol="user_pass"
-          userRoleTable="user_roles" roleNameCol="role_name" />
-      -->
-
-      <!--
-      <Realm  className="org.apache.catalina.realm.JDBCRealm"
-             driverName="sun.jdbc.odbc.JdbcOdbcDriver"
-          connectionURL="jdbc:odbc:CATALINA"
-              userTable="users" userNameCol="user_name" userCredCol="user_pass"
-          userRoleTable="user_roles" roleNameCol="role_name" />
-      -->
-
-      <!-- Define the default virtual host
-           Note: XML Schema validation will not work with Xerces 2.2.
-       -->
-      <Host name="localhost" appBase="webapps"
-       unpackWARs="true" autoDeploy="true"
-       xmlValidation="false" xmlNamespaceAware="false">
-
-        <!-- Defines a cluster for this node,
-             By defining this element, means that every manager will be changed.
-             So when running a cluster, only make sure that you have webapps in there
-             that need to be clustered and remove the other ones.
-             A cluster has the following parameters:
-
-             className = the fully qualified name of the cluster class
-
-             clusterName = a descriptive name for your cluster, can be anything
-
-             mcastAddr = the multicast address, has to be the same for all the nodes
-
-             mcastPort = the multicast port, has to be the same for all the nodes
-             
-             mcastBindAddress = bind the multicast socket to a specific address
-             
-             mcastTTL = the multicast TTL if you want to limit your broadcast
-             
-             mcastSoTimeout = the multicast readtimeout 
-
-             mcastFrequency = the number of milliseconds in between sending a "I'm alive" heartbeat
-
-             mcastDropTime = the number a milliseconds before a node is considered "dead" if no heartbeat is received
-
-             tcpThreadCount = the number of threads to handle incoming replication requests, optimal would be the same amount of threads as nodes 
-
-             tcpListenAddress = the listen address (bind address) for TCP cluster request on this host, 
-                                in case of multiple ethernet cards.
-                                auto means that address becomes
-                                InetAddress.getLocalHost().getHostAddress()
-
-             tcpListenPort = the tcp listen port
-
-             tcpSelectorTimeout = the timeout (ms) for the Selector.select() method in case the OS
-                                  has a wakup bug in java.nio. Set to 0 for no timeout
-
-             printToScreen = true means that managers will also print to std.out
-
-             expireSessionsOnShutdown = true means that 
-
-             useDirtyFlag = true means that we only replicate a session after setAttribute,removeAttribute has been called.
-                            false means to replicate the session after each request.
-                            false means that replication would work for the following piece of code: (only for SimpleTcpReplicationManager)
-                            <%
-                            HashMap map = (HashMap)session.getAttribute("map");
-                            map.put("key","value");
-                            %>
-             replicationMode = can be either 'pooled', 'synchronous' or 'asynchronous'.
-                               * Pooled means that the replication happens using several sockets in a synchronous way. Ie, the data gets replicated, then the request return. This is the same as the 'synchronous' setting except it uses a pool of sockets, hence it is multithreaded. This is the fastest and safest configuration. To use this, also increase the nr of tcp threads that you have dealing with replication.
-                               * Synchronous means that the thread that executes the request, is also the
-                               thread the replicates the data to the other nodes, and will not return until all
-                               nodes have received the information.
-                               * Asynchronous means that there is a specific 'sender' thread for each cluster node,
-                               so the request thread will queue the replication request into a "smart" queue,
-                               and then return to the client.
-                               The "smart" queue is a queue where when a session is added to the queue, and the same session
-                               already exists in the queue from a previous request, that session will be replaced
-                               in the queue instead of replicating two requests. This almost never happens, unless there is a 
-                               large network delay.
-        -->             
-        <!--
-            When configuring for clustering, you also add in a valve to catch all the requests
-            coming in, at the end of the request, the session may or may not be replicated.
-            A session is replicated if and only if all the conditions are met:
-            1. useDirtyFlag is true or setAttribute or removeAttribute has been called AND
-            2. a session exists (has been created)
-            3. the request is not trapped by the "filter" attribute
-
-            The filter attribute is to filter out requests that could not modify the session,
-            hence we don't replicate the session after the end of this request.
-            The filter is negative, ie, anything you put in the filter, you mean to filter out,
-            ie, no replication will be done on requests that match one of the filters.
-            The filter attribute is delimited by ;, so you can't escape out ; even if you wanted to.
-
-            filter=".*\.gif;.*\.js;" means that we will not replicate the session after requests with the URI
-            ending with .gif and .js are intercepted.
-            
-            The deployer element can be used to deploy apps cluster wide.
-            Currently the deployment only deploys/undeploys to working members in the cluster
-            so no WARs are copied upons startup of a broken node.
-            The deployer watches a directory (watchDir) for WAR files when watchEnabled="true"
-            When a new war file is added the war gets deployed to the local instance,
-            and then deployed to the other instances in the cluster.
-            When a war file is deleted from the watchDir the war is undeployed locally 
-            and cluster wide
-        -->
-        
-        <!--
-        <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
-                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
-                 expireSessionsOnShutdown="false"
-                 useDirtyFlag="true"
-                 notifyListenersOnReplication="true">
-
-            <Membership 
-                className="org.apache.catalina.cluster.mcast.McastService"
-                mcastAddr="228.0.0.4"
-                mcastPort="45564"
-                mcastFrequency="500"
-                mcastDropTime="3000"/>
-
-            <Receiver 
-                className="org.apache.catalina.cluster.tcp.ReplicationListener"
-                tcpListenAddress="auto"
-                tcpListenPort="4001"
-                tcpSelectorTimeout="100"
-                tcpThreadCount="6"/>
-
-            <Sender
-                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
-                replicationMode="pooled"
-                ackTimeout="15000"
-                waitForAck="true"/>
-
-            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
-                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
-                   
-            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
-                      tempDir="/tmp/war-temp/"
-                      deployDir="/tmp/war-deploy/"
-                      watchDir="/tmp/war-listen/"
-                      watchEnabled="false"/>
-                      
-            <ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>
-        </Cluster>
-        -->        
-
-
-
-        <!-- Normally, users must authenticate themselves to each web app
-             individually.  Uncomment the following entry if you would like
-             a user to be authenticated the first time they encounter a
-             resource protected by a security constraint, and then have that
-             user identity maintained across *all* web applications contained
-             in this virtual host. -->
-        <!--
-        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-        -->
-
-        <!-- Access log processes all requests for this virtual host.  By
-             default, log files are created in the "logs" directory relative to
-             $CATALINA_HOME.  If you wish, you can specify a different
-             directory with the "directory" attribute.  Specify either a relative
-             (to $CATALINA_HOME) or absolute path to the desired directory.
-        -->
-        <!--
-        <Valve className="org.apache.catalina.valves.AccessLogValve"
-                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
-                 pattern="common" resolveHosts="false"/>
-        -->
-
-        <!-- Access log processes all requests for this virtual host.  By
-             default, log files are created in the "logs" directory relative to
-             $CATALINA_HOME.  If you wish, you can specify a different
-             directory with the "directory" attribute.  Specify either a relative
-             (to $CATALINA_HOME) or absolute path to the desired directory.
-             This access log implementation is optimized for maximum performance,
-             but is hardcoded to support only the "common" and "combined" patterns.
-        -->
-        <!--
-        <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
-                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
-                 pattern="common" resolveHosts="false"/>
-        -->
-
-      </Host>
-
-    </Engine>
-
-  </Service>
-
-</Server>
diff --git a/build/resources/main.ico b/build/resources/main.ico
deleted file mode 100644
index 1db75f8..0000000
--- a/build/resources/main.ico
+++ /dev/null
Binary files differ
diff --git a/build/resources/tickno.bmp b/build/resources/tickno.bmp
deleted file mode 100644
index 64a6749..0000000
--- a/build/resources/tickno.bmp
+++ /dev/null
Binary files differ
diff --git a/build/resources/tickyes.bmp b/build/resources/tickyes.bmp
deleted file mode 100644
index 7b5d420..0000000
--- a/build/resources/tickyes.bmp
+++ /dev/null
Binary files differ
diff --git a/build/resources/uninst.ico b/build/resources/uninst.ico
deleted file mode 100644
index 59c79f3..0000000
--- a/build/resources/uninst.ico
+++ /dev/null
Binary files differ
diff --git a/build/tomcat.nsi b/build/tomcat.nsi
index fe6dfb2..1a1b393 100644
--- a/build/tomcat.nsi
+++ b/build/tomcat.nsi
@@ -45,7 +45,15 @@
 Var JvmDll
 Var Arch
 Var ResetInstDir
-Var TomcatPort
+Var TomcatPortShutdown
+Var TomcatPortHttp
+Var TomcatPortAjp
+Var TomcatMenuEntriesEnable
+Var TomcatShortcutAllUsers
+Var TomcatServiceName
+Var TomcatServiceDefaultName
+Var TomcatServiceFileName
+Var TomcatServiceManagerFileName
 Var TomcatAdminEnable
 Var TomcatAdminUsername
 Var TomcatAdminPassword
@@ -53,7 +61,11 @@
 
 ; Variables that store handles of dialog controls
 Var CtlJavaHome
-Var CtlTomcatPort
+Var CtlTomcatPortShutdown
+Var CtlTomcatPortHttp
+Var CtlTomcatPortAjp
+Var CtlTomcatServiceName
+Var CtlTomcatShortcutAllUsers
 Var CtlTomcatAdminUsername
 Var CtlTomcatAdminPassword
 Var CtlTomcatAdminRoles
@@ -68,10 +80,10 @@
   !define MUI_HEADERIMAGE
   !define MUI_HEADERIMAGE_RIGHT
   !define MUI_HEADERIMAGE_BITMAP header.bmp
-  !define MUI_WELCOMEFINISHPAGE_BITMAP side_left.bmp 
+  !define MUI_WELCOMEFINISHPAGE_BITMAP side_left.bmp
   !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\webapps\ROOT\RELEASE-NOTES.txt"
-  !define MUI_FINISHPAGE_RUN $INSTDIR\bin\tomcat@VERSION_MAJOR@w.exe
-  !define MUI_FINISHPAGE_RUN_PARAMETERS //MR//Tomcat@VERSION_MAJOR@
+  !define MUI_FINISHPAGE_RUN
+  !define MUI_FINISHPAGE_RUN_FUNCTION "startService"
   !define MUI_FINISHPAGE_NOREBOOTSUPPORT
 
   !define MUI_ABORTWARNING
@@ -87,12 +99,17 @@
   LangString TEXT_JVM_SUBTITLE ${LANG_ENGLISH} "Java Virtual Machine path selection."
   LangString TEXT_JVM_PAGETITLE ${LANG_ENGLISH} ": Java Virtual Machine path selection"
 
+  LangString TEXT_INSTDIR_NOT_EMPTY ${LANG_ENGLISH} "The specified installation directory is not empty. Do you wish to continue?"
   LangString TEXT_CONF_TITLE ${LANG_ENGLISH} "Configuration"
   LangString TEXT_CONF_SUBTITLE ${LANG_ENGLISH} "Tomcat basic configuration."
   LangString TEXT_CONF_PAGETITLE ${LANG_ENGLISH} ": Configuration Options"
 
   LangString TEXT_JVM_LABEL1 ${LANG_ENGLISH} "Please select the path of a Java SE 5.0 or later JRE installed on your system."
-  LangString TEXT_CONF_LABEL_PORT ${LANG_ENGLISH} "HTTP/1.1 Connector Port"
+  LangString TEXT_CONF_LABEL_PORT_SHUTDOWN ${LANG_ENGLISH} "Server Shutdown Port"
+  LangString TEXT_CONF_LABEL_PORT_HTTP ${LANG_ENGLISH} "HTTP/1.1 Connector Port"
+  LangString TEXT_CONF_LABEL_PORT_AJP ${LANG_ENGLISH} "AJP/1.3 Connector Port"
+  LangString TEXT_CONF_LABEL_SERVICE_NAME ${LANG_ENGLISH} "Windows Service Name"
+  LangString TEXT_CONF_LABEL_SHORTCUT_ALL_USERS ${LANG_ENGLISH} "Create shortcuts for all users"
   LangString TEXT_CONF_LABEL_ADMIN ${LANG_ENGLISH} "Tomcat Administrator Login (optional)"
   LangString TEXT_CONF_LABEL_ADMINUSERNAME ${LANG_ENGLISH} "User Name"
   LangString TEXT_CONF_LABEL_ADMINPASSWORD ${LANG_ENGLISH} "Password"
@@ -106,6 +123,7 @@
   !insertmacro MUI_PAGE_COMPONENTS
   Page custom pageConfiguration pageConfigurationLeave "$(TEXT_CONF_PAGETITLE)"
   Page custom pageChooseJVM pageChooseJVMLeave "$(TEXT_JVM_PAGETITLE)"
+  !define MUI_PAGE_CUSTOMFUNCTION_LEAVE pageDirectoryLeave
   !insertmacro MUI_PAGE_DIRECTORY
   !insertmacro MUI_PAGE_INSTFILES
   Page custom CheckUserType
@@ -139,13 +157,8 @@
   InstType Minimum
   InstType Full
 
-  ; Main registry key
-  InstallDirRegKey HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@" ""
-
   ReserveFile "${NSISDIR}\Plugins\System.dll"
   ReserveFile "${NSISDIR}\Plugins\nsDialogs.dll"
-  ReserveFile confinstall\server_1.xml
-  ReserveFile confinstall\server_2.xml
   ReserveFile confinstall\tomcat-users_1.xml
   ReserveFile confinstall\tomcat-users_2.xml
 
@@ -191,33 +204,37 @@
 
   DetailPrint "Using Jvm: $JavaHome"
 
+  StrCpy $R0 $TomcatServiceName
+  StrCpy $TomcatServiceFileName $R0.exe
+  StrCpy $TomcatServiceManagerFileName $R0w.exe
+
   SetOutPath $INSTDIR\bin
-  File bin\tomcat@VERSION_MAJOR@w.exe
+  File /oname=$TomcatServiceManagerFileName bin\tomcat@VERSION_MAJOR@w.exe
 
   ; Get the current platform x86 / AMD64 / IA64
   ${If} $Arch == "x86"
-    File /oname=tomcat@VERSION_MAJOR@.exe bin\tomcat@VERSION_MAJOR@.exe
+    File /oname=$TomcatServiceFileName bin\tomcat@VERSION_MAJOR@.exe
   ${ElseIf} $Arch == "x64"
-    File /oname=tomcat@VERSION_MAJOR@.exe bin\x64\tomcat@VERSION_MAJOR@.exe
+    File /oname=$TomcatServiceFileName bin\x64\tomcat@VERSION_MAJOR@.exe
   ${ElseIf} $Arch == "i64"
-    File /oname=tomcat@VERSION_MAJOR@.exe bin\i64\tomcat@VERSION_MAJOR@.exe
+    File /oname=$TomcatServiceFileName bin\i64\tomcat@VERSION_MAJOR@.exe
   ${EndIf}
 
   FileOpen $ServiceInstallLog "$INSTDIR\logs\service-install.log" a
   FileSeek $ServiceInstallLog 0 END
 
   InstallRetry:
-  FileWrite $ServiceInstallLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //IS//Tomcat@VERSION_MAJOR@ --DisplayName "Apache Tomcat @VERSION_MAJOR@" --Description "Apache Tomcat @VERSION@ Server - http://tomcat.apache.org/" --LogPath "$INSTDIR\logs" --Install "$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" --Jvm "$JvmDll" --StartPath "$INSTDIR" --StopPath "$INSTDIR"'
+  FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //IS//$TomcatServiceName --DisplayName "Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName" --Description "Apache Tomcat @VERSION@ Server - http://tomcat.apache.org/" --LogPath "$INSTDIR\logs" --Install "$INSTDIR\bin\$TomcatServiceFileName" --Jvm "$JvmDll" --StartPath "$INSTDIR" --StopPath "$INSTDIR"'
   FileWrite $ServiceInstallLog "$\r$\n"
   ClearErrors
-  DetailPrint "Installing Tomcat@VERSION_MAJOR@ service"
-  nsExec::ExecToStack '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //IS//Tomcat@VERSION_MAJOR@ --DisplayName "Apache Tomcat @VERSION_MAJOR@" --Description "Apache Tomcat @VERSION@ Server - http://tomcat.apache.org/" --LogPath "$INSTDIR\logs" --Install "$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" --Jvm "$JvmDll" --StartPath "$INSTDIR" --StopPath "$INSTDIR"'
+  DetailPrint "Installing $TomcatServiceName service"
+  nsExec::ExecToStack '"$INSTDIR\bin\$TomcatServiceFileName" //IS//$TomcatServiceName --DisplayName "Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName" --Description "Apache Tomcat @VERSION@ Server - http://tomcat.apache.org/" --LogPath "$INSTDIR\logs" --Install "$INSTDIR\bin\$TomcatServiceFileName" --Jvm "$JvmDll" --StartPath "$INSTDIR" --StopPath "$INSTDIR"'
   Pop $0
   Pop $1
   StrCmp $0 "0" InstallOk
     FileWrite $ServiceInstallLog "Install failed: $0 $1$\r$\n"
     MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP \
-      "Failed to install Tomcat@VERSION_MAJOR@ service.$\r$\nCheck your settings and permissions.$\r$\nIgnore and continue anyway (not recommended)?" \
+      "Failed to install $TomcatServiceName service.$\r$\nCheck your settings and permissions.$\r$\nIgnore and continue anyway (not recommended)?" \
        /SD IDIGNORE IDIGNORE InstallOk IDRETRY InstallRetry
   Quit
   InstallOk:
@@ -232,13 +249,11 @@
   SectionIn 3
 
   ${If} $ServiceInstallLog != ""
-    FileWrite $ServiceInstallLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --Startup auto'
+    FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Startup auto'
     FileWrite $ServiceInstallLog "$\r$\n"
   ${EndIf}
-  DetailPrint "Configuring Tomcat@VERSION_MAJOR@ service"
-  nsExec::ExecToLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --Startup auto'
-  ; Behave like Apache Httpd (put the icon in tray on login)
-  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor" '"$INSTDIR\bin\tomcat@VERSION_MAJOR@w.exe" //MS//Tomcat@VERSION_MAJOR@'
+  DetailPrint "Configuring $TomcatServiceName service"
+  nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Startup auto'
 
   ClearErrors
 
@@ -268,7 +283,6 @@
 
   SectionIn 1 2 3
 
-  Call createShortcuts
 SectionEnd
 
 Section "Documentation" SecDocs
@@ -328,28 +342,40 @@
 
 Section -post
   ${If} $ServiceInstallLog != ""
-    FileWrite $ServiceInstallLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --Classpath "$INSTDIR\bin\bootstrap.jar" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop  --StartMode jvm --StopMode jvm'
+    FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Classpath "$INSTDIR\bin\bootstrap.jar;$INSTDIR\bin\tomcat-juli.jar" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop  --StartMode jvm --StopMode jvm'
     FileWrite $ServiceInstallLog "$\r$\n"
-    FileWrite $ServiceInstallLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --JvmOptions "-Dcatalina.home=$INSTDIR#-Dcatalina.base=$INSTDIR#-Djava.endorsed.dirs=$INSTDIR\common\endorsed#-Djava.io.tmpdir=$INSTDIR\temp#-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager#-Djava.util.logging.config.file=$INSTDIR\conf\logging.properties"'
+    FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --JvmOptions "-Dcatalina.home=$INSTDIR#-Dcatalina.base=$INSTDIR#-Djava.endorsed.dirs=$INSTDIR\endorsed#-Djava.io.tmpdir=$INSTDIR\temp#-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager#-Djava.util.logging.config.file=$INSTDIR\conf\logging.properties"'
     FileWrite $ServiceInstallLog "$\r$\n"
-    FileWrite $ServiceInstallLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --StdOutput auto --StdError auto'
+    FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --StdOutput auto --StdError auto'
     FileWrite $ServiceInstallLog "$\r$\n"
     FileClose $ServiceInstallLog
   ${EndIf}
 
-  DetailPrint "Configuring Tomcat@VERSION_MAJOR@ service"
-  nsExec::ExecToLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --Classpath "$INSTDIR\bin\bootstrap.jar" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop  --StartMode jvm --StopMode jvm'
-  nsExec::ExecToLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --JvmOptions "-Dcatalina.home=$INSTDIR#-Dcatalina.base=$INSTDIR#-Djava.endorsed.dirs=$INSTDIR\common\endorsed#-Djava.io.tmpdir=$INSTDIR\temp#-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager#-Djava.util.logging.config.file=$INSTDIR\conf\logging.properties"'
-  nsExec::ExecToLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //US//Tomcat@VERSION_MAJOR@ --StdOutput auto --StdError auto'
+  DetailPrint "Configuring $TomcatServiceName service"
+  nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Classpath "$INSTDIR\bin\bootstrap.jar;$INSTDIR\bin\tomcat-juli.jar" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop  --StartMode jvm --StopMode jvm'
+  nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --JvmOptions "-Dcatalina.home=$INSTDIR#-Dcatalina.base=$INSTDIR#-Djava.endorsed.dirs=$INSTDIR\endorsed#-Djava.io.tmpdir=$INSTDIR\temp#-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager#-Djava.util.logging.config.file=$INSTDIR\conf\logging.properties"'
+  nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --StdOutput auto --StdError auto'
+
+  ${If} $TomcatShortcutAllUsers == "1"
+    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor@VERSION_MAJOR_MINOR@_$TomcatServiceName" '"$INSTDIR\bin\$TomcatServiceManagerFileName" //MS//$TomcatServiceName'
+  ${Else}
+    WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor@VERSION_MAJOR_MINOR@_$TomcatServiceName" '"$INSTDIR\bin\$TomcatServiceManagerFileName" //MS//$TomcatServiceName'
+  ${EndIf}
+  
+  ${If} $TomcatMenuEntriesEnable == "1"
+    Call createShortcuts
+  ${EndIf}
 
   WriteUninstaller "$INSTDIR\Uninstall.exe"
 
-  WriteRegStr HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@" "InstallPath" $INSTDIR
-  WriteRegStr HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@" "Version" @VERSION@
-  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@" \
-                   "DisplayName" "Apache Tomcat @VERSION_MAJOR_MINOR@ (remove only)"
-  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@" \
-                   "UninstallString" '"$INSTDIR\Uninstall.exe"'
+  WriteRegStr HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@\$TomcatServiceName" "InstallPath" $INSTDIR
+  WriteRegStr HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@\$TomcatServiceName" "Version" @VERSION@
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName" \
+                   "DisplayName" "Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName (remove only)"
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName" \
+                   "DisplayIcon" "$\"$INSTDIR\tomcat.ico$\""
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName" \
+                   "UninstallString" "$\"$INSTDIR\Uninstall.exe$\" -ServiceName=$\"$TomcatServiceName$\""
 
 SectionEnd
 
@@ -370,7 +396,15 @@
 
   ;Initialize default values
   StrCpy $JavaHome ""
-  StrCpy $TomcatPort "8080"
+  StrCpy $TomcatPortShutdown "8005"
+  StrCpy $TomcatPortHttp "8080"
+  StrCpy $TomcatPortAjp "8009"
+  StrCpy $TomcatMenuEntriesEnable "0"
+  StrCpy $TomcatShortcutAllUsers "0"
+  StrCpy $TomcatServiceDefaultName "Tomcat@VERSION_MAJOR@"
+  StrCpy $TomcatServiceName $TomcatServiceDefaultName
+  StrCpy $TomcatServiceFileName "Tomcat@VERSION_MAJOR@.exe"
+  StrCpy $TomcatServiceManagerFileName "Tomcat@VERSION_MAJOR@w.exe"
   StrCpy $TomcatAdminEnable "0"
   StrCpy $TomcatAdminUsername ""
   StrCpy $TomcatAdminPassword ""
@@ -428,6 +462,7 @@
 Function pageComponentsLeave
   StrCpy $TomcatAdminEnable "0"
   StrCpy $TomcatAdminRoles ""
+  StrCpy $TomcatMenuEntriesEnable "0"
 
   SectionGetFlags ${SecManager} $0
   IntOp $0 $0 & ${SF_SELECTED}
@@ -446,6 +481,24 @@
       StrCpy $TomcatAdminRoles "admin-gui"
     ${EndIf}
   ${EndIf}
+  
+  SectionGetFlags ${SecMenu} $0
+  IntOp $0 $0 & ${SF_SELECTED}
+  ${If} $0 <> 0
+    StrCpy $TomcatMenuEntriesEnable "1"
+  ${EndIf}
+FunctionEnd
+
+Function pageDirectoryLeave
+  ${DirState} "$INSTDIR" $0
+  ${If} $0 == 1 ;folder is full. (other values: 0: empty, -1: not found)
+    ;query selection
+    MessageBox MB_OKCANCEL|MB_ICONQUESTION "$(TEXT_INSTDIR_NOT_EMPTY)" /SD IDOK IDCANCEL notok
+    Goto ok
+    notok:
+    Abort
+    ok:
+  ${EndIf}
 FunctionEnd
 
 Function pageConfiguration
@@ -454,50 +507,147 @@
   nsDialogs::Create 1018
   Pop $R0
 
-  ${NSD_CreateLabel} 0 5u 100u 15u "$(TEXT_CONF_LABEL_PORT)"
+  ${NSD_CreateLabel} 0 2u 100u 14u "$(TEXT_CONF_LABEL_PORT_SHUTDOWN)"
   Pop $R0
 
-  ${NSD_CreateText} 150u 5u 50u 13u "$TomcatPort"
-  Pop $CtlTomcatPort
-  ${NSD_SetTextLimit} $CtlTomcatPort 5
+  ${NSD_CreateText} 150u 0 50u 12u "$TomcatPortShutdown"
+  Pop $CtlTomcatPortShutdown
+  ${NSD_SetTextLimit} $CtlTomcatPortShutdown 5
+
+  ${NSD_CreateLabel} 0 19u 100u 14u "$(TEXT_CONF_LABEL_PORT_HTTP)"
+  Pop $R0
+
+  ${NSD_CreateText} 150u 17u 50u 12u "$TomcatPortHttp"
+  Pop $CtlTomcatPortHttp
+  ${NSD_SetTextLimit} $CtlTomcatPortHttp 5
+
+  ${NSD_CreateLabel} 0 36u 100u 14u "$(TEXT_CONF_LABEL_PORT_AJP)"
+  Pop $R0
+
+  ${NSD_CreateText} 150u 34u 50u 12u "$TomcatPortAjp"
+  Pop $CtlTomcatPortAjp
+  ${NSD_SetTextLimit} $CtlTomcatPortAjp 5
+
+  ${NSD_CreateLabel} 0 57u 140u 14u "$(TEXT_CONF_LABEL_SERVICE_NAME)"
+  Pop $R0
+
+  ${NSD_CreateText} 150u 55u 140u 12u "$TomcatServiceName"
+  Pop $CtlTomcatServiceName
+
+  ${If} $TomcatMenuEntriesEnable == "1"
+    ${NSD_CreateLabel} 0 75u 100u 14u "$(TEXT_CONF_LABEL_SHORTCUT_ALL_USERS)"
+    Pop $R0
+    ${NSD_CreateCheckBox} 150u 74u 10u 10u "$TomcatShortcutAllUsers"
+    Pop $CtlTomcatShortcutAllUsers
+  ${EndIf}
 
   ${If} $TomcatAdminEnable == "1"
-    ${NSD_CreateLabel} 0 30u 100% 15u "$(TEXT_CONF_LABEL_ADMIN)"
+    ${NSD_CreateLabel} 0 93u 90u 28u "$(TEXT_CONF_LABEL_ADMIN)"
     Pop $R0
-    ${NSD_CreateLabel} 10u 50u 140u 15u "$(TEXT_CONF_LABEL_ADMINUSERNAME)"
+    ${NSD_CreateLabel} 100u 93u 40u 14u "$(TEXT_CONF_LABEL_ADMINUSERNAME)"
     Pop $R0
-    ${NSD_CreateText} 150u 50u 110u 13u "$TomcatAdminUsername"
+    ${NSD_CreateText} 150u 91u 110u 12u "$TomcatAdminUsername"
     Pop $CtlTomcatAdminUsername
-    ${NSD_CreateLabel} 10u 70u 140u 15u "$(TEXT_CONF_LABEL_ADMINPASSWORD)"
+    ${NSD_CreateLabel} 100u 110u 40u 12u "$(TEXT_CONF_LABEL_ADMINPASSWORD)"
     Pop $R0
-    ${NSD_CreatePassword} 150u 70u 110u 13u "$TomcatAdminPassword"
+    ${NSD_CreatePassword} 150u 108u 110u 12u "$TomcatAdminPassword"
     Pop $CtlTomcatAdminPassword
-    ${NSD_CreateLabel} 10u 90u 140u 15u "$(TEXT_CONF_LABEL_ADMINROLES)"
+    ${NSD_CreateLabel} 100u 127u 40u 14u "$(TEXT_CONF_LABEL_ADMINROLES)"
     Pop $R0
-    ${NSD_CreateText} 150u 90u 110u 13u "$TomcatAdminRoles"
+    ${NSD_CreateText} 150u 125u 110u 12u "$TomcatAdminRoles"
     Pop $CtlTomcatAdminRoles
   ${EndIf}
 
-  ${NSD_SetFocus} $CtlTomcatPort
+  ${NSD_SetFocus} $CtlTomcatPortShutdown
   nsDialogs::Show
 FunctionEnd
 
 Function pageConfigurationLeave
-  ${NSD_GetText} $CtlTomcatPort $TomcatPort
+  ${NSD_GetText} $CtlTomcatPortShutdown $TomcatPortShutdown
+  ${NSD_GetText} $CtlTomcatPortHttp $TomcatPortHttp
+  ${NSD_GetText} $CtlTomcatPortAjp $TomcatPortAjp
+  ${NSD_GetText} $CtlTomcatServiceName $TomcatServiceName
+  ${If} $TomcatMenuEntriesEnable == "1"
+    ${NSD_GetState} $CtlTomcatShortcutAllUsers $TomcatShortcutAllUsers
+  ${EndIf}
   ${If} $TomcatAdminEnable == "1"
     ${NSD_GetText} $CtlTomcatAdminUsername $TomcatAdminUsername
     ${NSD_GetText} $CtlTomcatAdminPassword $TomcatAdminPassword
     ${NSD_GetText} $CtlTomcatAdminRoles $TomcatAdminRoles
   ${EndIf}
+
+  ${If} $TomcatPortShutdown == ""
+    MessageBox MB_ICONEXCLAMATION|MB_OK 'The shutdown port may not be empty'
+    Abort "Config not right"
+    Goto exit
+  ${EndIf}
+
+  ${If} $TomcatPortHttp == ""
+    MessageBox MB_ICONEXCLAMATION|MB_OK 'The HTTP port may not be empty'
+    Abort "Config not right"
+    Goto exit
+  ${EndIf}
+
+  ${If} $TomcatPortAjp == ""
+    MessageBox MB_ICONEXCLAMATION|MB_OK 'The AJP port may not be empty'
+    Abort "Config not right"
+    Goto exit
+  ${EndIf}
+
+  ${If} $TomcatServiceName == ""
+    MessageBox MB_ICONEXCLAMATION|MB_OK 'The Service Name may not be empty'
+    Abort "Config not right"
+    Goto exit
+  ${EndIf}
+
+  Push $TomcatServiceName
+  Call validateServiceName
+  Pop $0
+  
+  IntCmp $0 1 exit
+  MessageBox MB_ICONEXCLAMATION|MB_OK 'The Service Name may not contain a space or any of the following characters: <>:"/\:|?*'
+  Abort "Config not right"
+  exit:
 FunctionEnd
 
-; Not used
-;Function Void
-;FunctionEnd
+; Validates that a service name does not use any of the invalid
+; characters: <>:"/\:|?*
+; Note that space is also not permitted although it will be once
+; Tomcat is using Daemon 1.0.6 or later
+;
+; Put the proposed service name on the stack
+; If the name is valid, a 1 will be left on the stack
+; If the name is invalid, a 0 will be left on the stack
+Function validateServiceName
+  Pop $0
+  StrLen $1 $0
+  StrCpy $3 '<>:"/\:|?* '
+  StrLen $4 $3
+  
+  loopInput:
+    IntOp $1 $1 - 1
+    IntCmp $1 -1 valid
+    loopTestChars:
+      IntOp $4 $4 - 1
+      IntCmp $4 -1 loopTestCharsDone
+      StrCpy $2 $0 1 $1
+      StrCpy $5 $3 1 $4
+      StrCmp $2 $5 invalid loopTestChars
+    loopTestCharsDone:
+    StrLen $4 $3
+    Goto loopInput
+
+  invalid:
+  Push 0
+  Goto exit
+  
+  valid:
+  Push 1
+  exit:
+FunctionEnd
 
 ;--------------------------------
 ;Descriptions
-
 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
   !insertmacro MUI_DESCRIPTION_TEXT ${SecTomcat} $(DESC_SecTomcat)
   !insertmacro MUI_DESCRIPTION_TEXT ${SecTomcatCore} $(DESC_SecTomcatCore)
@@ -640,9 +790,17 @@
   ; The default varies depending on 32-bit or 64-bit
   ${If} "$INSTDIR" == ""
     ${If} $Arch == "x86"
-      StrCpy $INSTDIR "$PROGRAMFILES32\Apache Software Foundation\Tomcat @VERSION_MAJOR_MINOR@"
+      ${If} $TomcatServiceName == $TomcatServiceDefaultName
+        StrCpy $INSTDIR "$PROGRAMFILES32\Apache Software Foundation\Tomcat @VERSION_MAJOR_MINOR@"
+      ${Else}
+        StrCpy $INSTDIR "$PROGRAMFILES32\Apache Software Foundation\Tomcat @VERSION_MAJOR_MINOR@_$TomcatServiceName"
+      ${EndIf}
     ${Else}
-      StrCpy $INSTDIR "$PROGRAMFILES64\Apache Software Foundation\Tomcat @VERSION_MAJOR_MINOR@"
+      ${If} $TomcatServiceName == $TomcatServiceDefaultName
+        StrCpy $INSTDIR "$PROGRAMFILES64\Apache Software Foundation\Tomcat @VERSION_MAJOR_MINOR@"
+      ${Else}
+        StrCpy $INSTDIR "$PROGRAMFILES64\Apache Software Foundation\Tomcat @VERSION_MAJOR_MINOR@_$TomcatServiceName"
+      ${EndIf}
     ${EndIf}
   ${EndIf}
 
@@ -660,23 +818,37 @@
 Function findJavaHome
 
   ClearErrors
+  StrCpy $1 ""
 
-  ; Use the 64-bit registry on 64-bit machines
+  ; Use the 64-bit registry first on 64-bit machines
   ExpandEnvStrings $0 "%PROGRAMW6432%"
   ${If} $0 != "%PROGRAMW6432%"
     SetRegView 64
+    ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
+    ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome"
+    ReadRegStr $3 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "RuntimeLib"
+
+    IfErrors 0 +2
+    StrCpy $1 ""
+    ClearErrors
   ${EndIf}
 
-  ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
-  ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome"
-  ReadRegStr $3 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "RuntimeLib"
+  ; If no 64-bit Java was found, look for 32-bit Java
+  ${If} $1 == ""
+    SetRegView 32
+    ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
+    ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome"
+    ReadRegStr $3 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "RuntimeLib"
 
-  IfErrors 0 NoErrors
-  StrCpy $1 ""
-
-NoErrors:
-
-  ClearErrors
+    IfErrors 0 +2
+    StrCpy $1 ""
+    ClearErrors
+    
+    ; If using 64-bit, go back to using 64-bit registry
+    ${If} $0 != "%PROGRAMW6432%"
+      SetRegView 64
+    ${EndIf}
+  ${EndIf}
 
   ; Put the result in the stack
   Push $1
@@ -745,7 +917,38 @@
 ; Writes server.xml and tomcat-users.xml
 ;
 Function configure
-  StrCpy $R4 'port="$TomcatPort"'
+  ; Build final server.xml
+  DetailPrint "Creating server.xml.new"
+
+  FileOpen $R1 "$INSTDIR\conf\server.xml" r
+  FileOpen $R2 "$INSTDIR\conf\server.xml.new" w
+
+  SERVER_XML_LOOP:
+    FileRead $R1 $R3
+    IfErrors SERVER_XML_LEAVELOOP
+    ${StrRep} $R4 $R3 "8005" "$TomcatPortShutdown"
+    ${StrRep} $R3 $R4 "8080" "$TomcatPortHttp"
+    ${StrRep} $R4 $R3 "8009" "$TomcatPortAjp"
+    FileWrite $R2 $R4
+  Goto SERVER_XML_LOOP
+  SERVER_XML_LEAVELOOP:
+
+  FileClose $R1
+  FileClose $R2
+
+  ; Replace server.xml with server.xml.new
+  Delete "$INSTDIR\conf\server.xml"
+  FileOpen $R9 "$INSTDIR\conf\server.xml" w
+  Push "$INSTDIR\conf\server.xml.new"
+  Call copyFile
+  FileClose $R9
+  Delete "$INSTDIR\conf\server.xml.new"
+  
+  DetailPrint 'Server shutdown listener configured on port "$TomcatPortShutdown"'
+  DetailPrint 'HTTP/1.1 Connector configured on port "$TomcatPortHttp"'
+  DetailPrint 'AJP/1.3 Connector configured on port "$TomcatPortAjp"'
+  DetailPrint "server.xml written"
+
   StrCpy $R5 ''
 
   ${If} $TomcatAdminEnable == "1"
@@ -766,31 +969,14 @@
     DetailPrint 'Admin user added: "$TomcatAdminUsername"'
   ${EndIf}
 
-  DetailPrint 'HTTP/1.1 Connector configured on port "$TomcatPort"'
 
   ; Extract these fragments to $PLUGINSDIR. That is a temporary directory,
   ; that is automatically deleted when the installer exits.
   InitPluginsDir
   SetOutPath $PLUGINSDIR
-  File confinstall\server_1.xml
-  File confinstall\server_2.xml
   File confinstall\tomcat-users_1.xml
   File confinstall\tomcat-users_2.xml
 
-  ; Build final server.xml
-  Delete "$INSTDIR\conf\server.xml"
-  DetailPrint "Writing server.xml"
-  FileOpen $R9 "$INSTDIR\conf\server.xml" w
-
-  Push "$PLUGINSDIR\server_1.xml"
-  Call copyFile
-  FileWrite $R9 $R4
-  Push "$PLUGINSDIR\server_2.xml"
-  Call copyFile
-
-  FileClose $R9
-  DetailPrint "server.xml written"
-
   ; Build final tomcat-users.xml
   Delete "$INSTDIR\conf\tomcat-users.xml"
   DetailPrint "Writing tomcat-users.xml"
@@ -812,8 +998,6 @@
   FileClose $R9
   DetailPrint "tomcat-users.xml written"
 
-  Delete "$PLUGINSDIR\server_1.xml"
-  Delete "$PLUGINSDIR\server_2.xml"
   Delete "$PLUGINSDIR\tomcat-users_1.xml"
   Delete "$PLUGINSDIR\tomcat-users_2.xml"
 FunctionEnd
@@ -863,74 +1047,108 @@
 ; =================
 ; createShortcuts Function
 ; =================
-;
-; This is called by the SecMenu section.
-;
-; The code is moved here, because ${SecManager} etc. are not visible
-; in SecMenu, because they are defined lower than it.
-;
 Function createShortcuts
 
-  SetOutPath "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@"
+  ${If} $TomcatShortcutAllUsers == ${BST_CHECKED}
+    SetShellVarContext all
+  ${EndIf}
+  
+  SetOutPath "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName"
 
-  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Tomcat Home Page.lnk" \
+  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Tomcat Home Page.lnk" \
                  "http://tomcat.apache.org/"
 
-  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Welcome.lnk" \
-                 "http://127.0.0.1:$TomcatPort/"
+  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Welcome.lnk" \
+                 "http://127.0.0.1:$TomcatPortHttp/"
 
   ${If} ${SectionIsSelected} ${SecManager}
-    CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Tomcat Manager.lnk" \
-                   "http://127.0.0.1:$TomcatPort/manager/html"
+    CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Tomcat Manager.lnk" \
+                   "http://127.0.0.1:$TomcatPortHttp/manager/html"
   ${EndIf}
 
   ${If} ${SectionIsSelected} ${SecHostManager}
-    CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Tomcat Host Manager.lnk" \
-                   "http://127.0.0.1:$TomcatPort/host-manager/html"
+    CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Tomcat Host Manager.lnk" \
+                   "http://127.0.0.1:$TomcatPortHttp/host-manager/html"
   ${EndIf}
 
   ${If} ${SectionIsSelected} ${SecDocs}
-    CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Tomcat Documentation.lnk" \
-                   "$INSTDIR\webapps\tomcat-docs\index.html"
+    CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Tomcat Documentation.lnk" \
+                   "$INSTDIR\webapps\docs\index.html"
   ${EndIf}
 
-  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Uninstall Tomcat @VERSION_MAJOR_MINOR@.lnk" \
-                 "$INSTDIR\Uninstall.exe"
+  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Uninstall Tomcat @VERSION_MAJOR_MINOR@.lnk" \
+                 "$INSTDIR\Uninstall.exe" '-ServiceName="$TomcatServiceName"'
 
-  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Tomcat @VERSION_MAJOR_MINOR@ Program Directory.lnk" \
+  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Tomcat @VERSION_MAJOR_MINOR@ Program Directory.lnk" \
                  "$INSTDIR"
 
-  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Monitor Tomcat.lnk" \
-                 "$INSTDIR\bin\tomcat@VERSION_MAJOR@w.exe" \
-                 '//MS//Tomcat@VERSION_MAJOR@' \
+  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Monitor Tomcat.lnk" \
+                 "$INSTDIR\bin\$TomcatServiceManagerFileName" \
+                 '//MS//$TomcatServiceName' \
                  "$INSTDIR\tomcat.ico" 0 SW_SHOWNORMAL
 
-  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@\Configure Tomcat.lnk" \
-                 "$INSTDIR\bin\tomcat@VERSION_MAJOR@w.exe" \
-                 '//ES//Tomcat@VERSION_MAJOR@' \
+  CreateShortCut "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName\Configure Tomcat.lnk" \
+                 "$INSTDIR\bin\$TomcatServiceManagerFileName" \
+                 '//ES//$TomcatServiceName' \
                  "$INSTDIR\tomcat.ico" 0 SW_SHOWNORMAL
 
+  ${If} $TomcatShortcutAllUsers == ${BST_CHECKED}
+    SetShellVarContext current
+  ${EndIf}
+
 FunctionEnd
 
+; =================
+; startService Function
+;
+; Using a function allows the service name to be varied
+; =================
+Function startService
+  ExecShell "" "$INSTDIR\bin\$TomcatServiceManagerFileName" "//MR//$TomcatServiceName"
+FunctionEnd
+
+
 ;--------------------------------
 ;Uninstaller Section
 
 Section Uninstall
 
+  ${If} $TomcatServiceName == ""
+    MessageBox MB_ICONSTOP|MB_OK \
+        "No service name specified to uninstall. This will be provided automatically if you uninstall via \
+         Add/Remove Programs or the shortcut on the Start menu. Alternatively, call the installer from \
+         the command line with -ServiceName=$\"<name of service>$\"."
+    Quit
+  ${EndIf}
+  
   Delete "$INSTDIR\Uninstall.exe"
 
   ; Stop Tomcat service monitor if running
-  DetailPrint "Stopping Tomcat@VERSION_MAJOR@ service monitor"
-  nsExec::ExecToLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@w.exe" //MQ//Tomcat@VERSION_MAJOR@'
+  DetailPrint "Stopping $TomcatServiceName service monitor"
+  nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceManagerFileName" //MQ//$TomcatServiceName'
   ; Delete Tomcat service
-  DetailPrint "Uninstalling Tomcat@VERSION_MAJOR@ service"
-  nsExec::ExecToLog '"$INSTDIR\bin\tomcat@VERSION_MAJOR@.exe" //DS//Tomcat@VERSION_MAJOR@'
+  DetailPrint "Uninstalling $TomcatServiceName service"
+  nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //DS//$TomcatServiceName'
   ClearErrors
 
-  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@"
-  DeleteRegKey HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@"
-  DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor"
-  RMDir /r "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@"
+  ; Don't know if 32-bit or 64-bit registry was used so, for now, remove both
+  SetRegView 32
+  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName"
+  DeleteRegKey HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@ $TomcatServiceName"
+  DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor@VERSION_MAJOR_MINOR@_$TomcatServiceName"
+  DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor@VERSION_MAJOR_MINOR@_$TomcatServiceName"
+  SetRegView 64
+  DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName"
+  DeleteRegKey HKLM "SOFTWARE\Apache Software Foundation\Tomcat\@VERSION_MAJOR_MINOR@\$TomcatServiceName"
+  DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor@VERSION_MAJOR_MINOR@_$TomcatServiceName"
+  DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor@VERSION_MAJOR_MINOR@_$TomcatServiceName"
+
+  ; Don't know if short-cuts were created for all users, one user or not at all so, for now, remove both
+  SetShellVarContext all
+  RMDir /r "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName"
+  SetShellVarContext current
+  RMDir /r "$SMPROGRAMS\Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName"
+
   Delete "$INSTDIR\tomcat.ico"
   Delete "$INSTDIR\LICENSE"
   Delete "$INSTDIR\NOTICE"
@@ -955,7 +1173,7 @@
   ; if $INSTDIR was removed, skip these next ones
   IfFileExists "$INSTDIR" 0 Removed
     MessageBox MB_YESNO|MB_ICONQUESTION \
-      "Remove all files in your Tomcat @VERSION_MAJOR_MINOR@ directory? (If you have anything  \
+      "Remove all files in your Apache Tomcat @VERSION_MAJOR_MINOR@ $TomcatServiceName directory? (If you have anything  \
  you created that you want to keep, click No)" IDNO Removed
     ; these would be skipped if the user hits no
     RMDir /r "$INSTDIR\webapps"
@@ -971,4 +1189,18 @@
 
 SectionEnd
 
+
+; =================
+; uninstall init function
+;
+; Read the command line paramater and set up the service name variables so the
+; uninstaller knows which service it is working with
+; =================
+Function un.onInit
+  ${GetParameters} $R0
+  ${GetOPtions} $R0 "-ServiceName=" $R1
+  StrCpy $TomcatServiceName $R1
+  StrCpy $TomcatServiceFileName $R1.exe
+  StrCpy $TomcatServiceManagerFileName $R1w.exe
+FunctionEnd
 ;eof
diff --git a/container/webapps/docs/changelog.xml b/container/webapps/docs/changelog.xml
index b875641..3c7872d 100644
--- a/container/webapps/docs/changelog.xml
+++ b/container/webapps/docs/changelog.xml
@@ -40,6 +40,28 @@
  General, Catalina, Coyote, Jasper, Cluster, Webapps
 -->
 <section name="Tomcat 5.5.34 (jim)" rtext="">
+  <subsection name="General">
+    <changelog>
+      <fix>
+        <bug>33262</bug>: When using the Windows installer, the monitor is now
+        auto-started for the current user rather than all users to be consistent
+        with menu item creation. (markt)
+      </fix>
+      <fix>
+        <bug>40510</bug>: Provide an option within the Windows installer to
+        create menu entries for the current user or all users. (markt)
+      </fix>
+      <fix>
+        <bug>50949</bug>: Add the ability to specify the AJP port and the
+        shutdown port when using the Windows installer. (markt)
+      </fix>
+      <fix>
+        <bug>51135</bug>: Fix auto-detection of JAVA_HOME for 64-bit Windows
+        platforms that only have a 32-bit JVM installed when using the Windows
+        installer. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Catalina">
     <changelog>
       <fix>