[commons-daemon] 05/52: Imported Upstream version 1.0.1

Tony Mancill tmancill at moszumanska.debian.org
Wed Nov 12 05:31:27 UTC 2014


This is an automated email from the git hooks/post-receive script.

tmancill pushed a commit to branch master
in repository commons-daemon.

commit fbfeb357bca52f7547728420fea37127578ab28a
Author: tony mancill <tmancill at debian.org>
Date:   Fri Nov 7 07:59:27 2014 -0800

    Imported Upstream version 1.0.1
---
 NOTICE.txt                                         |    2 +
 README                                             |    6 +-
 RELEASE-NOTES.txt                                  |   12 +-
 STATUS.html                                        |    2 +-
 build.xml                                          |    8 +-
 maven.xml                                          |   36 +
 project.properties                                 |    3 +
 project.xml                                        |  120 +-
 src/java/org/apache/commons/daemon/Daemon.java     |   73 +-
 .../org/apache/commons/daemon/DaemonContext.java   |   73 +-
 .../apache/commons/daemon/DaemonController.java    |   73 +-
 .../org/apache/commons/daemon/DaemonListener.java  |   71 +-
 .../apache/commons/daemon/DaemonPermission.java    |   73 +-
 .../commons/daemon/support/DaemonLoader.java       |   87 +-
 src/native/nt/executables/vdmoniadm/resource.h     |   73 +-
 src/native/nt/executables/vdmonisvc/resource.h     |   73 +-
 src/native/nt/lib/moni_inst.h                      |   16 +
 src/native/nt/moni/vdmoniadm.c                     |   75 +-
 src/native/nt/moni/vdmonisvc.c                     |   75 +-
 src/native/nt/procrun/LICENSE                      |  287 ++
 src/native/nt/procrun/License.rtf                  |   30 -
 src/native/nt/procrun/Makefile                     |   20 -
 src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.c     | 1705 ++++++++++
 src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.h     |  117 +
 .../nt/procrun/apps/apsvcmgr/apsvcmgr.manifest     |   10 +
 src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.rc    |  310 ++
 .../nt/procrun/apps/apsvcmgr/apsvcmgr.vcproj       |  252 ++
 src/native/nt/procrun/apps/jar2exe/jar2exe.c       |  542 ++++
 src/native/nt/procrun/apps/jar2exe/jar2exe.h       |   86 +
 src/native/nt/procrun/apps/jar2exe/jar2exe.rc      |   55 +
 .../jar2exe/jar2exe.vcproj}                        |   75 +-
 src/native/nt/procrun/apps/prunmgr/prunmgr.c       | 1698 ++++++++++
 src/native/nt/procrun/apps/prunmgr/prunmgr.h       |  138 +
 .../nt/procrun/apps/prunmgr/prunmgr.manifest       |   10 +
 src/native/nt/procrun/apps/prunmgr/prunmgr.rc      |  288 ++
 src/native/nt/procrun/apps/prunmgr/prunmgr.vcproj  |  244 ++
 src/native/nt/procrun/apps/prunsrv/prunsrv.c       | 1260 ++++++++
 src/native/nt/procrun/apps/prunsrv/prunsrv.h       |   31 +
 src/native/nt/procrun/apps/prunsrv/prunsrv.rc      |   55 +
 .../prunsrv/prunsrv.vcproj}                        |   76 +-
 src/native/nt/procrun/apps/srvbatch/MSG00001.bin   |  Bin 0 -> 84 bytes
 .../nt/procrun/apps/srvbatch/example/example.c     |   59 +
 .../srvbatch/example/example.vcproj}               |  252 +-
 .../nt/procrun/apps/srvbatch/example/exservice.bat |   53 +
 src/native/nt/procrun/apps/srvbatch/srvbatch.c     |  827 +++++
 src/native/nt/procrun/apps/srvbatch/srvbatch.rc    |   58 +
 src/native/nt/procrun/apps/srvbatch/srvbatch.sln   |   30 +
 .../srvbatch/srvbatch.vcproj}                      |  255 +-
 src/native/nt/procrun/extend.h                     |    3 -
 src/native/nt/procrun/icoi.ico                     |  Bin 318 -> 0 bytes
 src/native/nt/procrun/icos.ico                     |  Bin 318 -> 0 bytes
 src/native/nt/procrun/icow.ico                     |  Bin 318 -> 0 bytes
 src/native/nt/procrun/include/apxwin.h             |  196 ++
 src/native/nt/procrun/include/cmdline.h            |   76 +
 src/native/nt/procrun/include/console.h            |   25 +
 src/native/nt/procrun/include/gui.h                |  185 ++
 src/native/nt/procrun/include/handles.h            |  191 ++
 src/native/nt/procrun/include/javajni.h            |   41 +
 src/native/nt/procrun/include/log.h                |  101 +
 src/native/nt/procrun/include/registry.h           |  145 +
 src/native/nt/procrun/include/rprocess.h           |   75 +
 src/native/nt/procrun/include/service.h            |   72 +
 src/native/nt/procrun/java/Test.java               |   18 +-
 src/native/nt/procrun/libprocrun.vcproj            |  270 ++
 src/native/nt/procrun/procgui.c                    | 1300 --------
 src/native/nt/procrun/procrun.c                    | 3306 --------------------
 src/native/nt/procrun/procrun.dev                  |   62 -
 src/native/nt/procrun/procrun.dsp                  |  293 --
 src/native/nt/procrun/procrun.dsw                  |   41 -
 src/native/nt/procrun/procrun.h                    |  359 ---
 src/native/nt/procrun/procrun.rc                   |  232 --
 src/native/nt/procrun/procrun.sln                  |   92 +-
 src/native/nt/procrun/procrun.vcproj               |  374 ---
 src/native/nt/procrun/procrund.dev                 |   62 -
 src/native/nt/procrun/procrunw.dev                 |   70 -
 src/native/nt/procrun/proctry.ico                  |  Bin 1078 -> 0 bytes
 src/native/nt/procrun/readme.txt                   |  149 -
 src/native/nt/procrun/resources/apsvcmgr.ico       |  Bin 0 -> 7406 bytes
 .../{jakarta-banner.bmp => resources/jakarta.bmp}  |  Bin
 src/native/nt/procrun/resources/license.rtf        |   33 +
 src/native/nt/procrun/resources/procrunr.ico       |  Bin 0 -> 318 bytes
 src/native/nt/procrun/resources/procruns.ico       |  Bin 0 -> 318 bytes
 src/native/nt/procrun/resources/procrunw.ico       |  Bin 0 -> 1078 bytes
 src/native/nt/procrun/resources/sorterd.bmp        |  Bin 0 -> 190 bytes
 src/native/nt/procrun/resources/sorteru.bmp        |  Bin 0 -> 190 bytes
 src/native/nt/procrun/resources/sstatus.bmp        |  Bin 0 -> 630 bytes
 src/native/nt/procrun/resources/susers.bmp         |  Bin 0 -> 886 bytes
 src/native/nt/procrun/resources/toolbar.bmp        |  Bin 0 -> 2294 bytes
 src/native/nt/procrun/samples/cchild.c             |  133 +
 src/native/nt/procrun/samples/cchild.vcproj        |  227 ++
 src/native/nt/procrun/splash.bmp                   |  Bin 116718 -> 0 bytes
 src/native/nt/procrun/src/cmdline.c                |  276 ++
 src/native/nt/procrun/src/console.c                |  149 +
 src/native/nt/procrun/src/gui.c                    | 1024 ++++++
 src/native/nt/procrun/src/handles.c                |  685 ++++
 src/native/nt/procrun/src/javajni.c                |  807 +++++
 src/native/nt/procrun/src/log.c                    |  409 +++
 src/native/nt/procrun/src/mclib.c                  |  285 ++
 src/native/nt/procrun/src/mclib.h                  |   26 +
 src/native/nt/procrun/src/private.h                |  273 ++
 src/native/nt/procrun/src/registry.c               | 1084 +++++++
 src/native/nt/procrun/src/rprocess.c               |  938 ++++++
 src/native/nt/procrun/src/service.c                |  562 ++++
 src/native/nt/procrun/src/utils.c                  |  946 ++++++
 src/native/nt/procrun/testchild/testchild.c        |   66 +-
 src/native/nt/procrun/testchild/testchild.vcproj   |  240 +-
 src/native/nt/procrun/xdocs/index.xml              |   18 +
 src/native/nt/service/instmain.c                   |   75 +-
 src/native/nt/signals/kills.c                      |   73 +-
 src/native/nt/supcalls_nt/vdenv.c                  |   75 +-
 src/native/unix/CHANGES.txt                        |   15 +
 src/native/unix/INSTALL.txt                        |    9 +-
 src/native/unix/Makedefs.in                        |   73 +-
 src/native/unix/Makefile.in                        |   73 +-
 src/native/unix/configure                          |  611 ++--
 src/native/unix/configure.in                       |  100 +-
 src/native/unix/man/README                         |   20 +
 src/native/unix/man/fetch.sh                       |   21 +
 src/native/unix/man/jsvc.1.xml                     |  172 +
 src/native/unix/native/Makefile.in                 |    2 +-
 src/native/unix/native/Tomcat5.sh                  |   24 +-
 src/native/unix/native/arguments.c                 |   31 +-
 src/native/unix/native/arguments.h                 |    8 +-
 src/native/unix/native/debug.c                     |   23 +-
 src/native/unix/native/debug.h                     |    2 +-
 src/native/unix/native/dso-dlfcn.c                 |    2 +-
 src/native/unix/native/dso-dyld.c                  |    2 +-
 src/native/unix/native/dso.h                       |    2 +-
 src/native/unix/native/help.c                      |   11 +-
 src/native/unix/native/help.h                      |    2 +-
 src/native/unix/native/home.c                      |    2 +-
 src/native/unix/native/home.h                      |    2 +-
 src/native/unix/native/java.c                      |  106 +-
 src/native/unix/native/java.h                      |    2 +-
 src/native/unix/native/jsvc-unix.c                 |  275 +-
 src/native/unix/native/jsvc.h                      |    2 +-
 src/native/unix/native/location.c                  |   19 +-
 src/native/unix/native/location.h                  |    2 +-
 src/native/unix/native/replace.c                   |    2 +-
 src/native/unix/native/replace.h                   |    2 +-
 src/native/unix/native/signals.c                   |    2 +-
 src/native/unix/support/apfunctions.m4             |   63 +-
 src/native/unix/support/apjava.m4                  |   63 +-
 src/native/unix/support/apsupport.m4               |  119 +-
 src/native/unix/support/buildconf.sh               |   73 +-
 src/native/unix/support/install.sh                 |  302 +-
 src/samples/AloneDaemon.sh                         |   15 +
 src/samples/AloneService.java                      |   75 +-
 src/samples/Native.c                               |   42 +
 src/samples/Native.sh                              |   18 +
 src/samples/README.txt                             |    6 +-
 src/samples/ServiceDaemon.java                     |   75 +-
 src/samples/ServiceDaemon.sh                       |   15 +
 src/samples/ServiceDaemonReadThread.java           |   74 +-
 src/samples/SimpleDaemon.java                      |  123 +-
 src/samples/SimpleDaemon.sh                        |   22 +
 src/samples/build.xml                              |    8 +-
 .../org/apache/commons/daemon/SimpleDaemon.java    |   75 +-
 xdocs/faq.xml                                      |   22 +
 xdocs/jsvc.xml                                     |   13 +-
 xdocs/navigation.xml                               |    8 +-
 xdocs/procrun.xml                                  |  462 ++-
 162 files changed, 20254 insertions(+), 8954 deletions(-)

diff --git a/NOTICE.txt b/NOTICE.txt
new file mode 100644
index 0000000..3f59805
--- /dev/null
+++ b/NOTICE.txt
@@ -0,0 +1,2 @@
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
diff --git a/README b/README
index 4e29af6..27460f7 100644
--- a/README
+++ b/README
@@ -18,4 +18,8 @@ To build the native part:
 
 To build the documentation:
 maven site:generate
-(Do not forget to get ../project.xml (jakarta-commons/project.xml)
+(Do not forget to get ../commons-build: (cd ..; svn co http://svn.apache.org/repos/asf/jakarta/commons/proper/commons-build/trunk/ commons-build))
+
+To deploy the documentation to apache site:
+maven -Dmaven.username=${user.name} site:deploy
+(Check <siteAddress/> in project.xml).
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index dd9efff..babc7c6 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -1,7 +1,7 @@
-$Id: RELEASE-NOTES.txt,v 1.2 2004/01/13 15:07:07 yoavs Exp $
+$Id: RELEASE-NOTES.txt 170552 2005-05-17 09:02:03Z jfclere $
 
 			Commons Daemon Package
-			   Version 1.0
+			   Version 1.0.1
 			    Release Notes
 
 
@@ -19,7 +19,13 @@ NEW FEATURES:
   for Unix and Windows NT/2K/XP, which allows running a Java program 
   as a native operating system daemon
 
+* Add -wait and -stop parameters. (1.0.1).
+  The -wait parameter is experimental: that a is loop testing for a file in /tmp
+  and waiting n/10 seconds.
+
+* Allow to run as normal user for testing. (1.0.1).
 
-BUG FIXES:
 
+BUG FIXES:
 
+1.0.1: 304310,  30177, 27523, 29465, 31614, 33580, 31613, 34851.
diff --git a/STATUS.html b/STATUS.html
index 92b0757..9c8580b 100644
--- a/STATUS.html
+++ b/STATUS.html
@@ -7,7 +7,7 @@
 
 <div align="center">
 <h1>The Jakarta Commons <em>Daemon</em> Component</h1>
-$Id: STATUS.html,v 1.2 2003/12/31 03:53:52 billbarker Exp $<br />
+$Id: STATUS.html 155409 2005-02-26 12:57:06Z dirkv $<br />
 <a href="#Introduction">[Introduction]</a>
 <a href="#Dependencies">[Dependencies]</a>
 <a href="#Release Info">[Release Info]</a>
diff --git a/build.xml b/build.xml
index b8ed949..63ac93e 100644
--- a/build.xml
+++ b/build.xml
@@ -3,7 +3,7 @@
 
 <!--
         "Daemon" component of the Jakarta Commons Subproject
-        $Id: build.xml,v 1.3 2004/01/13 15:07:07 yoavs Exp $
+        $Id: build.xml 170560 2005-05-17 10:02:51Z jfclere $
 -->
 
 
@@ -43,7 +43,7 @@
   <property name="component.title"         value="Java Daemons"/>
 
   <!-- The current version number of this component -->
-  <property name="component.version"       value="1.0"/>
+  <property name="component.version"       value="1.0.1"/>
 
   <!-- The base directory for compilation targets -->
   <property name="build.home"              value="target"/>
@@ -208,6 +208,8 @@
     <mkdir      dir="${dist.home}/logs"/>
     <copy      file="LICENSE"
               todir="${dist.home}"/>
+    <copy      file="NOTICE.txt"
+              todir="${dist.home}"/>
     <copy      file="RELEASE-NOTES.txt"
               todir="${dist.home}"/>
     <copy todir="${dist.home}/bin/unix/jsvc-src">
@@ -228,6 +230,8 @@
     <mkdir      dir="${build.home}/classes/META-INF"/>
     <copy      file="LICENSE"
              tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
+    <copy      file="NOTICE.txt"
+             tofile="${build.home}/classes/META-INF/NOTICE.txt"/>
     <jar    jarfile="${dist.home}/commons-${component.name}.jar"
             basedir="${build.home}/classes"
            manifest="${build.home}/conf/MANIFEST.MF"
diff --git a/maven.xml b/maven.xml
new file mode 100644
index 0000000..34903d2
--- /dev/null
+++ b/maven.xml
@@ -0,0 +1,36 @@
+<!--
+   Copyright 2001-2004 The Apache Software Foundation
+
+   Licensed 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.
+-->
+<project default="java:jar"
+  xmlns:j="jelly:core">
+
+  <!-- ================================================================== -->
+  <!-- START : C O M M O N S - B U I L D                                  -->
+  <!-- ================================================================== -->
+  <!-- Required: Look and Feel for documentation within distributions     -->
+  <!-- ================================================================== -->
+  <postGoal name="xdoc:copy-resources">  
+    <copy todir="${basedir}/target/docs/style/" failonerror="false">
+      <fileset dir="${basedir}/../commons-build/xdocs/style">
+      	<include name='**/*'/>
+      	<exclude name='**/CVS/**'/>
+      </fileset>
+    </copy>
+  </postGoal>
+  <!-- ================================================================== -->
+  <!-- END: C O M M O N S - B U I L D                                     -->
+  <!-- ================================================================== -->
+  
+</project>
diff --git a/project.properties b/project.properties
index ff1bc8b..5a4d3d5 100755
--- a/project.properties
+++ b/project.properties
@@ -2,11 +2,14 @@
 # Properties that override Maven build defaults
 ##
 
+maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory
+
 #maven.checkstyle.properties=${basedir}/checkstyle.xml
 maven.test.failure = false
 maven.junit.fork=true
 maven.linkcheck.enable=false
 
+maven.xdoc.jsl=../commons-build/commons-site.jsl
 maven.xdoc.date=left
 maven.xdoc.version=${pom.currentVersion}
 maven.xdoc.developmentProcessUrl=http://jakarta.apache.org/commons/charter.html
diff --git a/project.xml b/project.xml
index f8a2114..42716d7 100644
--- a/project.xml
+++ b/project.xml
@@ -1,27 +1,72 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Copyright 2001-2004 The Apache Software Foundation
 
+   Licensed 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.
+-->
 <project>
-  <extend>../commons-build/project.xml</extend>
-  <name>Daemon</name>
+  <pomVersion>3</pomVersion>
+  
   <id>commons-daemon</id>
-  <logo>/images/logo.gif</logo>
-  <currentVersion>1.0</currentVersion>
+  <currentVersion>1.0.1</currentVersion>
+  <inceptionYear>2003</inceptionYear>
+  <name>Daemon</name>
+  <shortDescription>Commons Daemon</shortDescription>
+  <description>Commons Daemon</description>
+  <logo>/images/logo.png</logo>
+  <url>http://jakarta.apache.org/commons/${pom.artifactId.substring(8)}/</url>
+  <package>org.apache.commons.${pom.artifactId.substring(8)}</package>
 
   <organization>
-    <name>Apache Software Foundation</name>
-    <url>http://jakarta.apache.org/</url>
+    <name>The Apache Software Foundation</name>
+    <url>http://jakarta.apache.org</url>
     <logo>http://jakarta.apache.org/images/jakarta-logo.gif</logo>
   </organization>
-  <logo>/images/logo.png</logo>
-
-  <inceptionYear>2003</inceptionYear>
+ 
+  <licenses>
+	<license>
+    	<name>The Apache Software License, Version 2.0</name>
+    	<url>/LICENSE.txt</url>
+    	<distribution>repo</distribution>
+	</license>
+  </licenses>
+  
   <gumpRepositoryId>jakarta</gumpRepositoryId>
-  <shortDescription>Commons Daemon</shortDescription>
-
-  <description>
-    Commons Daemon
-  </description>
+  <issueTrackingUrl>http://issues.apache.org/bugzilla/</issueTrackingUrl>
+  <siteAddress>people.apache.org</siteAddress>
+  <siteDirectory>/www/jakarta.apache.org/commons/${pom.artifactId.substring(8)}/</siteDirectory>
+  <distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons/${pom.artifactId.substring(8)}/</distributionDirectory>
+  
+  <repository>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/jakarta/commons/proper/${pom.artifactId.substring(8)}/trunk</connection>
+    <url>http://svn.apache.org/repos/asf/jakarta/commons/proper/${pom.artifactId.substring(8)}/trunk</url>
+  </repository>
   
+  <mailingLists>
+    <mailingList>
+      <name>Commons Dev List</name>
+      <subscribe>commons-dev-subscribe at jakarta.apache.org</subscribe>
+      <unsubscribe>commons-dev-unsubscribe at jakarta.apache.org</unsubscribe>
+      <archive>http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-dev@jakarta.apache.org</archive>
+    </mailingList>
+    <mailingList>
+      <name>Commons User List</name>
+      <subscribe>commons-user-subscribe at jakarta.apache.org</subscribe>
+      <unsubscribe>commons-user-unsubscribe at jakarta.apache.org</unsubscribe>
+      <archive>http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-user@jakarta.apache.org</archive>
+    </mailingList>
+  </mailingLists>
+
   <developers>
     <developer>
       <name>Jean-Frederic Clere</name>
@@ -52,4 +97,51 @@
     </developer>
   </developers>
 
+  <build>
+    <unitTest>
+      <includes>
+        <include>**/*Test.java</include>
+      </includes>
+      <resources>
+         <resource>
+            <directory>${pom.build.unitTestSourceDirectory}</directory>
+            <includes>
+              <include>**/*.xml</include>
+            </includes>
+         </resource>
+      </resources>
+    </unitTest>
+  </build>
+  
+  <build>
+    	<nagEmailAddress>commons-dev at jakarta.apache.org</nagEmailAddress>
+    	<sourceDirectory>src/java</sourceDirectory>
+    	<unitTestSourceDirectory>src/test</unitTestSourceDirectory>
+    	<integrationUnitTestSourceDirectory/>
+    	<aspectSourceDirectory/>
+
+    	<!-- Unit test classes -->
+    	<unitTest>
+	      	<includes>
+                <include>**/*Test.java</include>
+            </includes>
+            <excludes>
+                <exclude>**/*AbstractTest.java</exclude>
+            </excludes>
+   		</unitTest>
+
+  </build>
+  
+  <reports>
+  	<report>maven-changelog-plugin</report>
+   	<report>maven-changes-plugin</report>
+    <report>maven-developer-activity-plugin</report>
+    <report>maven-file-activity-plugin</report>
+    <report>maven-javadoc-plugin</report>
+    <report>maven-jdepend-plugin</report>
+    <report>maven-junit-report-plugin</report>
+    <report>maven-jxr-plugin</report>
+    <report>maven-license-plugin</report>
+    <report>maven-tasklist-plugin</report>
+  </reports>
 </project>
diff --git a/src/java/org/apache/commons/daemon/Daemon.java b/src/java/org/apache/commons/daemon/Daemon.java
index 79c2320..f363166 100644
--- a/src/java/org/apache/commons/daemon/Daemon.java
+++ b/src/java/org/apache/commons/daemon/Daemon.java
@@ -1,59 +1,18 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *             Copyright (c) 2001 The Apache Software Foundation.            *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The Jakarta  Project",  and  "Apache  Software Foundation" *
- *    must not  be used  to endorse  or promote  products derived  from this *
- *    software without  prior written  permission.  For written  permission, *
- *    please contact <apache at apache.org>.                                    *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
 package org.apache.commons.daemon;
 
@@ -71,7 +30,7 @@ package org.apache.commons.daemon;
  * @author Pier Fumagalli
  * @author Copyright © 2000-2001 <a href="http://www.apache.org/">The
  *         Apache Software Foundation</a>. All rights reserved.
- * @version 1.0 <i>(CVS $Revision: 1.3 $)</i>
+ * @version 1.0 <i>(CVS $Revision: 155409 $)</i>
  */
 public interface Daemon {
 
diff --git a/src/java/org/apache/commons/daemon/DaemonContext.java b/src/java/org/apache/commons/daemon/DaemonContext.java
index 2d5e60e..3acd4ee 100644
--- a/src/java/org/apache/commons/daemon/DaemonContext.java
+++ b/src/java/org/apache/commons/daemon/DaemonContext.java
@@ -1,59 +1,18 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *             Copyright (c) 2001 The Apache Software Foundation.            *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The Jakarta  Project",  and  "Apache  Software Foundation" *
- *    must not  be used  to endorse  or promote  products derived  from this *
- *    software without  prior written  permission.  For written  permission, *
- *    please contact <apache at apache.org>.                                    *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
 package org.apache.commons.daemon;
 
@@ -65,7 +24,7 @@ package org.apache.commons.daemon;
  * @author Pier Fumagalli
  * @author Copyright © 2000-2001 <a href="http://www.apache.org/">The
  *         Apache Software Foundation</a>. All rights reserved.
- * @version 1.0 <i>(CVS $Revision: 1.3 $)</i>
+ * @version 1.0 <i>(CVS $Revision: 155409 $)</i>
  */
 public interface DaemonContext {
 
diff --git a/src/java/org/apache/commons/daemon/DaemonController.java b/src/java/org/apache/commons/daemon/DaemonController.java
index 2ef2c90..7aade88 100644
--- a/src/java/org/apache/commons/daemon/DaemonController.java
+++ b/src/java/org/apache/commons/daemon/DaemonController.java
@@ -1,59 +1,18 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *             Copyright (c) 2001 The Apache Software Foundation.            *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The Jakarta  Project",  and  "Apache  Software Foundation" *
- *    must not  be used  to endorse  or promote  products derived  from this *
- *    software without  prior written  permission.  For written  permission, *
- *    please contact <apache at apache.org>.                                    *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
 package org.apache.commons.daemon;
 
@@ -63,7 +22,7 @@ package org.apache.commons.daemon;
  * @author Pier Fumagalli
  * @author Copyright © 2000-2001 <a href="http://www.apache.org/">The
  *         Apache Software Foundation</a>. All rights reserved.
- * @version 1.0 <i>(CVS $Revision: 1.2 $)</i>
+ * @version 1.0 <i>(CVS $Revision: 155409 $)</i>
  */
 public interface DaemonController {
 
diff --git a/src/java/org/apache/commons/daemon/DaemonListener.java b/src/java/org/apache/commons/daemon/DaemonListener.java
index df64f08..9a419eb 100644
--- a/src/java/org/apache/commons/daemon/DaemonListener.java
+++ b/src/java/org/apache/commons/daemon/DaemonListener.java
@@ -1,59 +1,18 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *             Copyright (c) 2001 The Apache Software Foundation.            *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The Jakarta  Project",  and  "Apache  Software Foundation" *
- *    must not  be used  to endorse  or promote  products derived  from this *
- *    software without  prior written  permission.  For written  permission, *
- *    please contact <apache at apache.org>.                                    *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
 package org.apache.commons.daemon;
 
diff --git a/src/java/org/apache/commons/daemon/DaemonPermission.java b/src/java/org/apache/commons/daemon/DaemonPermission.java
index 3e84926..8a6fada 100644
--- a/src/java/org/apache/commons/daemon/DaemonPermission.java
+++ b/src/java/org/apache/commons/daemon/DaemonPermission.java
@@ -1,59 +1,18 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *             Copyright (c) 2001 The Apache Software Foundation.            *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The Jakarta  Project",  and  "Apache  Software Foundation" *
- *    must not  be used  to endorse  or promote  products derived  from this *
- *    software without  prior written  permission.  For written  permission, *
- *    please contact <apache at apache.org>.                                    *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
 package org.apache.commons.daemon;
 
@@ -125,7 +84,7 @@ import java.util.StringTokenizer;
  * @author Pier Fumagalli
  * @author Copyright © 2000-2001 <a href="http://www.apache.org/">The
  *         Apache Software Foundation</a>. All rights reserved.
- * @version 1.0 <i>(CVS $Revision: 1.2 $)</i>
+ * @version 1.0 <i>(CVS $Revision: 155409 $)</i>
  */
 public final class DaemonPermission extends Permission {
 
diff --git a/src/java/org/apache/commons/daemon/support/DaemonLoader.java b/src/java/org/apache/commons/daemon/support/DaemonLoader.java
index 0ffccce..b710899 100644
--- a/src/java/org/apache/commons/daemon/support/DaemonLoader.java
+++ b/src/java/org/apache/commons/daemon/support/DaemonLoader.java
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2003 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: DaemonLoader.java,v 1.3 2003/09/27 16:49:13 jfclere Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: DaemonLoader.java 155409 2005-02-26 12:57:06Z dirkv $ */
 
 package org.apache.commons.daemon.support;
 
@@ -151,14 +110,14 @@ public final class DaemonLoader {
             if (c==null) throw new ClassNotFoundException(cn);
 
             /* Check interface */
-            Class[] interf = c.getInterfaces();
             boolean isdaemon = false;
-            if ( interf != null ) {
-              for(int i=0;i<interf.length;i++) {
-                if (interf[i].getName().equals("org.apache.commons.daemon.Daemon"))
-                  isdaemon = true;
-              }
+            try {
+              Class dclass = cl.loadClass("org.apache.commons.daemon.Daemon");
+              isdaemon = dclass.isAssignableFrom(c);
+            } catch(Exception cnfex) {
+              // Swallow if Daemon not found.
             }
+
             /* Check methods */
             Class[] myclass = new Class[1];
             if (isdaemon) {
diff --git a/src/native/nt/executables/vdmoniadm/resource.h b/src/native/nt/executables/vdmoniadm/resource.h
index 65877c3..c969996 100644
--- a/src/native/nt/executables/vdmoniadm/resource.h
+++ b/src/native/nt/executables/vdmoniadm/resource.h
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2002 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
-/* @version $Id: resource.h,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/* @version $Id: resource.h 155409 2005-02-26 12:57:06Z dirkv $ */
 /* Used by vdmoniadm.rc */
 #define NO_ACCESS                       1
 #define NO_ACCESS_MONI                  2
diff --git a/src/native/nt/executables/vdmonisvc/resource.h b/src/native/nt/executables/vdmonisvc/resource.h
index 83c6f1b..d9d94f9 100644
--- a/src/native/nt/executables/vdmonisvc/resource.h
+++ b/src/native/nt/executables/vdmonisvc/resource.h
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
-/* @version $Id: resource.h,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/* @version $Id: resource.h 155409 2005-02-26 12:57:06Z dirkv $ */
 /* Used by vdmonisvc.rc */
 
 /* Next default values for new objects */
diff --git a/src/native/nt/lib/moni_inst.h b/src/native/nt/lib/moni_inst.h
index 326649e..fe27196 100644
--- a/src/native/nt/lib/moni_inst.h
+++ b/src/native/nt/lib/moni_inst.h
@@ -1,4 +1,20 @@
 /*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/*
  * include for the service installation
  */
 #define SZAPPNAME               "JavaService"
diff --git a/src/native/nt/moni/vdmoniadm.c b/src/native/nt/moni/vdmoniadm.c
index 9fcc124..0a14a29 100644
--- a/src/native/nt/moni/vdmoniadm.c
+++ b/src/native/nt/moni/vdmoniadm.c
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: vdmoniadm.c,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: vdmoniadm.c 155409 2005-02-26 12:57:06Z dirkv $ */
 
 #include <windows.h>       /* required for all Windows applications */
 #include <stdio.h>         /* for sprintf                           */
diff --git a/src/native/nt/moni/vdmonisvc.c b/src/native/nt/moni/vdmonisvc.c
index dee44bd..3e4c015 100644
--- a/src/native/nt/moni/vdmonisvc.c
+++ b/src/native/nt/moni/vdmonisvc.c
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: vdmonisvc.c,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: vdmonisvc.c 155409 2005-02-26 12:57:06Z dirkv $ */
 
 /* jsvc monitor service module:
  * Implements the body of the service.
diff --git a/src/native/nt/procrun/LICENSE b/src/native/nt/procrun/LICENSE
new file mode 100644
index 0000000..876754a
--- /dev/null
+++ b/src/native/nt/procrun/LICENSE
@@ -0,0 +1,287 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+
+
+
+APACHE PORTABLE RUNTIME SUBCOMPONENTS: 
+
+The Apache Portable Runtime includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses. 
+
+For the include\apr_md5.h component: 
+/*
+ * This is work is derived from material Copyright RSA Data Security, Inc.
+ *
+ * The RSA copyright statement and Licence for that original material is
+ * included below. This is followed by the Apache copyright statement and
+ * licence for the modifications made to that material.
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.
+
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.
+
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.
+ */
+
+For the passwd\apr_md5.c component:
+
+/*
+ * This is work is derived from material Copyright RSA Data Security, Inc.
+ *
+ * The RSA copyright statement and Licence for that original material is
+ * included below. This is followed by the Apache copyright statement and
+ * licence for the modifications made to that material.
+ */
+
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.
+
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.
+
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.
+ */
+/*
+ * The apr_md5_encode() routine uses much code obtained from the FreeBSD 3.0
+ * MD5 crypt() function, which is licenced as follows:
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk at login.dknet.dk> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.  Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ */
+
diff --git a/src/native/nt/procrun/License.rtf b/src/native/nt/procrun/License.rtf
deleted file mode 100644
index f81125d..0000000
--- a/src/native/nt/procrun/License.rtf
+++ /dev/null
@@ -1,30 +0,0 @@
-{\rtf1\ansi\ansicpg1252\uc1 \deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
-{\f34\froman\fcharset238\fprq2 Times New Roman CE;}{\f35\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f37\froman\fcharset161\fprq2 Times New Roman Greek;}{\f38\froman\fcharset162\fprq2 Times New Roman Tur;}
-{\f39\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f40\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f41\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f42\fswiss\fcharset238\fprq2 Arial CE;}{\f43\fswiss\fcharset204\fprq2 Arial Cyr;}
-{\f45\fswiss\fcharset161\fprq2 Arial Greek;}{\f46\fswiss\fcharset162\fprq2 Arial Tur;}{\f47\fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f48\fswiss\fcharset178\fprq2 Arial (Arabic);}{\f49\fswiss\fcharset186\fprq2 Arial Baltic;}}
-{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;
-\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 
-\fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}{\*\cs15 \additive \ul\cf2 \sbasedon10 Hyperlink;}}{\info{\author Mladen Turk}{\operator Sara D Wilken}{\creatim\yr2003\mo4\dy9\hr14\min37}
-{\revtim\yr2004\mo2\dy10\hr21\min22}{\version4}{\edmins2}{\nofpages1}{\nofwords370}{\nofchars2113}{\*\company Apache Software Foundation}{\nofcharsws0}{\vern8269}}
-\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind4\viewscale100\nolnhtadjtbl \fet0\sectd \linex0\sectdefaultcl 
-{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}{\*\pnseclvl5
-\pndec\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang
-{\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}\pard\plain \ql \li0\ri0\nowidctlpar\faauto\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\f1\fs20 The Apac
-he Software License, Version 2.0
-\par }{\f1\fs18 
-\par }{\f1\fs18      Copyright 2002-2004 The Apache Software Foundation.
-\par    
-\par      Licensed under the Apache License, Version 2.0 (the "License");
-\par      you may not use this file except in compliance with the License.
-\par      You may obtain a copy of the License at
-\par    
-\par          }{\field{\*\fldinst {\f1\fs18  HYPERLINK "http://www.apache.org/licenses/LICENSE-2.0" }{\f1\fs18 {\*\datafield 
-00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b5600000068007400740070003a002f002f007700770077002e006100700061006300680065002e006f00720067002f006c006900630065006e007300650073002f004c004900430045004e00530045002d0032002e00
-30000000}}}{\fldrslt {\cs15\ul\cf2 http://www.apache.org/licenses/LICENSE-2.0}}}{\f1\fs18 
-\par    
-\par      Unless required by applicable law or agreed to in writing, software
-\par      distributed under the License is distributed on an "AS IS" BASIS,
-\par      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-\par      See the License for the specific language governing permissions and
-\par      limitations under the License.}{\f1\fs18 
-\par }}
\ No newline at end of file
diff --git a/src/native/nt/procrun/Makefile b/src/native/nt/procrun/Makefile
deleted file mode 100644
index 735fb55..0000000
--- a/src/native/nt/procrun/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-JAVA_HOME=c:/j2sdk1.4.1_01
-INCLUDE=-I. -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32
-BIN=.
-# CFLAGS for debugging
-#CFLAGS=-D_DEBUG
-
-all: $(BIN)/procrun $(BIN)/procrunw
-
-$(BIN)/procrun: procrun.c
-	gcc -mno-cygwin $(INCLUDE) $(CFLAGS) -DPROCRUN_CONSOLE procrun.c \
-	-lshlwapi \
-	-o $(BIN)/procrun
-
-$(BIN)/procrunw: procrun.c
-	gcc -mno-cygwin $(INCLUDE) $(CFLAGS) -DPROCRUN_WINAPP -c procgui.c
-	gcc -mno-cygwin $(INCLUDE) $(CFLAGS) -DPROCRUN_WINAPP procrun.c \
-	procgui.o \
-	-lshlwapi \
-	-lcomctl32 \
-	-o $(BIN)/procrunw
diff --git a/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.c b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.c
new file mode 100644
index 0000000..8971d5f
--- /dev/null
+++ b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.c
@@ -0,0 +1,1705 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "apsvcmgr.h"
+
+LPAPXGUISTORE _gui_store  = NULL;
+HWND          hWndToolbar = NULL;
+HWND          hWndList    = NULL;
+HWND          hWndListHdr = NULL;
+WNDPROC       ListViewWinMain;
+WNDPROC       ListViewWinHead;
+HWND          hWndStatus  = NULL;
+HWND          hWndModal   = NULL;
+LVHITTESTINFO lvLastHit;
+int           lvHitItem = -1;
+/* Toolbar buttons 
+ * TODO: Localize...
+ */
+TBBUTTON tbButtons[] = {
+    { 4, IDAM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+    { 5, IDAM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+    { 7, IDMS_REFRESH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+    {16, IDMV_FILTER, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
+    { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
+    { 8, IDAM_DELETE, 0, TBSTYLE_BUTTON, 0, 0},
+    { 6, IDMS_PROPERTIES, 0, TBSTYLE_BUTTON, 0, 0},
+    { 0, IDMS_START, 0, TBSTYLE_BUTTON, 0, 0},
+    { 1, IDMS_STOP, 0, TBSTYLE_BUTTON, 0, 0},
+    { 2, IDMS_PAUSE, 0, TBSTYLE_BUTTON, 0, 0},
+    { 3, IDMS_RESTART, 0, TBSTYLE_BUTTON, 0, 0},
+    { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
+    {11, IDMH_HELP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0}
+};
+
+APXLVITEM lvItems[] = {
+    { 0, FALSE, 80,  80, LVCFMT_LEFT, TEXT("Status") },
+    { 0, TRUE, 120, 120, LVCFMT_LEFT, TEXT("Name") },
+    { 0, TRUE, 240, 240, LVCFMT_LEFT, TEXT("Description") },
+    { 0, TRUE,  80,  80, LVCFMT_LEFT, TEXT("Startup Type") },
+    { 0, TRUE,  80,  80, LVCFMT_LEFT, TEXT("Log On As") },
+    { 0, FALSE, 80,  80, LVCFMT_RIGHT, TEXT("Process Id") },
+    { 0, FALSE,  0,  80, LVCFMT_RIGHT, TEXT("# Handles") }
+};
+
+#define NUMTBBUTTONS  (sizeof(tbButtons) / sizeof(tbButtons[0]))
+#define NUMLVITEMS    (sizeof(lvItems) / sizeof(lvItems[0]))
+
+#define APSVCMGR_CLASS      TEXT("APSVCMGR")
+
+/* Display only Started/Paused status */
+#define STAT_STARTED        TEXT("Started")
+#define STAT_PAUSED         TEXT("Paused")
+#define STAT_STOPPED        TEXT("Stopped")
+#define STAT_DISABLED       TEXT("Disabled")
+#define STAT_NONE           TEXT("")
+#define STAT_SYSTEM         L"LocalSystem"
+
+#define START_AUTO           L"Automatic"
+#define START_MANUAL         L"Manual"
+#define START_DISABLED       L"Disabled"
+#define START_BOOT           L"Boot"
+#define START_SYSTEM         L"SystemInit"
+
+#define SFILT_KEY            L"Filters"
+#define SFILT_INAME          L"IncludeName"
+#define SFILT_XNAME          L"ExcludeName"
+#define SFILT_ISIMG          L"IncludeImage"
+#define SFILT_XSIMG          L"ExcludeImage"
+
+#define DISPLAY_KEY          "Display"
+#define DISPLAY_STATE        "GuiState"
+#define EMPTY_PASSWORD       L"               "
+#define EXPORT_TITLE         "Export Services list"
+#define EXPORT_EXTFILT       "Comma separated (*.csv)\0*.csv\0Tab Delimited (*.tab)\0*.txt\0All Files(*.*)\0*.*\0"
+
+
+#define WM_TIMER_REFRESH    10
+#define WM_USER_LREFRESH    WM_USER + 1
+#define UPD_FAST            10000
+#define UPD_SLOW            60000
+
+static int _toolbarHeight = 0;
+static int _statbarHeight = 0;
+static int _currentTimer  = IDMV_UPAUSED;
+static int _currentLitem  = 0;
+static int _listviewCols  = 0;
+static int _sortOrder     = 1;
+static int _sortColumn    = 1;
+static LPAPXSERVENTRY     _currentEntry = NULL;
+
+static LPWSTR   _filterIname    = NULL;
+static LPWSTR   _filterXname    = NULL;
+static LPWSTR   _filterIimage   = NULL;
+static LPWSTR   _filterXimage   = NULL;
+static LPSTR    _exportFilename = NULL;
+static DWORD    _exportIndex    = 0;
+/* Main application pool */
+APXHANDLE hPool     = NULL;
+APXHANDLE hService  = NULL;
+APXHANDLE hRegistry = NULL;
+
+/* Service browse callback declaration */
+BOOL ServiceCallback(APXHANDLE hObject, UINT uMsg,
+                     WPARAM wParam, LPARAM lParam);
+
+int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+{
+    WCHAR  szA[1024] = {0};
+    WCHAR  szB[1024] = {0};
+    int    rc;
+    ListView_GetItemTextW(hWndList, (INT)lParam1, _sortColumn, szA, 1023);
+    ListView_GetItemTextW(hWndList, (INT)lParam2, _sortColumn, szB, 1023);
+    rc = lstrcmpW(szA, szB);
+
+    return rc * _sortOrder;
+}
+
+void DestroyListView()
+{
+    int i, x;
+    
+    x = ListView_GetItemCount(hWndList);
+    if (x > 0) {
+        LV_ITEM lvI;
+        lvI.mask = LVIF_PARAM;
+        for (i = 0; i < x; i++) {
+            lvI.iItem  = i;
+            lvI.lParam = 0;
+            ListView_GetItem(hWndList, &lvI);
+            if (lvI.lParam) {
+                LPAPXSERVENTRY lpEnt = (LPAPXSERVENTRY)lvI.lParam;
+                apxFree(lpEnt->lpConfig);
+                apxFree(lpEnt);
+            }
+        }
+    }
+    ListView_DeleteAllItems(hWndList);
+    _currentLitem = 0;
+}
+
+BOOL ExportListView(LPCSTR szFileName, DWORD dwIndex)
+{
+    int i, j, x;
+    CHAR szI[SIZ_DESLEN];
+    HANDLE hFile;
+    DWORD  dwWriten;
+    LPSTR  szD;
+    hFile = CreateFileA(szFileName, 
+                        GENERIC_WRITE,
+                        0,
+                        NULL,
+                        CREATE_ALWAYS,
+                        FILE_ATTRIBUTE_NORMAL,
+                        NULL);
+    if (IS_INVALID_HANDLE(hFile))
+        return FALSE;
+    x = ListView_GetItemCount(hWndList);
+    if (x > 0) {
+        LV_ITEM lvI;
+        lvI.mask = LVIF_PARAM;
+
+        if (dwIndex == 1)
+            szD = ";";
+        else
+            szD = "\t";
+        WriteFile(hFile, "ServiceName", sizeof("ServiceName") - 1, &dwWriten, NULL);
+        for (i = 1; i <  NUMLVITEMS; i++) {
+            if (lvItems[i].iWidth) {
+#ifdef _UNICODE
+                WideToAscii(lvItems[i].szLabel, szI);
+#else
+                lstrcpyA(szI, lvItems[i].szLabel);
+#endif
+                WriteFile(hFile, szD, 1, &dwWriten, NULL);
+                WriteFile(hFile, szI, lstrlenA(szI), &dwWriten, NULL);
+            }
+        }
+        WriteFile(hFile, "\r\n", 2, &dwWriten, NULL);           
+        for (i = 0; i < x; i++) {
+            lvI.iItem  = i;
+            lvI.lParam = 0;
+            ListView_GetItem(hWndList, &lvI);
+            if (lvI.lParam) {
+                LPAPXSERVENTRY lpEnt = (LPAPXSERVENTRY)lvI.lParam;
+                WideToAscii(lpEnt->szServiceName, szI);
+                WriteFile(hFile, szI, lstrlenA(szI), &dwWriten, NULL);
+                WriteFile(hFile, szD, 1, &dwWriten, NULL);
+                
+            }
+            for (j = 1; j < _listviewCols - 1; j++) {
+                szI[0] = '\0';
+                ListView_GetItemTextA(hWndList, i, j, szI, SIZ_DESMAX);
+                if (szI[0])
+                    WriteFile(hFile, szI, lstrlenA(szI), &dwWriten, NULL);
+                WriteFile(hFile, szD, 1, &dwWriten, NULL);
+            }
+            szI[0] = '\0';
+            ListView_GetItemTextA(hWndList, i, j, szI, SIZ_DESMAX);
+            if (szI[0])
+                WriteFile(hFile, szI, lstrlenA(szI), &dwWriten, NULL);
+            WriteFile(hFile, "\r\n", 2, &dwWriten, NULL);           
+        }
+    }  
+    CloseHandle(hFile);
+    return TRUE;
+}
+
+void RefreshServices(int iRefresh)
+{
+    int prev = _currentLitem;
+    _currentLitem = 0;
+    apxServiceBrowse(hService, _filterIname, _filterIimage,
+                     _filterXname, _filterXimage, WM_USER+1+iRefresh,
+                     ServiceCallback, NULL);
+    ListView_SortItemsEx(hWndList, CompareFunc, NULL);
+    if (prev > _currentLitem) {
+        DestroyListView();
+        apxServiceBrowse(hService, _filterIname, _filterIimage,
+                         _filterXname, _filterXimage, WM_USER+1,
+                         ServiceCallback, NULL);
+        ListView_SortItemsEx(hWndList, CompareFunc, NULL);
+    }
+    if ((lvHitItem = ListView_GetSelectionMark(hWndList)) >= 0) {
+#if 0
+        /* Ensure that the selected is visible */
+        ListView_EnsureVisible(hWndList,lvHitItem, FALSE);
+#endif
+        PostMessage(hWndList, WM_USER_LREFRESH, 0, 0);
+    }
+}
+
+void RestoreRefreshTimer()
+{
+    if (_currentTimer == IDMV_UFAST)
+        SetTimer(_gui_store->hMainWnd, WM_TIMER_REFRESH, UPD_FAST, NULL); 
+    else if (_currentTimer == IDMV_USLOW)
+        SetTimer(_gui_store->hMainWnd, WM_TIMER_REFRESH, UPD_SLOW, NULL); 
+    else
+        KillTimer(_gui_store->hMainWnd, WM_TIMER_REFRESH);
+}
+
+/* wParam progress dialog handle
+ */
+static BOOL __startServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                   WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+    APXHANDLE hSrv;
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            hSrv = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+            if (!hSrv) {
+                EndDialog(hDlg, IDOK);
+                PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                            MAKEWPARAM(IDMS_REFRESH, 0), 0);
+                return FALSE;
+            }
+            if (!apxServiceOpen(hSrv, _currentEntry->szServiceName,
+                                GENERIC_READ | GENERIC_EXECUTE)) {
+                apxCloseHandle(hSrv);
+                EndDialog(hDlg, IDOK);
+                PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                            MAKEWPARAM(IDMS_REFRESH, 0), 0);
+                return FALSE;
+            }
+            if (apxServiceControl(hSrv, SERVICE_CONTROL_CONTINUE, WM_USER+2,
+                                  __startServiceCallback, hDlg)) {
+                _currentEntry->stServiceStatus.dwCurrentState = SERVICE_RUNNING;
+                _currentEntry->stStatusProcess.dwCurrentState = SERVICE_RUNNING;
+                                
+            }
+            apxCloseHandle(hSrv);
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(500);
+            break;
+    }
+    return TRUE;
+}
+
+static BOOL __stopServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                   WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+    APXHANDLE hSrv;
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            hSrv = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+            if (!hSrv)
+                return FALSE;
+            if (!apxServiceOpen(hSrv, _currentEntry->szServiceName,
+                                GENERIC_READ | GENERIC_EXECUTE)) {
+                apxCloseHandle(hSrv);
+                return FALSE;
+            }
+            if (apxServiceControl(hSrv, SERVICE_CONTROL_STOP, WM_USER+2,
+                                  __stopServiceCallback, hDlg)) {
+            }
+            apxCloseHandle(hSrv);
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            if (wParam == 4)
+                AplCopyMemory(&_currentEntry->stServiceStatus,
+                              (LPVOID)lParam, sizeof(SERVICE_STATUS));
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(100);
+            break;
+    }
+    return TRUE;
+}
+
+static BOOL __restartServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                     WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+    APXHANDLE hSrv;
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            hSrv = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+            if (!hSrv)
+                return FALSE;
+            if (!apxServiceOpen(hSrv, _currentEntry->szServiceName,
+                                GENERIC_READ | GENERIC_EXECUTE)) {
+                apxCloseHandle(hSrv);
+                return FALSE;
+            }
+            /* TODO: use 128 as controll code */
+            if (apxServiceControl(hSrv, 128, WM_USER+2,
+                                  __restartServiceCallback, hDlg)) {
+                                
+            }
+            apxCloseHandle(hSrv);
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            if (wParam == 4)
+                AplCopyMemory(&_currentEntry->stServiceStatus,
+                              (LPVOID)lParam, sizeof(SERVICE_STATUS));
+
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(100);
+            break;
+    }
+    return TRUE;
+}
+
+static BOOL __pauseServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                   WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+    APXHANDLE hSrv;
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            hSrv = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+            if (!hSrv)
+                return FALSE;
+            if (!apxServiceOpen(hSrv, _currentEntry->szServiceName,
+                                GENERIC_READ | GENERIC_EXECUTE)) {
+                apxCloseHandle(hSrv);
+                return FALSE;
+            }
+            if (apxServiceControl(hSrv, SERVICE_CONTROL_PAUSE, WM_USER+2,
+                                  __pauseServiceCallback, hDlg)) {
+            }
+            apxCloseHandle(hSrv);
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            if (wParam == 4)
+                AplCopyMemory(&_currentEntry->stServiceStatus,
+                             (LPVOID)lParam, sizeof(SERVICE_STATUS));
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(100);
+            break;
+    }
+    return TRUE;
+}
+
+LRESULT CALLBACK ListViewMainSubclass(HWND hWnd, UINT uMsg, WPARAM wParam,
+                                      LPARAM lParam)
+{
+    static POINTS  mouseClick;
+
+    HMENU         hMenu = NULL;
+    HMENU         hLoad = NULL;
+    HMENU         hMain = NULL;
+    switch (uMsg) {
+        case WM_LBUTTONDOWN:
+        case WM_RBUTTONDOWN:
+        case WM_LBUTTONDBLCLK:
+            mouseClick = MAKEPOINTS(lParam);
+            lvLastHit.pt.x = mouseClick.x;
+            lvLastHit.pt.y = mouseClick.y;
+        case WM_USER_LREFRESH:
+            lvHitItem = ListView_HitTest(hWndList, &lvLastHit);
+            _currentEntry = NULL;
+            hMain = GetMenu(_gui_store->hMainWnd);
+            CallWindowProc(ListViewWinMain, hWnd, uMsg, wParam, lParam);
+            EnableMenuItem(hMain, IDMS_START, MF_BYCOMMAND | MF_GRAYED);
+            EnableMenuItem(hMain, IDMS_STOP, MF_BYCOMMAND | MF_GRAYED);
+            EnableMenuItem(hMain, IDMS_PAUSE, MF_BYCOMMAND | MF_GRAYED);
+            EnableMenuItem(hMain, IDMS_RESTART, MF_BYCOMMAND | MF_GRAYED);
+            EnableMenuItem(hMain, IDAM_DELETE, MF_BYCOMMAND | MF_GRAYED);
+            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_START, FALSE);
+            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_STOP, FALSE);
+            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_PAUSE, FALSE);
+            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_RESTART, FALSE);
+            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_PROPERTIES, FALSE);
+            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDAM_DELETE, FALSE);
+            EnableMenuItem(hMain, IDMS_PROPERTIES, MF_BYCOMMAND | MF_GRAYED);
+
+            if (lvHitItem >= 0) {
+                LV_ITEM lvI;
+                lvI.mask = LVIF_PARAM;
+                lvI.iItem  = lvHitItem;
+                lvI.lParam = 0;
+                ListView_GetItem(hWndList, &lvI);
+                if (lvI.lParam) {
+                    _currentEntry = (LPAPXSERVENTRY)lvI.lParam;
+                    SendMessageW(hWndStatus, WM_SETTEXT, 0, (LPARAM)_currentEntry->szServiceDescription);
+                    if (uMsg == WM_RBUTTONDOWN) {
+                        hLoad = LoadMenu(_gui_store->hInstance,
+                                         MAKEINTRESOURCE(IDM_POPUPMENU));
+
+                        hMenu = GetSubMenu(hLoad, 0);
+                    }
+                    switch (_currentEntry->stServiceStatus.dwCurrentState) {
+                        case SERVICE_RUNNING:
+                            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP) {
+                                SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_STOP, TRUE);
+                                EnableMenuItem(hMain, IDMS_STOP, MF_BYCOMMAND | MF_ENABLED);
+                                if (hMenu)
+                                    EnableMenuItem(hMenu, IDMS_STOP, MF_BYCOMMAND | MF_ENABLED);
+                            }
+                            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) {
+                                SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_PAUSE, TRUE);
+                                SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_RESTART, TRUE);
+                                EnableMenuItem(hMain, IDMS_PAUSE, MF_BYCOMMAND | MF_ENABLED);
+                                EnableMenuItem(hMain, IDMS_RESTART, MF_BYCOMMAND | MF_ENABLED);
+                                if (hMenu) {
+                                    EnableMenuItem(hMenu, IDMS_PAUSE, MF_BYCOMMAND | MF_ENABLED);
+                                    EnableMenuItem(hMenu, IDMS_RESTART, MF_BYCOMMAND | MF_ENABLED);
+                                }
+                            }                            
+                        break;
+                        case SERVICE_PAUSED:
+                            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_RESTART, TRUE);
+                            SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_START, TRUE);
+                            EnableMenuItem(hMain, IDMS_RESTART, MF_BYCOMMAND | MF_ENABLED);
+                            EnableMenuItem(hMain, IDMS_START, MF_BYCOMMAND | MF_ENABLED);
+                            if (hMenu) {
+                                EnableMenuItem(hMenu, IDMS_RESTART, MF_BYCOMMAND | MF_ENABLED);
+                                EnableMenuItem(hMenu, IDMS_START, MF_BYCOMMAND | MF_ENABLED);
+                            }
+                        break;
+                        case SERVICE_STOPPED:
+                            if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+                                SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_START, TRUE);
+                                EnableMenuItem(hMain, IDMS_START, MF_BYCOMMAND | MF_ENABLED);
+                                if (hMenu)
+                                    EnableMenuItem(hMenu, IDMS_START, MF_BYCOMMAND | MF_ENABLED);
+                            }
+                        break;
+                        default:
+
+                        break;
+                    }
+                }
+                SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMS_PROPERTIES, TRUE);
+                EnableMenuItem(hMain, IDMS_PROPERTIES, MF_BYCOMMAND | MF_ENABLED);
+                SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDAM_DELETE, TRUE);
+                EnableMenuItem(hMain, IDAM_DELETE, MF_BYCOMMAND | MF_ENABLED);
+                SetMenuDefaultItem(GetSubMenu(hMain, 1), IDMS_PROPERTIES, FALSE);
+
+                if (hMenu) {
+                    POINT pt; 
+                    EnableMenuItem(hMenu, IDMS_PROPERTIES, MF_BYCOMMAND | MF_ENABLED);
+                    SetMenuDefaultItem(hMenu, IDMS_PROPERTIES, FALSE);
+
+                    GetCursorPos(&pt); 
+                    TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
+                        pt.x, pt.y, 0, _gui_store->hMainWnd, NULL);
+                    DestroyMenu(hLoad);
+                    hMenu = NULL;
+                    hLoad = NULL;
+                }
+                /* Post the Properties message to main window */
+                if (uMsg == WM_LBUTTONDBLCLK) {
+                    PostMessage(_gui_store->hMainWnd, WM_COMMAND, 
+                                MAKEWPARAM(IDMS_PROPERTIES, 0), 0);
+                }
+            }
+            else {
+                SetMenuDefaultItem(GetSubMenu(hMain, 1), -1, FALSE);
+                SendMessageW(hWndStatus, WM_SETTEXT, 0, (LPARAM)(L""));
+            }
+            return TRUE;
+        break;
+    }
+    return CallWindowProc(ListViewWinMain, hWnd, uMsg, wParam, lParam);
+}
+
+LRESULT CALLBACK ListViewHeadSubclass(HWND hWnd, UINT uMsg, WPARAM wParam,
+                                      LPARAM lParam)
+{
+    DWORD     i, n = 0;
+
+    switch (uMsg) {
+        case WM_LBUTTONUP:
+            CallWindowProc(ListViewWinHead, hWnd, uMsg, wParam, lParam);
+            for (i = 0; i < NUMLVITEMS; i++) {
+                if (lvItems[i].iWidth) {
+                    lvItems[i].iWidth = ListView_GetColumnWidth(hWndList, n++);
+                }
+            }
+            return TRUE;
+        break;
+
+    }
+    return CallWindowProc(ListViewWinHead, hWnd, uMsg, wParam, lParam);
+}
+
+HWND CreateServiceList(HWND hWndParent)
+{
+    HWND        hWndList;
+    RECT        rc;
+    LV_COLUMN   lvC;
+    DWORD       i;
+    HBITMAP     hStatBmp;
+    HIMAGELIST  hStatImg;
+    DWORD       dwStyle;
+
+    dwStyle =   WS_TABSTOP | 
+                WS_CHILD | 
+                WS_VISIBLE |
+                LVS_SINGLESEL |
+                LVS_REPORT;
+
+    GetWindowRect(hWndToolbar, &rc);
+    _toolbarHeight = rc.bottom - rc.top;
+    GetWindowRect(hWndStatus, &rc);
+    _statbarHeight = rc.bottom - rc.top;
+    /* Get the size and position of the parent window. */
+    GetClientRect(hWndParent, &rc);
+
+    /* Create the list view window */
+    hWndList = CreateWindowEx(WS_EX_CLIENTEDGE,
+                              WC_LISTVIEW, TEXT(""), 
+                              dwStyle,
+                              0, _toolbarHeight, 
+                              rc.right - rc.left, 
+                              rc.bottom - rc.top - _toolbarHeight - _statbarHeight,
+                              hWndParent,
+                              (HMENU)IDC_LISTVIEW,
+                              _gui_store->hInstance, NULL);
+    if (hWndList == NULL)
+        return NULL;
+    GetClientRect(hWndList, &rc);
+    hStatImg = ImageList_Create(16, 16, ILC_COLOR4, 0, 16);
+    hStatBmp = LoadImage(GetModuleHandleA(NULL), MAKEINTRESOURCE(IDB_SSTATUS),
+                         IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
+
+    ImageList_Add(hStatImg, hStatBmp, NULL);
+    DeleteObject(hStatBmp);
+
+    ListView_SetImageList(hWndList, hStatImg, LVSIL_SMALL);
+    lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+    _listviewCols = 0;
+    for (i = 0; i < NUMLVITEMS; i++) {
+        lvC.iSubItem = i;
+        lvC.cx       = lvItems[i].iWidth;
+        lvC.pszText  = lvItems[i].szLabel;
+        lvC.fmt      = lvItems[i].iFmt;
+        if (lvItems[i].iWidth > 0) {
+            ListView_InsertColumn(hWndList, i, &lvC ); 
+            _listviewCols++;
+        }
+    }
+#ifdef LVS_EX_FULLROWSELECT
+    ListView_SetExtendedListViewStyleEx(hWndList, 0,
+                LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
+#endif 
+    hWndListHdr = ListView_GetHeader(hWndList);
+    /* Sub-class */
+    ListViewWinMain = (WNDPROC)((SIZE_T)SetWindowLong(hWndList, GWL_WNDPROC, 
+                                                      (LONG)((SIZE_T)ListViewMainSubclass))); 
+
+    ListViewWinHead = (WNDPROC)((SIZE_T)SetWindowLong(hWndListHdr, GWL_WNDPROC, 
+                                                      (LONG)((SIZE_T)ListViewHeadSubclass))); 
+
+
+    return hWndList;
+}
+
+static DWORD  _propertyChanged;
+/* Service property pages */
+void CALLBACK __propertyCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
+{
+    switch(uMsg) {
+        case PSCB_PRECREATE:       
+           {
+                LPDLGTEMPLATE  lpTemplate = (LPDLGTEMPLATE)lParam;
+                if (!(lpTemplate->style & WS_SYSMENU))
+                    lpTemplate->style |= WS_SYSMENU;
+                apxCenterWindow(hwndPropSheet, _gui_store->hMainWnd);
+                _propertyChanged = 0;
+            }
+        break;
+        case PSCB_INITIALIZED:
+        break;
+
+    }
+}
+
+BOOL __generalPropertySave(HWND hDlg) 
+{
+    APXHANDLE hSrv;
+    WCHAR szN[256];
+    WCHAR szD[256];
+    DWORD dwStartType = SERVICE_NO_CHANGE;
+    int i;
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 1);
+
+    if (!(hSrv = apxCreateService(hPool, SC_MANAGER_CREATE_SERVICE, FALSE)))
+        return FALSE;
+    if (!apxServiceOpen(hSrv, _currentEntry->szServiceName, SERVICE_ALL_ACCESS)) {
+        apxCloseHandle(hSrv);
+        return FALSE;
+    }
+    GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, 255);
+    GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, 1023);
+    i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
+    if (i == 0)
+        dwStartType = SERVICE_AUTO_START;
+    else if (i == 1)
+        dwStartType = SERVICE_DEMAND_START;
+    else if (i == 2)
+        dwStartType = SERVICE_DISABLED;
+    apxServiceSetNames(hSrv, NULL, szN, szD, NULL, NULL);
+    apxServiceSetOptions(hSrv, SERVICE_NO_CHANGE, dwStartType, SERVICE_NO_CHANGE);
+
+    apxCloseHandle(hSrv);
+    if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+
+    return TRUE;
+}
+
+BOOL __generalLogonSave(HWND hDlg) 
+{
+    APXHANDLE hSrv;
+    WCHAR szU[64];
+    WCHAR szP[64];
+    WCHAR szC[64];
+    DWORD dwStartType = SERVICE_NO_CHANGE;
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 2);
+
+    if (!(hSrv = apxCreateService(hPool, SC_MANAGER_CREATE_SERVICE, FALSE)))
+        return FALSE;
+    if (!apxServiceOpen(hSrv, _currentEntry->szServiceName, SERVICE_ALL_ACCESS)) {
+        apxCloseHandle(hSrv);
+        return FALSE;
+    }
+    GetDlgItemTextW(hDlg, IDC_PPSLUSER,  szU, 63);
+    GetDlgItemTextW(hDlg, IDC_PPSLPASS,  szP, 63);
+    GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+    
+    if (lstrlenW(szU) && lstrcmpiW(szU, STAT_SYSTEM)) {
+        if (szP[0] != L' ' &&  szC[0] != L' ' && !lstrcmpW(szP, szC))
+            apxServiceSetNames(hSrv, NULL, NULL, NULL, szU, szP);
+        else {
+            MessageBoxW(hDlg, apxLoadResourceW(IDS_VALIDPASS, 0),
+                        apxLoadResourceW(IDS_APPLICATION, 1),
+                        MB_OK | MB_ICONSTOP);
+            apxCloseHandle(hSrv);
+            return FALSE;
+        }
+    }             
+    else {
+        if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED)
+            apxServiceSetOptions(hSrv,
+                _currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
+                SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+        else
+            apxServiceSetOptions(hSrv,
+                _currentEntry->stServiceStatus.dwServiceType & ~SERVICE_INTERACTIVE_PROCESS,
+                SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+    }
+    apxCloseHandle(hSrv);
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+    return TRUE;
+}
+
+void __generalPropertyRefresh(HWND hDlg)
+{
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), FALSE);
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), FALSE);
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), FALSE);
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), FALSE);
+    switch (_currentEntry->stServiceStatus.dwCurrentState) {
+        case SERVICE_RUNNING:
+            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP ||
+                _currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), TRUE);
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STARTED);
+            }
+            else
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) {
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), TRUE);
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+            }
+        break;
+        case SERVICE_PAUSED:
+            Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+            Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+            SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_PAUSED);
+        break;
+        case SERVICE_STOPPED:
+            if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+            }
+            else
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STOPPED);
+        break;
+        default:
+        break;
+    }
+}
+
+LRESULT CALLBACK __generalProperty(HWND hDlg,
+                                   UINT uMessage,
+                                   WPARAM wParam,
+                                   LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    WCHAR       szBuf[1024]; 
+
+    switch (uMessage) { 
+        case WM_INITDIALOG: 
+            {
+                PROPSHEETPAGE *lpPage = (PROPSHEETPAGE *)lParam;
+                LPAPXSERVENTRY lpService;
+                BOOL           bLocalSystem = TRUE;
+                
+                lpService = ( LPAPXSERVENTRY)lpPage->lParam;
+                SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, 255, 0);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, 1023, 0);
+
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_AUTO);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_MANUAL);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_DISABLED);
+                if (_currentEntry->lpConfig->dwStartType == SERVICE_AUTO_START)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 0);
+                else if (_currentEntry->lpConfig->dwStartType == SERVICE_DEMAND_START)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 1);
+                else if (_currentEntry->lpConfig->dwStartType == SERVICE_DISABLED)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 2);
+
+                SetDlgItemTextW(hDlg, IDC_PPSGNAME, _currentEntry->szServiceName);
+                SetDlgItemTextW(hDlg, IDC_PPSGDISP, _currentEntry->lpConfig->lpDisplayName);
+                SetDlgItemTextW(hDlg, IDC_PPSGDESC, _currentEntry->szServiceDescription);
+                SetDlgItemTextW(hDlg, IDC_PPSGDEXE, _currentEntry->lpConfig->lpBinaryPathName);
+                __generalPropertyRefresh(hDlg);
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPSGCMBST:
+                    if (HIWORD(wParam) == CBN_SELCHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 1);
+                    }
+                break;
+                case IDC_PPSGDISP:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, 255);
+                        if (!lstrcmpW(szBuf, _currentEntry->lpConfig->lpDisplayName)) {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 1);
+                        }
+                        else {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 1);
+                        }
+                    }
+                break;
+                case IDC_PPSGDESC:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, 1023);
+                        if (!lstrcmpW(szBuf, _currentEntry->szServiceDescription)) {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 1);
+                        }
+                        else {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 1);
+                        }
+                    }
+                break;
+                case IDC_PPSGSTART:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSSTART, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __startServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+                case IDC_PPSGSTOP:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSSTOP, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __stopServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+                case IDC_PPSGPAUSE:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSPAUSE, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __pauseServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+                case IDC_PPSGRESTART:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSRESTART, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __restartServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+            }
+        break;
+        case WM_NOTIFY:           
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalPropertySave(hDlg)) {
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                    }
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 1);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+                default:
+                break;
+            }
+        break;
+        default:
+        break;
+    }
+ 
+    return FALSE;
+}
+
+LRESULT CALLBACK __logonProperty(HWND hDlg,
+                                 UINT uMessage,
+                                 WPARAM wParam,
+                                 LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    WCHAR       szBuf[1024]; 
+    switch (uMessage) { 
+        case WM_INITDIALOG:
+            {
+                BOOL           bAccount = FALSE;
+                
+                SendMessage(GetDlgItem(hDlg, IDC_PPSLUSER), EM_LIMITTEXT, 63, 0);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSLPASS), EM_LIMITTEXT, 63, 0);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSLCPASS), EM_LIMITTEXT, 63, 0);
+                if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+                    bAccount = TRUE;
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLUA);
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+                    SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+                    SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+                }
+                else {
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLLS);
+                    if (_currentEntry->lpConfig->dwServiceType & 
+                        SERVICE_INTERACTIVE_PROCESS)
+                        CheckDlgButton(hDlg, IDC_PPSLID, BST_CHECKED);
+                }
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), !bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), bAccount);
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPSLLS:
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, L"");
+                    SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
+                    SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), FALSE);
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);                     
+                    if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    else {
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                        CLR_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    break;
+                case IDC_PPSLUA:
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+                    SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+                    SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), TRUE);
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);                     
+                    if (lstrcmpW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    else {
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                        CLR_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    break;
+                case IDC_PPSLID:
+                    PropSheet_Changed(GetParent(hDlg), hDlg); 
+                    SET_BIT_FLAG(_propertyChanged, 2);
+                break;
+                case IDC_PPSLUSER:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, 63);
+                        if (!lstrcmpiW(szBuf, _currentEntry->szObjectName)) {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 2);
+                        }
+                        else {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 2);
+                        }
+                    }
+                break;
+                case IDC_PPSLPASS:
+                case IDC_PPSLCPASS:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        WCHAR szP[64];
+                        WCHAR szC[64];
+                        GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
+                        GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+                        /* check for valid password match */
+                        if (szP[0] == L' ' &&  szC[0] == L' ') {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 2);
+                        }
+                        else if (!lstrcmpW(szP, szC)) {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 2);
+                        }
+                    }
+                break;
+                case IDC_PPSLBROWSE:
+                    {
+                        WCHAR szUser[SIZ_RESLEN];
+                        if (apxDlgSelectUser(hDlg, szUser))
+                            SetDlgItemTextW(hDlg, IDC_PPSLUSER, szUser);
+                    }
+                break;
+            }
+        break;
+        case WM_NOTIFY:
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalLogonSave(hDlg))
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 2);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+            }
+        break;
+
+        default:
+        break;
+    }
+    return FALSE;
+}
+
+void __initPpage(PROPSHEETPAGEW *lpPage, INT iDlg, INT iTitle, DLGPROC pfnDlgProc)
+{
+    lpPage->dwSize      = sizeof(PROPSHEETPAGE);
+    lpPage->dwFlags     = PSP_USETITLE;
+    lpPage->hInstance   = _gui_store->hInstance;
+    lpPage->pszTemplate = MAKEINTRESOURCEW(iDlg);
+    lpPage->pszIcon     = NULL;
+    lpPage->pfnDlgProc  = pfnDlgProc;
+    lpPage->pszTitle    = MAKEINTRESOURCEW(iTitle);
+    lpPage->lParam      = 0;
+}
+
+INT_PTR ShowServiceProperties(HWND hWnd)
+{
+    PROPSHEETPAGEW   psP[5];
+    PROPSHEETHEADERW psH; 
+    WCHAR           szT[1024] = {0};
+
+    __initPpage(&psP[0], IDD_PROPPAGE_SGENERAL, IDS_PPGENERAL, 
+                __generalProperty);
+    __initPpage(&psP[1], IDD_PROPPAGE_LOGON, IDS_PPLOGON, 
+                __logonProperty);
+
+    if (_currentEntry && _currentEntry->lpConfig)
+        lstrcpyW(szT, _currentEntry->lpConfig->lpDisplayName);
+    else
+        return (INT_PTR)0;
+    lstrcatW(szT, L" Service Properties");
+
+    psH.dwSize           = sizeof(PROPSHEETHEADER);
+    psH.dwFlags          = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
+    psH.hwndParent       = hWnd;
+    psH.hInstance        = _gui_store->hInstance;
+    psH.pszIcon          = MAKEINTRESOURCEW(IDI_MAINICON);
+    psH.pszCaption       = szT;
+    psH.nPages           = 2;
+    psH.ppsp             = (LPCPROPSHEETPAGEW) &psP;
+    psH.pfnCallback      = (PFNPROPSHEETCALLBACK)__propertyCallback;
+    psH.nStartPage       = 0;   
+
+    return PropertySheetW(&psH);
+}
+
+static LRESULT CALLBACK __filtersDlgProc(HWND hDlg, UINT uMsg,
+                                         WPARAM wParam, LPARAM lParam)
+{
+
+    switch (uMsg) {
+        case WM_INITDIALOG:
+            apxCenterWindow(hDlg, _gui_store->hMainWnd);
+            if (_filterIname)
+                SetDlgItemTextW(hDlg, IDC_FINAME, _filterIname);
+            if (_filterIimage)
+                SetDlgItemTextW(hDlg, IDC_FISIMG, _filterIimage);
+            if (_filterXname)
+                SetDlgItemTextW(hDlg, IDC_FXNAME, _filterXname);
+            if (_filterXimage)
+                SetDlgItemTextW(hDlg, IDC_FXSIMG, _filterXimage);
+            return TRUE;
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDOK:
+                    {
+                        apxFree(_filterIname);
+                        _filterIname = apxGetDlgTextW(hPool, hDlg, IDC_FINAME);
+                        apxFree(_filterXname);
+                        _filterXname = apxGetDlgTextW(hPool, hDlg, IDC_FXNAME);
+                        apxFree(_filterIimage);
+                        _filterIimage = apxGetDlgTextW(hPool, hDlg, IDC_FISIMG);
+                        apxFree(_filterXimage);
+                        _filterXimage = apxGetDlgTextW(hPool, hDlg, IDC_FXSIMG);
+                        PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                                    MAKEWPARAM(IDMS_REFRESH, 0), 0);
+                    }
+                case IDCANCEL:
+                    EndDialog(hDlg, LOWORD(wParam));
+                return TRUE;
+            }
+        break;
+    }
+    return FALSE;
+} 
+
+void EditServiceFilters(HWND hWnd)
+{
+
+   DialogBox(_gui_store->hInstance,
+              MAKEINTRESOURCE(IDD_FILTER),
+              hWnd,
+              (DLGPROC)__filtersDlgProc);
+
+}
+
+static LRESULT CALLBACK __selectColsDlgProc(HWND hDlg, UINT uMsg,
+                                            WPARAM wParam, LPARAM lParam)
+{
+
+    switch (uMsg) {
+        case WM_INITDIALOG:
+            apxCenterWindow(hDlg, _gui_store->hMainWnd);
+            CheckDlgButton(hDlg, IDC_CCOL1, lvItems[1].iWidth != 0);
+            CheckDlgButton(hDlg, IDC_CCOL2, lvItems[2].iWidth != 0);
+            CheckDlgButton(hDlg, IDC_CCOL3, lvItems[3].iWidth != 0);
+            CheckDlgButton(hDlg, IDC_CCOL4, lvItems[4].iWidth != 0);
+            CheckDlgButton(hDlg, IDC_CCOL5, lvItems[5].iWidth != 0);
+
+            return TRUE;
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDOK:
+                    if (IsDlgButtonChecked(hDlg, IDC_CCOL1) != BST_CHECKED)
+                        lvItems[1].iWidth = 0;
+                    else if (lvItems[1].iWidth == 0)
+                        lvItems[1].iWidth = lvItems[1].iDefault;
+                    if (IsDlgButtonChecked(hDlg, IDC_CCOL2) != BST_CHECKED)
+                        lvItems[2].iWidth = 0;
+                    else if (lvItems[2].iWidth == 0)
+                        lvItems[2].iWidth = lvItems[2].iDefault;
+                    if (IsDlgButtonChecked(hDlg, IDC_CCOL3) != BST_CHECKED)
+                        lvItems[3].iWidth = 0;
+                    else if (lvItems[3].iWidth == 0)
+                        lvItems[3].iWidth = lvItems[3].iDefault;
+                    if (IsDlgButtonChecked(hDlg, IDC_CCOL4) != BST_CHECKED)
+                        lvItems[4].iWidth = 0;
+                    else if (lvItems[4].iWidth == 0)
+                        lvItems[4].iWidth = lvItems[4].iDefault;
+                    if (IsDlgButtonChecked(hDlg, IDC_CCOL5) != BST_CHECKED)
+                        lvItems[5].iWidth = 0;
+                    else if (lvItems[5].iWidth == 0)
+                        lvItems[5].iWidth = lvItems[5].iDefault;
+                    CloseWindow(hWndList);
+                    hWndList = CreateServiceList(_gui_store->hMainWnd); 
+
+                    PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                                MAKEWPARAM(IDMS_REFRESH, 0), 0);
+
+                case IDCANCEL:
+                    EndDialog(hDlg, LOWORD(wParam));
+                return TRUE;
+            }
+        break;
+    }
+    return FALSE;
+} 
+
+void SelectDisplayColumns(HWND hWnd)
+{
+
+   DialogBox(_gui_store->hInstance,
+              MAKEINTRESOURCE(IDD_SELCOL),
+              hWnd,
+              (DLGPROC)__selectColsDlgProc);
+
+}
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg,
+                             WPARAM wParam, LPARAM lParam) 
+{
+    RECT rcP;
+    LPNMHDR     lpNmHdr; 
+
+    switch (uMsg) {
+        case WM_CREATE:
+
+            hWndToolbar = CreateToolbarEx(hWnd, 
+                                          WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT,  
+                                          IDC_TOOLBAR, NUMTOOLBUTTONS,
+                                          _gui_store->hInstance, IDB_TOOLBAR,
+                                          (LPCTBBUTTON)&tbButtons,
+                                          NUMTBBUTTONS, 16,16,16,16, sizeof(TBBUTTON)); 
+            hWndStatus = CreateStatusWindow(0x0800 /* SBT_TOOLTIPS */
+                                            | WS_CHILD | WS_VISIBLE,
+                                            TEXT(""), hWnd, IDC_STATBAR); 
+
+            hWndList = CreateServiceList(hWnd); 
+            RefreshServices(0);
+            CheckMenuRadioItem(GetMenu(hWnd), IDMV_UFAST, IDMV_UPAUSED,
+                               _currentTimer, MF_BYCOMMAND);
+            RestoreRefreshTimer();
+            return FALSE;
+        break;
+        case WM_SETFOCUS:
+            SetFocus(hWndList);
+            return FALSE;
+        break;
+        case WM_SIZE:
+            MoveWindow(hWndToolbar, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
+            MoveWindow(hWndList, 0, _toolbarHeight, LOWORD(lParam),
+                       HIWORD(lParam) -  _toolbarHeight - _statbarHeight, TRUE);
+            MoveWindow(hWndStatus, 0, HIWORD(lParam) - _statbarHeight, 
+                       LOWORD(lParam), HIWORD(lParam), TRUE);
+            GetWindowRect(hWnd, &rcP);
+            _gui_store->stState.rcPosition.top    = rcP.top;
+            _gui_store->stState.rcPosition.left   = rcP.left;
+            _gui_store->stState.rcPosition.right  = ABS(rcP.right - rcP.left);
+            _gui_store->stState.rcPosition.bottom = ABS(rcP.bottom - rcP.top);
+            if (wParam == SIZE_MAXIMIZED)
+                _gui_store->stState.dwShow = SW_SHOWMAXIMIZED;
+            else
+                _gui_store->stState.dwShow = SW_SHOW;
+
+            return FALSE;
+        break;   
+        case WM_TIMER: 
+            if (wParam == WM_TIMER_REFRESH) {
+                KillTimer(hWnd, WM_TIMER_REFRESH);
+                RefreshServices(1);
+                RestoreRefreshTimer();
+            }
+        break;
+        case WM_NOTIFY: 
+            lpNmHdr = (NMHDR FAR *)lParam;
+            switch (lpNmHdr->code) { 
+                case TTN_GETDISPINFO: 
+                    { 
+                        LPTOOLTIPTEXT lpttt; 
+                        lpttt = (LPTOOLTIPTEXT)lParam; 
+                        lpttt->hinst = _gui_store->hInstance; 
+                        /* Specify the resource identifier of the descriptive 
+                         * text for the given button. 
+                         */
+                        lpttt->lpszText = MAKEINTRESOURCE(lpttt->hdr.idFrom);
+                    }
+                break; 
+                case LVN_COLUMNCLICK :
+                    {
+                        LPNMLISTVIEW pLvi = (LPNMLISTVIEW)lParam;
+                        /* Find the real column */
+                        if (pLvi->iSubItem >= 0) {
+                            INT i, x = 0;
+                            for (i = 0; i < NUMLVITEMS; i++) {
+                                if (lvItems[i].iWidth && x < pLvi->iSubItem)
+                                    ++x;
+                                else
+                                    break;
+                            }
+                            if (lvItems[x].bSortable) {
+                                if (_sortColumn == x)
+                                    _sortOrder *= (-1);
+                                else {
+                                    _sortColumn = x;
+                                    _sortOrder  = 1;
+                                }
+                                ListView_SortItemsEx(hWndList, CompareFunc, NULL);
+                                if ((lvHitItem = ListView_GetSelectionMark(hWndList)) >= 0) {
+                                    ListView_EnsureVisible(hWndList,lvHitItem, FALSE);
+                                }
+                            }
+                        }
+                    }
+                break;
+                /* 
+                 * Process other notifications here. 
+                 */ 
+                default: 
+                break; 
+            } 
+        break;
+        case WM_COMMAND:
+            switch(LOWORD(wParam)) {
+                case IDMS_REFRESH:
+                    KillTimer(hWnd, WM_TIMER_REFRESH);
+                    RefreshServices(1);
+                    RestoreRefreshTimer();
+                break;
+                case IDAM_TRY:
+                    apxManageTryIconA(hWnd, NIM_ADD, NULL,
+                                      apxLoadResourceA(IDS_APPLICATION, 0),
+                                      NULL);
+
+                    KillTimer(hWnd, WM_TIMER_REFRESH);
+                    ShowWindow(hWnd, SW_HIDE);
+                break;
+                case IDAM_EXIT:
+                    SendMessage(hWnd, WM_CLOSE, 0, 0);
+                break;
+                case IDMH_ABOUT:
+                    apxAboutBox(hWnd);
+                break;
+                case IDMS_START:
+                    apxProgressBox(hWnd, apxLoadResource(IDS_HSSTART, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __startServiceCallback, NULL);
+                break;
+                case IDMS_STOP:
+                    apxProgressBox(hWnd, apxLoadResource(IDS_HSSTOP, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __stopServiceCallback, NULL);
+                break;
+                case IDMS_PAUSE:
+                    apxProgressBox(hWnd, apxLoadResource(IDS_HSPAUSE, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __pauseServiceCallback, NULL);
+                break;
+                case IDMS_RESTART:
+                    apxProgressBox(hWnd, apxLoadResource(IDS_HSRESTART, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __restartServiceCallback, NULL);
+                break;
+                case IDMS_PROPERTIES:
+                    KillTimer(hWnd, WM_TIMER_REFRESH);
+                    ShowServiceProperties(hWnd);
+                    RestoreRefreshTimer();
+                break;
+                case IDMV_UFAST:
+                case IDMV_USLOW:
+                case IDMV_UPAUSED:
+                    _currentTimer = LOWORD(wParam);
+                    CheckMenuRadioItem(GetMenu(hWnd), IDMV_UFAST, IDMV_UPAUSED,
+                                       _currentTimer, MF_BYCOMMAND);
+                    RestoreRefreshTimer();
+                break;
+                case IDAM_DELETE:
+                    {
+                        TCHAR szT[1024+128];
+#ifndef _UNICODE
+                        CHAR dName[1024];
+                        WideToAscii(_currentEntry->lpConfig->lpDisplayName, dName);
+#endif
+                        if (!_currentEntry || !_currentEntry->lpConfig)
+                            return FALSE;
+
+                        wsprintf(szT, apxLoadResource(IDS_DELSERVICET, 0),
+#ifdef _UNICODE
+                                 _currentEntry->lpConfig->lpDisplayName);
+#else
+                                 dName);
+#endif
+                        KillTimer(hWnd, WM_TIMER_REFRESH);
+                        if (apxYesNoMessage(apxLoadResource(IDS_DELSERVICEC, 0),
+                                            szT, TRUE)) {
+                            APXHANDLE hSrv;
+                            if ((hSrv = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE))) {
+                                if (apxServiceOpen(hSrv, _currentEntry->szServiceName,
+                                                   SERVICE_ALL_ACCESS)) {
+                                    apxServiceDelete(hSrv);
+                                    RefreshServices(1);
+                                }
+                                apxCloseHandle(hSrv);
+                            }
+                        }
+                        RestoreRefreshTimer();
+                    }
+                break;
+                case IDMV_FILTER:
+                    EditServiceFilters(hWnd);
+                break;
+                case IDMV_SELECTCOLUMNS:
+                    SelectDisplayColumns(hWnd);
+                break;
+                case IDAM_SAVE:
+                    if (_exportFilename) {
+                        ExportListView(_exportFilename, _exportIndex);
+                        return FALSE;
+                    }
+                case IDAM_SAVEAS:
+                    if (_exportFilename)
+                        apxFree(_exportFilename);
+                    _exportFilename = apxGetFileNameA(hWnd, EXPORT_TITLE,
+                                                      EXPORT_EXTFILT,
+                                                      ".csv", NULL, FALSE,
+                                                      &_exportIndex);
+                    if (_exportFilename)
+                        ExportListView(_exportFilename, _exportIndex);
+                break;
+                case IDAM_NEW:
+                    /* TODO: New service wizard */
+                    MessageBox(hWnd, apxLoadResource(IDS_NOTIMPLEMENTED, 0),
+                               apxLoadResource(IDS_APPLICATION, 1),
+                               MB_OK | MB_ICONINFORMATION);
+                break;
+                default:
+                    return DefWindowProc(hWnd, uMsg, wParam, lParam); 
+                break;
+            }
+        break;
+        case WM_TRAYMESSAGE:
+            switch(lParam) {
+                case WM_LBUTTONDBLCLK:
+                    ShowWindow(hWnd, SW_SHOW);
+                    apxManageTryIconA(hWnd, NIM_DELETE, NULL, NULL, NULL);
+                    RestoreRefreshTimer();
+                break;
+            }
+        break;
+        case WM_MOUSEWHEEL:
+            {
+                int nScroll;
+                if ((SHORT)HIWORD(wParam) < 0)
+                    nScroll = _gui_store->nWhellScroll;
+                else
+                    nScroll = _gui_store->nWhellScroll * (-1);
+                ListView_Scroll(hWndList, 0, nScroll * 16);
+            }
+        break;
+        case WM_QUIT:
+            OutputDebugString(TEXT("WM_QUIT"));
+            return DefWindowProc(hWnd, uMsg, wParam, lParam); 
+        break;
+        case WM_DESTROY:
+            DestroyListView();
+            apxManageTryIconA(hWnd, NIM_DELETE, NULL, NULL, NULL);
+            OutputDebugString(TEXT("WM_DESTROY"));
+            PostQuitMessage(0);
+            return FALSE;
+        break;
+        default:
+            return DefWindowProc(hWnd, uMsg, wParam, lParam); 
+        break;
+    }
+
+    return FALSE; 
+}
+
+/* Browse service callback */
+BOOL ServiceCallback(APXHANDLE hObject, UINT uMsg,
+                     WPARAM wParam, LPARAM lParam)
+{
+    LPAPXSERVENTRY  lpEnt = (LPAPXSERVENTRY)wParam;
+    LV_ITEM         lvI;
+    LV_ITEM         lvO;
+    INT             row = 0x7FFFFFFF;
+    WCHAR           szPid[16];
+    LPAPXSERVENTRY  lpEntry = NULL;
+    int             i;
+
+    AplZeroMemory(&lvI, sizeof(LV_ITEM)); 
+    lvI.mask        = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
+    lvI.iItem       = 0x7FFFFFFF;
+    switch (lpEnt->stServiceStatus.dwCurrentState) {
+        case SERVICE_RUNNING:
+            lvI.iImage      = 0;
+            lvI.pszText     = STAT_STARTED;
+        break;
+        case SERVICE_STOPPED:
+            lvI.iImage      = 1;
+            lvI.pszText     = STAT_NONE;
+        break;
+        case SERVICE_PAUSED:
+            lvI.iImage      = 2;
+            lvI.pszText     = STAT_PAUSED;
+        break;
+        default:
+            lvI.iImage      = 3;
+            lvI.pszText     = STAT_NONE;
+        break;
+    }
+    /* Search the items if this is a refresh callback */
+    if (uMsg == (WM_USER + 2)) {
+        for (i = 0; i < ListView_GetItemCount(hWndList); i++) {
+            lvO.iItem = i;
+            lvO.mask = LVIF_PARAM;
+            ListView_GetItem(hWndList, &lvO);
+            lpEntry = (LPAPXSERVENTRY)lvO.lParam;
+            if (!lstrcmpW(lpEntry->szServiceName, lpEnt->szServiceName)) {
+                row = lvO.iItem;
+                /* release the old config */
+                apxFree(lpEntry->lpConfig);
+                break;
+            }
+            else
+                lpEntry = NULL;
+        }
+    }
+    if (row == 0x7FFFFFFF || !lpEntry)
+        lpEntry = (LPAPXSERVENTRY) apxPoolAlloc(hPool, sizeof(APXSERVENTRY));
+    AplCopyMemory(lpEntry, lpEnt, sizeof(APXSERVENTRY));
+    lvI.lParam = (LPARAM)lpEntry;
+    if (row == 0x7FFFFFFF)
+        row = ListView_InsertItem(hWndList, &lvI);
+    else {
+        lvI.iItem = row;
+        ListView_SetItem(hWndList, &lvI);
+    }
+    if (row == -1)
+        return TRUE; 
+
+    ListView_SetItemTextW(hWndList, row, 1, lpEnt->lpConfig->lpDisplayName); 
+    i = 2;
+    if (lvItems[2].iWidth > 0) {
+        if (lpEnt->szServiceDescription)
+            ListView_SetItemTextW(hWndList, row, i, lpEnt->szServiceDescription);
+        i++;
+    }
+    if (lvItems[3].iWidth > 0) {
+        if (lpEnt->dwStart == SERVICE_DEMAND_START) {
+            ListView_SetItemTextW(hWndList, row, i, START_MANUAL);
+        }
+        else if (lpEnt->dwStart == SERVICE_AUTO_START) {
+            ListView_SetItemTextW(hWndList, row, i, START_AUTO);
+        }
+        else if (lpEnt->dwStart == SERVICE_DISABLED) {
+            ListView_SetItemTextW(hWndList, row, i, START_DISABLED);
+        }
+        else if (lpEnt->dwStart == SERVICE_BOOT_START) {
+            ListView_SetItemTextW(hWndList, row, i, START_BOOT);
+        }        
+        else if (lpEnt->dwStart == SERVICE_SYSTEM_START) {
+            ListView_SetItemTextW(hWndList, row, i, START_SYSTEM);
+        }
+        i++;
+    }
+    if (lvItems[4].iWidth > 0) {
+        ListView_SetItemTextW(hWndList, row, i++, *lpEnt->szObjectName ? 
+                              lpEnt->szObjectName : STAT_SYSTEM);
+    }
+    if (lvItems[5].iWidth > 0) {
+        if (lpEnt->stStatusProcess.dwProcessId) {
+            wsprintfW(szPid, L"%d", lpEnt->stStatusProcess.dwProcessId);
+            ListView_SetItemTextW(hWndList, row, i, szPid);
+        }
+        i++;
+    }
+    _currentLitem++;
+    return TRUE;
+}
+
+static BOOL loadConfiguration()
+{
+    DWORD dwSize, i;
+    /* Load the GUI State first */    
+    if (IS_INVALID_HANDLE(hRegistry))
+        return FALSE;
+
+    dwSize = sizeof(APXGUISTATE);
+    if (apxRegistryGetBinaryA(hRegistry, APXREG_USER, DISPLAY_KEY, DISPLAY_STATE,
+                              (LPBYTE)(&(_gui_store->stState)), &dwSize)) {
+        _gui_store->stStartupInfo.wShowWindow = (WORD)_gui_store->stState.dwShow;
+        if (_gui_store->stStartupInfo.wShowWindow == SW_MAXIMIZE) {
+            _gui_store->stState.rcPosition.top    = CW_USEDEFAULT;
+            _gui_store->stState.rcPosition.left   = CW_USEDEFAULT;
+            _gui_store->stState.rcPosition.bottom = CW_USEDEFAULT;
+            _gui_store->stState.rcPosition.right  = CW_USEDEFAULT;
+        }
+        if (_gui_store->stState.nColumnWidth[0] > 50)
+            lvItems[0].iWidth = _gui_store->stState.nColumnWidth[0];
+        if (_gui_store->stState.nColumnWidth[1] > 50)
+            lvItems[1].iWidth = _gui_store->stState.nColumnWidth[1];
+
+        for (i = 2; i < NUMLVITEMS; i++) {
+            lvItems[i].iWidth = _gui_store->stState.nColumnWidth[i];
+        }
+        _sortColumn   = _gui_store->stState.nUser[0];
+        _sortOrder    = _gui_store->stState.nUser[1];
+        _currentTimer = _gui_store->stState.nUser[2];
+    }
+    _filterIname  = apxRegistryGetStringW(hRegistry, APXREG_USER,
+                                          SFILT_KEY, SFILT_INAME);
+    _filterXname  = apxRegistryGetStringW(hRegistry, APXREG_USER,
+                                          SFILT_KEY, SFILT_XNAME);
+    _filterIimage = apxRegistryGetStringW(hRegistry, APXREG_USER,
+                                          SFILT_KEY, SFILT_ISIMG);
+    _filterIimage = apxRegistryGetStringW(hRegistry, APXREG_USER,
+                                          SFILT_KEY, SFILT_XSIMG);
+    /* try to load system defalut filters */
+    if (!_filterIname)
+        _filterIname  = apxRegistryGetStringW(hRegistry, APXREG_SOFTWARE,
+                                              SFILT_KEY, SFILT_INAME);
+    if (!_filterXname)
+        _filterXname  = apxRegistryGetStringW(hRegistry, APXREG_SOFTWARE,
+                                              SFILT_KEY, SFILT_XNAME);
+    if (!_filterIimage)
+        _filterIimage = apxRegistryGetStringW(hRegistry, APXREG_SOFTWARE,
+                                              SFILT_KEY, SFILT_ISIMG);
+    if (!_filterXimage)
+        _filterXimage = apxRegistryGetStringW(hRegistry, APXREG_SOFTWARE,
+                                              SFILT_KEY, SFILT_XSIMG);
+
+    return TRUE;
+}
+
+#define REGSET_FILTER(str, key) \
+    APXMACRO_BEGIN              \
+    if (str && lstrlenW(str))   \
+        apxRegistrySetStrW(hRegistry, APXREG_USER, SFILT_KEY, key, str);    \
+    else                                                                    \
+        apxRegistryDeleteW(hRegistry, APXREG_USER, SFILT_KEY, key);         \
+    APXMACRO_END
+
+static BOOL saveConfiguration()
+{
+    DWORD i;
+    if (IS_INVALID_HANDLE(hRegistry))
+        return FALSE;
+    for (i = 0; i < NUMLVITEMS; i++) {
+        _gui_store->stState.nColumnWidth[i] = lvItems[i].iWidth;
+    }
+    _gui_store->stState.nUser[0] = _sortColumn;
+    _gui_store->stState.nUser[1] = _sortOrder;
+    _gui_store->stState.nUser[2] = _currentTimer;
+
+    apxRegistrySetBinaryA(hRegistry, APXREG_USER, DISPLAY_KEY, DISPLAY_STATE,
+                          (LPBYTE)(&(_gui_store->stState)), sizeof(APXGUISTATE));
+    REGSET_FILTER(_filterIname,  SFILT_INAME);
+    REGSET_FILTER(_filterXname,  SFILT_XNAME);
+    REGSET_FILTER(_filterIimage, SFILT_ISIMG);
+    REGSET_FILTER(_filterXimage, SFILT_XSIMG);
+
+    return TRUE;
+}
+
+/* Main program entry
+ * Since we are inependant from CRT
+ * the arguments are not used
+ */
+#ifdef _NO_CRTLIBRARY
+int xMain(void)
+#else
+int WINAPI WinMain(HINSTANCE hInstance,
+                   HINSTANCE hPrevInstance,
+                   LPSTR lpCmdLine,
+                   int nCmdShow)
+#endif
+{
+    MSG    msg;
+
+    apxHandleManagerInitialize();
+    hPool     = apxPoolCreate(NULL, 0);
+    hService  = apxCreateService(hPool, GENERIC_ALL, TRUE);
+
+    _gui_store = apxGuiInitialize(MainWndProc, APSVCMGR_CLASS);
+
+    if (!_gui_store) {
+        goto cleanup;
+    }
+    hRegistry = apxCreateRegistry(hPool, KEY_ALL_ACCESS, NULL,
+                                  apxLoadResource(IDS_APPLICATION, 0),
+                                  APXREG_USER);
+    loadConfiguration();
+    _gui_store->hMainWnd = CreateWindow(_gui_store->szWndClass,
+                                        apxLoadResource(IDS_APPLICATION, 0),
+                                        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
+                                        _gui_store->stState.rcPosition.left,
+                                        _gui_store->stState.rcPosition.top,
+                                        _gui_store->stState.rcPosition.right,
+                                        _gui_store->stState.rcPosition.bottom,
+                                        NULL, NULL,
+                                        _gui_store->hInstance,
+                                        NULL);
+    if (!_gui_store->hMainWnd) {
+        goto cleanup;
+    }
+
+    ShowWindow(_gui_store->hMainWnd, _gui_store->stStartupInfo.wShowWindow);
+    UpdateWindow(_gui_store->hMainWnd); 
+    SetMenuDefaultItem(GetMenu(_gui_store->hMainWnd), IDMS_PROPERTIES, FALSE);
+
+    while (GetMessage(&msg, NULL, 0, 0))  {
+        if(!TranslateAccelerator(_gui_store->hMainWnd,
+                                 _gui_store->hAccel, &msg)) {
+            TranslateMessage(&msg);
+            DispatchMessage(&msg);
+        }
+    }
+    saveConfiguration();
+
+cleanup:
+    apxFree(_filterIname);
+    apxFree(_filterXname);
+    apxFree(_filterIimage);
+    apxFree(_filterXimage);
+    apxFree(_exportFilename);
+    apxCloseHandle(hService);
+    apxHandleManagerDestroy();
+    ExitProcess(0);
+    return 0;
+}
diff --git a/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.h b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.h
new file mode 100644
index 0000000..5fd27b2
--- /dev/null
+++ b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.h
@@ -0,0 +1,117 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#undef  PRG_VERSION
+#define PRG_VERSION    "1.0.0.0" 
+
+#define NUMTOOLBUTTONS                  17
+#define IDC_TOOLBAR                     2000
+#define IDB_TOOLBAR                     2001
+#define IDB_SSTATUS                     2002
+#define IDC_LISTVIEW                    2003
+
+#define IDM_ARROWUP                     2004
+#define IDM_ARROWDOWN                   2005
+#define IDS_HSSTART                     2006
+#define IDS_HSSTOP                      2007
+#define IDS_HSPAUSE                     2008
+#define IDS_HSRESTART                   2009
+#define IDM_POPUPMENU                   2010
+
+#define IDAM_TRY                        2100
+#define IDAM_SAVE                       2101
+#define IDAM_SAVEAS                     2102
+#define IDAM_EXIT                       2103
+#define IDAM_NEW                        2104
+#define IDAM_DELETE                     2105
+
+#define IDMS_START                      2110
+#define IDMS_STOP                       2111
+#define IDMS_PAUSE                      2112
+#define IDMS_RESTART                    2113
+#define IDMS_REFRESH                    2114
+#define IDMS_PROPERTIES                 2115
+#define IDMS_HELP                       2116
+
+#define IDMV_UFAST                      2120
+#define IDMV_USLOW                      2121
+#define IDMV_UPAUSED                    2122
+#define IDMV_SELECTCOLUMNS              2123
+#define IDMV_FILTER                     2124
+
+#define IDMH_HELP                       2130
+#define IDMH_ABOUT                      2131
+
+/* Property pages */
+
+#define IDD_PROPPAGE_SGENERAL           2600
+#define IDC_PPSGNAME                    2601
+#define IDC_PPSGDISP                    2602
+#define IDC_PPSGDESC                    2603
+#define IDC_PPSGDEXE                    2604
+#define IDC_PPSGCMBST                   2605
+#define IDC_PPSGSTATUS                  2606
+#define IDC_PPSGSTART                   2607
+#define IDC_PPSGSTOP                    2608
+#define IDC_PPSGPAUSE                   2609
+#define IDC_PPSGRESTART                 2610
+
+#define IDD_PROPPAGE_LOGON              2620
+#define IDC_PPSLLS                      2621
+#define IDC_PPSLID                      2622
+#define IDC_PPSLUA                      2623
+#define IDC_PPSLUSER                    2624
+#define IDC_PPSLBROWSE                  2625
+#define IDC_PPSLPASS                    2626
+#define IDC_PPSLCPASS                   2627
+#define IDL_PPSLPASS                    2628
+#define IDL_PPSLCPASS                   2629
+
+
+#define IDD_FILTER                      2640
+#define IDC_FINAME                      2641
+#define IDC_FXNAME                      2642
+#define IDC_FISIMG                      2643
+#define IDC_FXSIMG                      2644
+
+#define IDD_SELCOL                      2650
+#define IDC_CCOL1                       2651
+#define IDC_CCOL2                       2652
+#define IDC_CCOL3                       2653
+#define IDC_CCOL4                       2654
+#define IDC_CCOL5                       2655
+
+
+#if 0
+#define IDAMS_NEW                       3000
+#define IDAMS_DELETE                    3001
+#define IDAMS_SAVE                      3002
+#define IDMVS_REFRESH                   3003
+#define IDMSS_PROPERTIES                3004
+#define IDMSS_START                     3005
+#define IDMSS_STOP                      3006
+#define IDMSS_PAUSE                     3007
+#define IDMSS_RESTART                   3008
+#define IDMHS_HELP                      3009    
+#define IDMVS_FILTER                    3010
+#endif
+
+#define IDS_DELSERVICEC                 3100
+#define IDS_DELSERVICET                 3101
+#define IDS_VALIDPASS                   3102
+#define IDS_PPGENERAL                   3103
+#define IDS_PPLOGON                     3104
+#define IDS_NOTIMPLEMENTED              3105
+
diff --git a/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.manifest b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.manifest
new file mode 100644
index 0000000..c6d5851
--- /dev/null
+++ b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.manifest
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
+<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="Apache.Procrun.Apsvcmgr" type="win32" /> 
+<description>Your application description here.</description> 
+<dependency> 
+<dependentAssembly> 
+<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> 
+</dependentAssembly> 
+</dependency> 
+</assembly> 
diff --git a/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.rc b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.rc
new file mode 100644
index 0000000..cfcec05
--- /dev/null
+++ b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.rc
@@ -0,0 +1,310 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "apsvcmgr.h"
+
+#define RSTR_ASM        "Apache Service Manager"
+#define RSTR_SCMATS     "Service Manager is attempting to "
+
+IDI_MAINICON         ICON                   "../../resources/apsvcmgr.ico" 
+IDB_TOOLBAR          BITMAP  DISCARDABLE    "../../resources/toolbar.bmp"
+IDB_SSTATUS          BITMAP  DISCARDABLE    "../../resources/sstatus.bmp"
+IDB_SUSERS           BITMAP  DISCARDABLE    "../../resources/susers.bmp"
+IDR_LICENSE          RTF                    "../../resources/license.rtf"
+BMP_JAKARTA          BITMAP                 "../../resources/jakarta.bmp"
+ 
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "apsvcmgr.manifest"
+
+IDC_APPLICATION MENU 
+BEGIN
+    POPUP "&Action"
+    BEGIN
+        MENUITEM "&Minimize to try",            IDAM_TRY
+        MENUITEM SEPARATOR
+        MENUITEM "&New",                        IDAM_NEW
+        MENUITEM "&Delete",                     IDAM_DELETE, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "&Save                       CRTL+S", IDAM_SAVE
+        MENUITEM "Save &As...              CTRL+A", IDAM_SAVEAS
+        MENUITEM SEPARATOR
+        MENUITEM "E&xit",                       IDAM_EXIT
+    END
+    POPUP "&Service"
+    BEGIN
+        MENUITEM "P&ropeties ...",               IDMS_PROPERTIES, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "&Start",                       IDMS_START, GRAYED
+        MENUITEM "S&top",                        IDMS_STOP, GRAYED
+        MENUITEM "&Pause",                       IDMS_PAUSE, GRAYED
+        MENUITEM "Res&tart",                     IDMS_RESTART, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "Re&fresh",                     IDMS_REFRESH
+        MENUITEM SEPARATOR
+        MENUITEM "&Help",                        IDMS_HELP
+    END
+    POPUP "&View"
+    BEGIN
+        MENUITEM "Re&fresh Now      F5",         IDMS_REFRESH
+        POPUP "Update speed"
+        BEGIN
+            MENUITEM "10 Seconds",              IDMV_UFAST
+            MENUITEM "1    Minute",             IDMV_USLOW
+            MENUITEM "Paused",                  IDMV_UPAUSED
+        END
+        MENUITEM SEPARATOR
+        MENUITEM "Select Columns ...",          IDMV_SELECTCOLUMNS
+        MENUITEM "Filter Services ...",         IDMV_FILTER
+    END
+    POPUP "&Help"
+    BEGIN
+        MENUITEM "&Help ...",                   IDMH_HELP
+        MENUITEM "&About",                      IDMH_ABOUT
+    END
+END
+
+IDM_POPUPMENU MENU DISCARDABLE 
+BEGIN
+    POPUP "Popup Menu"
+    BEGIN
+        MENUITEM "Propeties ...",              IDMS_PROPERTIES, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "Start",                      IDMS_START, GRAYED
+        MENUITEM "Stop",                       IDMS_STOP, GRAYED
+        MENUITEM "Pause",                      IDMS_PAUSE, GRAYED
+        MENUITEM "Restart",                    IDMS_RESTART, GRAYED
+        MENUITEM SEPARATOR
+        MENUITEM "Refresh",                    IDMS_REFRESH
+        MENUITEM SEPARATOR
+        MENUITEM "Help",                       IDMS_HELP, HELP
+    END
+END
+
+IDD_ABOUTBOX DIALOGEX 0, 0, 337, 187
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "Apache Service Manager"
+FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+    DEFPUSHBUTTON   "&OK",IDOK,285,150,50,14
+    CONTROL         "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE | 
+                    ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
+    CONTROL         "BMP_JAKARTA",IDC_STATIC,"Static",SS_BITMAP,0,0,337,30
+    LTEXT           " ",IDC_ABOUTAPP,2,150,270,12
+    LTEXT           "Copyright � 2000-2003 The Apache Software Foundation.",IDC_STATIC,2,160,270,12
+    LTEXT           "http://www.jakarta.org",IDC_STATIC,2,170,270,12 
+    PUSHBUTTON      "&System Info",IAB_SYSINF,285,170,50,14
+END
+
+IDD_PROGRESS DIALOGEX 0, 0, 322, 92
+STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | 
+    WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_TOPMOST
+CAPTION "Apache Service Manager"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    DEFPUSHBUTTON   "Cl&ose",IDOK,261,73,50,14
+    PUSHBUTTON      "&Cancel",IDCANCEL,202,73,50,14
+    LTEXT           " ",
+                    IDDP_HEAD,40,4,250,8
+    LTEXT           " ",IDDP_TEXT,40,15,250,44
+    CONTROL         "",IDDP_PROGRESS,"msctls_progress32",WS_BORDER,10,50,302,
+                    14
+    ICON            IDI_MAINICON,IDC_STATIC,10,4,20,20,0,WS_EX_TRANSPARENT
+END
+
+IDD_PROPPAGE_SGENERAL DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "Service Name: ",IDC_STATIC,10,8,52,8
+    LTEXT           "  ",IDC_PPSGNAME,70,8,240,8
+    LTEXT           "Display &name: ",IDC_STATIC,10,23,50,8
+    EDITTEXT        IDC_PPSGDISP,70,22,180,14,ES_AUTOHSCROLL
+    LTEXT           "&Description: ",IDC_STATIC,10,41,43,8
+    EDITTEXT        IDC_PPSGDESC,70,40,180,14,ES_AUTOHSCROLL
+    LTEXT           "Pat&h to executable:",IDC_STATIC,10,63,66,8
+    EDITTEXT        IDC_PPSGDEXE,10,75,240,14,ES_AUTOHSCROLL | WS_DISABLED
+    LTEXT           "Startup typ&e:",IDC_STATIC,10,94,46,8
+    COMBOBOX        IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL | 
+                    WS_TABSTOP
+    CONTROL         "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1                    
+    LTEXT           "Service Status:",IDC_STATIC,10,138,52,8
+    LTEXT           "  ",IDC_PPSGSTATUS,70,138,240,8
+    PUSHBUTTON      "&Start",IDC_PPSGSTART,10,160,55,14,WS_DISABLED
+    PUSHBUTTON      "S&top",IDC_PPSGSTOP,71,160,55,14,WS_DISABLED
+    PUSHBUTTON      "&Pause",IDC_PPSGPAUSE,132,160,55,14,WS_DISABLED
+    PUSHBUTTON      "&Restart",IDC_PPSGRESTART,193,160,55,14,WS_DISABLED
+END
+
+IDD_PROPPAGE_LOGON DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "Log on as:",IDC_STATIC,10,8,51,8
+    CONTROL         "&Local System account",IDC_PPSLLS,"Button",
+                    BS_AUTORADIOBUTTON,10,23,85,10
+    CONTROL         "Allo&w service to interact with desktop",IDC_PPSLID,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,37,135,10
+    CONTROL         "&This account:",IDC_PPSLUA,"Button",BS_AUTORADIOBUTTON,
+                    10,59,61,10
+    EDITTEXT        IDC_PPSLUSER,86,58,114,14,ES_AUTOHSCROLL
+    PUSHBUTTON      "&Browse...",IDC_PPSLBROWSE,205,58,50,14
+    LTEXT           "&Password:",IDL_PPSLPASS,21,76,36,8
+    EDITTEXT        IDC_PPSLPASS,86,75,114,14,ES_PASSWORD | ES_AUTOHSCROLL
+    LTEXT           "&Confirm Password:",IDL_PPSLCPASS,20,93,63,8
+    EDITTEXT        IDC_PPSLCPASS,86,92,114,14,ES_PASSWORD | ES_AUTOHSCROLL
+END
+
+IDD_FILTER DIALOGEX 0, 0, 296, 199
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_CONTEXTHELP
+CAPTION "Service display filters"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    LTEXT           "Enter multiple filter match strings separated by the ';' character. '*' is a wildcard.",
+                    IDC_STATIC,10,7,278,8
+    DEFPUSHBUTTON   "&OK",IDOK,232,175,50,14
+    PUSHBUTTON      "&Cancel",IDCANCEL,176,175,50,14
+    GROUPBOX        " Service name filters ",IDC_STATIC,10,28,275,62
+    LTEXT           "Include:",IDC_STATIC,18,48,27,8
+    EDITTEXT        IDC_FINAME,63,46,211,14,ES_AUTOHSCROLL
+    LTEXT           "Exclude:",IDC_STATIC,18,66,28,8
+    EDITTEXT        IDC_FXNAME,63,64,211,14,ES_AUTOHSCROLL
+    GROUPBOX        "Service image path filters",IDC_STATIC,10,102,275,62
+    LTEXT           "Include:",IDC_STATIC,17,120,27,8
+    EDITTEXT        IDC_FISIMG,63,118,211,14,ES_AUTOHSCROLL
+    LTEXT           "Exclude:",IDC_STATIC,17,138,28,8
+    EDITTEXT        IDC_FXSIMG,63,136,211,14,ES_AUTOHSCROLL
+END
+
+IDD_SELCOL DIALOGEX 0, 0, 220, 130
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | 
+    WS_SYSMENU
+CAPTION "Select Columns"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    DEFPUSHBUTTON   "OK",IDOK,156,105,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,96,105,50,14
+    LTEXT           "Select the columns that will apear on the Service view of the Service Manager",
+                    IDC_STATIC,16,2,194,16
+    CONTROL         "Name",IDC_CCOL1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
+                    16,26,83,10
+    CONTROL         "Description",IDC_CCOL2,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,16,39,83,10
+    CONTROL         "Startup Type",IDC_CCOL3,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,16,52,83,10
+    CONTROL         "Log On As",IDC_CCOL4,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,16,65,83,10
+    CONTROL         "Process Id",IDC_CCOL5,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,16,78,83,10
+END
+
+IDD_SELUSER DIALOGEX 0, 0, 410, 201
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
+    WS_THICKFRAME
+EXSTYLE WS_EX_CONTEXTHELP
+CAPTION "Select User"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    LTEXT           "Name:",IDSU_SELNAME,10,183,22,8
+    EDITTEXT        IDSU_SELECTED,48,200,213,14,ES_AUTOHSCROLL
+    DEFPUSHBUTTON   "OK",IDOK,292,180,50,14,WS_DISABLED
+    PUSHBUTTON      "Cancel",IDCANCEL,348,180,50,14
+    LTEXT           "Look In:",IDC_STATIC,10,9,27,8
+    CONTROL         "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | 
+                    LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER | 
+                    WS_TABSTOP,0,26,410,149,WS_EX_CLIENTEDGE
+    CONTROL         "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST | 
+                    WS_VSCROLL | WS_TABSTOP,47,6,260,80
+END
+
+IDC_APPLICATION ACCELERATORS 
+BEGIN
+    "/",            IDMH_ABOUT,              ASCII,  ALT, NOINVERT
+    "?",            IDMH_ABOUT,              ASCII,  ALT, NOINVERT
+    VK_F1,          IDMH_HELP,               VIRTKEY, NOINVERT
+    "S",            IDAM_SAVE,               VIRTKEY, CONTROL, NOINVERT
+    "A",            IDAM_SAVEAS,             VIRTKEY, CONTROL, NOINVERT    
+    "F",            IDMV_FILTER,             VIRTKEY, CONTROL, NOINVERT    
+    VK_F5,          IDMS_REFRESH,            VIRTKEY, NOINVERT
+END
+
+
+STRINGTABLE 
+BEGIN
+    IDS_APPLICATION     RSTR_ASM
+    IDS_APPVERSION      "Version 1.0.0"
+    IDS_APPFULLNAME     RSTR_ASM " Version " PRG_VERSION
+    IDS_APPCOPYRIGHT    "Copyright � 2000-2003 The Apache Software Foundation"
+    IDS_APPDESCRIPTION  "Apache NT Service Management Tool"
+    IDS_HSSTART         RSTR_SCMATS "start the following service ..."
+    IDS_HSSTOP          RSTR_SCMATS "stop the following service ..."
+    IDS_HSRESTART       RSTR_SCMATS "to restart the following service ..."
+    IDS_HSPAUSE         RSTR_SCMATS "to pause the following service ..."
+    
+    IDAM_NEW            "New Service"
+    IDAM_DELETE         "Delete Service"
+    IDAM_SAVE           "Export List"
+    IDMS_REFRESH        "Refresh"
+    IDMV_FILTER         "Filter Services"
+    IDMS_PROPERTIES     "Properties"
+    IDMS_START          "Start Service"
+    IDMS_STOP           "Stop Service"
+    IDMS_PAUSE          "Pause Service"
+    IDMS_RESTART        "Restart Service"
+    IDMH_HELP           "Help"    
+    
+    IDS_DELSERVICEC     "Confirm Delete Service"
+    IDS_DELSERVICET     "You cannot undo the effects of this dialog box!\r\n\r\nYou are about to delete '%s' service.\r\nDeleting services may cause your system unusable.\r\n\r\nDo you want to proceed?"
+    IDS_VALIDPASS       "Please enter a valid password"    
+    IDS_PPGENERAL       "General"
+    IDS_PPLOGON         "Log On"
+    IDS_NOTIMPLEMENTED  "Sorry, but this feature is not implemented yet"
+END
+ 
+
+1 VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "040904b0"
+    BEGIN
+      VALUE "Comments", "NT Service Management Tool\0"
+      VALUE "CompanyName", "Apache Software Foundation\0"
+      VALUE "FileDescription", RSTR_ASM "\0"
+      VALUE "FileVersion", PRG_VERSION
+      VALUE "InternalName", RSTR_ASM "\0"
+      VALUE "LegalCopyright", "Copyright � 2000-2003 The Apache Software Foundation.\0"
+      VALUE "OriginalFilename", "apsvcmgr.exe\0"
+      VALUE "ProductName", RSTR_ASM "\0"
+      VALUE "ProductVersion", PRG_VERSION
+    END
+  END
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x409, 1200
+  END
+END 
diff --git a/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.vcproj b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.vcproj
new file mode 100644
index 0000000..6e2f937
--- /dev/null
+++ b/src/native/nt/procrun/apps/apsvcmgr/apsvcmgr.vcproj
@@ -0,0 +1,252 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="apsvcmgr"
+	ProjectGUID="{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="..\..\obj\Debug"
+			IntermediateDirectory="..\..\obj\Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/apsvcmgrd.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/apsvcmgr.pdb"
+				SubSystem="2"
+				EntryPointSymbol=""
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="..\..\obj\Release"
+			IntermediateDirectory="..\..\obj\Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				RuntimeLibrary="0"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/apsvcmgr.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="FALSE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				EntryPointSymbol=""
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug Unicode|Win32"
+			OutputDirectory="..\..\obj\$(ConfigurationName)"
+			IntermediateDirectory="..\..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_UNICODE;_WINDOWS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/apsvcmgrud.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/apsvcmgr.pdb"
+				SubSystem="2"
+				EntryPointSymbol=""
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release Unicode|Win32"
+			OutputDirectory="..\..\obj\$(ConfigurationName)"
+			IntermediateDirectory="..\..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_UNICODE;_WINDOWS"
+				RuntimeLibrary="0"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/apsvcmgru.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="FALSE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				EntryPointSymbol=""
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\apsvcmgr.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\apsvcmgr.h">
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+			<File
+				RelativePath=".\apsvcmgr.rc">
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/apps/jar2exe/jar2exe.c b/src/native/nt/procrun/apps/jar2exe/jar2exe.c
new file mode 100644
index 0000000..2e651a0
--- /dev/null
+++ b/src/native/nt/procrun/apps/jar2exe/jar2exe.c
@@ -0,0 +1,542 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* ====================================================================
+ * jar2exe -- convert .jar file to WIN executable.
+ * Contributed by Mladen Turk <mturk at apache.org>
+ * 05 Aug 2003
+ * ==================================================================== 
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI  1
+#include "apxwin.h"
+#include <imagehlp.h>
+#include "jar2exe.h"
+#pragma comment( lib, "imagehlp.lib" )
+
+
+#ifdef _DEBUG
+#define LOG_MARK        _verbose, __FILE__, __LINE__
+#else
+#define LOG_MARK        _verbose, NULL, 0
+#endif
+
+#define EXE_SUFFIX      ".EXE"
+#define EXE_SUFFIX_SZ   (sizeof(".EXE") - 1)
+#define JAR_LINT        "jar2exe Copyright (c) 2000-2003 The Apache Software Foundation."
+
+#define EMBED_SIZE      2048
+#define EMBED_MAX       2044
+
+typedef struct {
+    char    s_signature[16];
+    char    s_class[EMBED_SIZE];
+    UINT32  s_flags[4];
+    char    e_signature[16];
+} st_config;
+
+static char         _progname[MAX_PATH+1];
+static char         _progpath[MAX_PATH+1];
+static HANDLE       _hstub   = NULL;
+static BOOL         _verbose = FALSE;
+static BOOL         _makegui = FALSE;
+static const char   *_lint   = JAR_LINT;
+static st_config    *_config = NULL;
+
+/* zip file header magic */
+static BYTE zip_fh_magic[4] = { '\120', '\113', '\001', '\002'};
+/* end of central directory signature */
+static BYTE zip_ec_magic[4] = { '\120', '\113', '\005', '\006'}; 
+/* lower case configuration block signature 
+ * to enable binary searching
+ */
+static BYTE c_signature[] = {
+    's', 't', 'a', 'r', 't', 'u', 's', 'e', 'r', 's', 'b', 'l', 'o', 'c', 'k', '\0' 
+};
+
+/* space in exe stub for user configuration */
+static BYTE conf_in_exe[EMBED_SIZE + 48] = {
+    'S', 'T', 'A', 'R', 'T', 'U', 'S', 'E', 'R', 'S', 'B', 'L', 'O', 'C', 'K', '\0',
+
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+
+    '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+    'E', 'N', 'D', 'O', 'F', 'U', 'S', 'E', 'R', 'S', 'B', 'L', 'O', 'C', 'K', '\0',
+};
+
+static LPCSTR _usage = JAR_LINT "\n"                                     \
+    "Usage:\n"                                                           \
+    "  jar2exe [options] <output.exe> <class> <embed.jar> [params ...]\n" \
+    "  options:\n"                                          \
+    "  -d\t\tdisplay error messages\n"                      \
+    "  -g\t\tmake non-console application\n"                \
+    "  -m<nn>\t\tInitial memory pool (nn MB)\n"             \
+    "  -x<nn>\t\tMaximum memory size (nn MB)\n"             \
+    "  -s<nn>\t\tThread stack size (nn Bytes)\n"            \
+    "  output.exe\toutput executable\n"                     \
+    "  class\t\tmain class name\n"                          \
+    "  embed.jar\tjar file to embed in stub\n"              \
+    "  params\t\tJava VM parameters\n";
+
+/* Fix the ZIP central directory 
+ * Find the central dir position and
+ * add the stub length offset to each enty.
+ */
+static int fixjar(size_t slen)
+{
+    HANDLE hmap;
+    BYTE *map, *cd, *hd, *mp;
+    size_t len, off, cdir, cpos = 0;
+    int i, nent, rc = 0;
+
+    len = SetFilePointer(_hstub, 0, NULL, FILE_END);
+    if ((hmap = CreateFileMapping(_hstub, NULL, 
+                                  PAGE_READWRITE, 0, 0, NULL)) == NULL) {
+        apxDisplayError(LOG_MARK, "%s unable to map the stub file\n",
+                        _progname);
+        return -1;
+    }
+    if ((map = MapViewOfFile(hmap, FILE_MAP_ALL_ACCESS, 0, 0, 0)) == NULL) {
+        apxDisplayError(LOG_MARK, "%s unable to map the view of file\n",
+                        _progname);
+        CloseHandle(hmap);
+    }
+    off = len - ZIPOFF_CDIR_CLEN;
+    cd  = map + off;
+    mp  = CHECK_4_MAGIC(cd, zip_ec_magic) ? cd : NULL; 
+    while ((len - off) < (64 * 1024)) { 
+        i = 0;
+        if (!mp) {
+            off -= ZIPOFF_CDIR_CLEN;
+            cd = map + off;
+
+            if (!CHECK_4_MAGIC(cd, zip_ec_magic)) {
+                for (; i < ZIPOFF_CDIR_CLEN; i++) {
+                    if (CHECK_4_MAGIC((cd + i), zip_ec_magic)) {
+                        mp = cd + i;
+                        break;
+                    }
+                }
+            }
+            else
+                mp = cd;
+        }         
+
+        if (mp) { 
+            cpos = READ_32_BITS(mp, ZIPOFF_CDIR_OFFSET);
+            nent = READ_16_BITS(mp, ZIPOFF_CDIR_TOTENTRIES);
+            cdir = off + i;
+            break;
+        }
+
+    }
+    if (cpos) {
+        hd = map + cpos + slen;
+        for (i = 0; i < nent; i++) {
+            size_t xl, cl, fl, sp;
+            if (!CHECK_4_MAGIC(hd, zip_fh_magic)) {
+                rc = -1;     
+                apxDisplayError(LOG_MARK, "Wrong header at %d\n", hd - map);
+                goto cleanup;
+            }
+            sp = READ_32_BITS(hd, ZIPOFF_FH_LFHOFFSET);
+            fl = READ_16_BITS(hd, ZIPOFF_FH_FNLEN);
+            xl = READ_16_BITS(hd, ZIPOFF_FH_XFLEN);
+            cl = READ_16_BITS(hd, ZIPOFF_FH_FCLEN);
+            if (i == 0 && sp != 0) {
+                apxDisplayError(LOG_MARK, "The first entry is not zero\n");
+                rc = -1;     
+                goto cleanup;
+            }
+            WRITE_32_BITS(hd, ZIPOFF_FH_LFHOFFSET, sp + slen);            
+            hd += (fl + xl + cl + ZIPLEN_FH);
+        }
+        /* repos to the end of central dir */
+        mp = map + cdir;
+        WRITE_32_BITS(mp, ZIPOFF_CDIR_OFFSET, cpos + slen);            
+    }
+cleanup:
+    UnmapViewOfFile(map);
+    CloseHandle(hmap);
+    return rc;
+
+}
+
+/* Merge the stub with jar file
+ * Fix the userblock bounded code.
+ */
+static int merge(LPCSTR jar, size_t slen)
+{
+    HANDLE hjar, hmap;
+    char buff[4096];
+    BYTE bmatch[16];
+
+    DWORD rd, wr;
+    BYTE *map, *ss;
+    int i;
+    if ((hmap = CreateFileMapping(_hstub, NULL, 
+                                  PAGE_READWRITE, 0, 0, NULL)) == NULL) {
+        apxDisplayError(LOG_MARK, "%s unable to map the stub file\n",
+                        _progname);
+        return -1;
+    }
+    if ((hjar = CreateFile(jar, GENERIC_READ, 0, NULL,
+                           OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
+        apxDisplayError(LOG_MARK, "%s unable to open jar file : %s\n",
+                        _progname, jar);
+        return -1;
+    }
+    
+    if ((map = MapViewOfFile(hmap, FILE_MAP_ALL_ACCESS, 0, 0, 0)) == NULL) {
+        apxDisplayError(LOG_MARK, "%s unable to map the view of file\n",
+                        _progname);
+        CloseHandle(hmap);
+        return -1;
+    }
+    /* convert to upper case */
+    for (i = 0; i < 15; i++)
+        bmatch[i] = c_signature[i] - 32;
+    bmatch[15] = 0;
+    if ((ss = ApcMemSearch(map, bmatch, 16, slen)) != NULL) {
+        st_config cfg;
+        AplCopyMemory(&cfg, ss, sizeof(st_config));
+        AplCopyMemory(ss, _config, sizeof(st_config));
+    }
+    UnmapViewOfFile(map);
+    CloseHandle(hmap);
+    SetFilePointer(_hstub, 0, NULL, FILE_END);
+    while (ReadFile(hjar, buff, 4096, &rd, NULL)) {
+        if (rd)
+            WriteFile(_hstub, buff, rd, &wr, NULL);
+        else
+            break;
+        if (rd != wr) {
+            apxDisplayError(LOG_MARK, "%s mismatch read/write\n(Readed : %d Written %d)\n",
+                            _progname, rd, wr);
+            CloseHandle(hjar);
+            return -1;
+        }
+    }
+    CloseHandle(hjar);
+    return 0;
+}
+
+static int
+jar2exe(int argc, char *argv[])
+{
+    int i = 1, l;
+    BY_HANDLE_FILE_INFORMATION stub_inf;
+    char *p;
+    LOADED_IMAGE li;
+
+    while (argc > 1 && *argv[1] == '-') {
+        p = argv[1];
+        /* Check if verbose mode is on */
+        while (*p) {
+            if (*p == 'm') {
+                _config->s_flags[0] = atoi(p + 1);
+                break;
+            }
+            else if (*p == 'x') {
+                _config->s_flags[1] = atoi(p + 1);
+                break;
+            }
+            else if (*p == 's') {
+                _config->s_flags[2] = atoi(p + 1);
+                break;
+            }
+            else if (*p == 'd')
+                _verbose = TRUE;
+            else if (*p == 'g')
+                _makegui = TRUE;
+            ++p;
+        }
+        --argc;
+        ++argv;
+    }
+    if (argc < 4) {
+        SetLastError(ERROR_SUCCESS);
+        apxDisplayError(TRUE, NULL, 0, _usage);
+        return -1;
+    }
+    AplZeroMemory(_config->s_class, EMBED_SIZE);
+    lstrcpyA(_config->s_class, argv[2]);
+    l = lstrlenA(_config->s_class);
+    for (i = 0; i < l; i++) {
+        if (_config->s_class[i] == '.')
+            _config->s_class[i] = '/';
+    }
+    p = (char *)(&(_config->s_class[l+1]));
+    *p++ = '\0';
+    if (argc > 4) {
+        --p;
+        for (i = 4; i < argc; i++) {
+            l += lstrlenA(argv[i]);
+            if (l > EMBED_MAX) {
+                apxDisplayError(LOG_MARK, "%s args are too long (max %d are allowed)\n",
+                                _progname, EMBED_MAX);
+                return -1;
+            }
+            lstrcpyA(p, argv[i]);
+            p += lstrlenA(argv[i]);
+            *p++ = '\0';
+        }
+    }
+    *p++ = '\0';
+    DeleteFile(argv[1]);
+    CopyFile(_progpath, argv[1], TRUE);
+    if ((_hstub = CreateFile(argv[1], GENERIC_READ | GENERIC_WRITE, 0, NULL,
+                             OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
+        apxDisplayError(LOG_MARK, "%s unable to open stub %s\n",
+                        _progname, argv[1]);
+        DeleteFile(argv[1]);
+        return -1;
+    }
+    /* Get original stub size */
+    GetFileInformationByHandle(_hstub, &stub_inf);
+    
+    if (merge(argv[3], stub_inf.nFileSizeLow))
+        goto cleanup;
+    if (fixjar(stub_inf.nFileSizeLow))
+        goto cleanup;
+    CloseHandle(_hstub);
+    if (_makegui) {
+        /* Change a portable executable (PE) image Subsytem to GUI.
+         * It will also calculate a new Checksum.
+         */
+        if (MapAndLoad(argv[1], NULL, &li, FALSE, FALSE)) {
+            if (li.FileHeader)
+                li.FileHeader->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
+            UnMapAndLoad(&li);
+        }
+        else
+            apxDisplayError(LOG_MARK, "%s MapAndLoad %s\n",
+                            _progname, argv[1]);
+    }
+    return 0;
+cleanup:
+    CloseHandle(_hstub);
+    DeleteFile(argv[1]);
+    return -1;
+}
+
+/* Run the embedded jar file
+ *
+ */
+int run(int argc, char *argv[])
+{
+    HANDLE hPool, hJava;
+    DWORD  rv = 0;
+    apxHandleManagerInitialize();
+    hPool = apxPoolCreate(NULL, 0);
+    /* Use default JVM */
+    hJava = apxCreateJava(hPool, NULL);
+    if (!IS_INVALID_HANDLE(hJava)) {
+        LPSTR lpCmd;
+        if (!apxJavaInitialize(hJava, _progpath,
+                              _config->s_class + 
+                              strlen(_config->s_class) + 1,
+                              _config->s_flags[0],
+                              _config->s_flags[1],
+                              _config->s_flags[2])) {            
+            rv = 1;
+            goto cleanup;
+        }
+        lpCmd = apxArrayToMultiSzA(hPool, argc - 1, &argv[1]);
+        if (!apxJavaLoadMainClass(hJava, _config->s_class, NULL, lpCmd)) {
+            rv = 2;
+            goto cleanup;
+        }
+        if (!apxJavaStart(hJava)) {
+            rv = 3;
+        }
+        else
+            apxJavaWait(hJava, INFINITE, FALSE);
+cleanup:
+        apxCloseHandle(hJava);
+    }
+    else {
+        rv = 4;
+    }
+
+    apxHandleManagerDestroy();
+    ExitProcess(rv);
+    return 0;
+}
+
+int main(int argc, char *argv[])
+{
+    char *p;
+    char path[MAX_PATH+1];
+    GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
+    lstrcpyA(_progpath, path);
+    
+    _config = (st_config *)conf_in_exe;
+    if (lstrcmpiA(_config->s_signature, c_signature)) {
+        apxDisplayError(LOG_MARK, "%s\nWrong user block signature\n", _lint);
+        ExitProcess(1);
+    }
+    /* remove the path and extension from module name */
+    if ((p = AplRindexA(path, '\\')))
+        *p++ = '\0';
+    else
+        p = &path[0];
+    lstrcpyA(_progname, p);
+    if (lstrlenA(_progname) > EXE_SUFFIX_SZ && ((p = AplRindexA(_progname, '.')) != NULL)) {
+        if (!lstrcmpiA(p, EXE_SUFFIX))
+            *p = '\0';
+    }
+    
+    if (lstrcmpiA(_progname, "jar2exe") == 0)
+        return jar2exe(argc, argv);
+    else if (lstrcmpiA(_progname, "jar2exew") == 0) {
+        /* default is to make gui app */
+        _makegui = TRUE;
+        return jar2exe(argc, argv);
+    }
+    else /* run the embedded jar */
+        return run(argc, argv);
+    
+    /* NOT REACHED */
+    return 0;
+}
diff --git a/src/native/nt/procrun/apps/jar2exe/jar2exe.h b/src/native/nt/procrun/apps/jar2exe/jar2exe.h
new file mode 100644
index 0000000..5bef749
--- /dev/null
+++ b/src/native/nt/procrun/apps/jar2exe/jar2exe.h
@@ -0,0 +1,86 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* ====================================================================
+ * jar2exe -- convert .jar file to WIN executable.
+ * Contributed by Mladen Turk <mturk at apache.org>
+ * 05 Aug 2003
+ * ==================================================================== 
+ */
+
+#ifndef _JAR2EXE_H
+#define _JAR2EXE_H
+
+#undef  PRG_VERSION
+#define PRG_VERSION    "1.0.0.0" 
+
+#define ZIPOFF_CDIR_CLEN            20
+#define ZIPOFF_CDIR_DISKNO          4
+#define ZIPOFF_CDIR_FINALDISKNO     6
+#define ZIPOFF_CDIR_ENTRIES         8
+#define ZIPOFF_CDIR_TOTENTRIES      10
+#define ZIPOFF_CDIR_SIZE            12
+#define ZIPOFF_CDIR_OFFSET          16
+
+#define ZIPOFF_FH_VERSION           4
+#define ZIPOFF_FH_NEEDVERSION       6
+#define ZIPOFF_FH_GPBF              8
+#define ZIPOFF_FH_CM                10
+#define ZIPOFF_FH_MTIME             12
+#define ZIPOFF_FH_MDATE             14
+#define ZIPOFF_FH_CRC32             16
+#define ZIPOFF_FH_CSIZE             20
+#define ZIPOFF_FH_USIZE             24
+#define ZIPOFF_FH_FNLEN             28
+#define ZIPOFF_FH_XFLEN             30
+#define ZIPOFF_FH_FCLEN             32
+#define ZIPOFF_FH_DISKNO            34
+#define ZIPOFF_FH_IFATTR            36
+#define ZIPOFF_FH_EFATTR            38
+#define ZIPOFF_FH_LFHOFFSET         42
+#define ZIPLEN_FH                   46
+
+#define READ_32_BITS(base, offset)                \
+        ((((unsigned char)(base)[offset + 0])) |       \
+         (((unsigned char)(base)[offset + 1]) << 8)  | \
+         (((unsigned char)(base)[offset + 2]) << 16) | \
+         (((unsigned char)(base)[offset + 3]) << 24))
+        
+#define READ_16_BITS(base, offset)                \
+        ((((unsigned char)(base)[offset])) |         \
+         (((unsigned char)(base)[offset + 1]) << 8)) \
+
+#define WRITE_32_BITS(base, offset, value) { \
+    (base)[offset + 0] = (unsigned char)(value & 0xff);               \
+    (base)[offset + 1] = (unsigned char)((value & 0xff00) >> 8);      \
+    (base)[offset + 2] = (unsigned char)((value & 0xff0000) >> 16);   \
+    (base)[offset + 3] = (unsigned char)((value & 0xff000000) >> 24); \
+}
+
+#define WRITE_16_BITS(base, offset, value) { \
+    (base)[offset + 0] = (unsigned char)(value & 0xff);               \
+    (base)[offset + 1] = (unsigned char)((value & 0xff00) >> 8);      \
+}
+
+/* shuld be faster then memcmp */
+#define CHECK_4_MAGIC(base, magic) \
+    ( ((base)[0] == (magic)[0]) && \
+      ((base)[1] == (magic)[1]) && \
+      ((base)[2] == (magic)[2]) && \
+      ((base)[3] == (magic)[3]) )
+
+
+#endif /* _JAR2EXE_H */
+
diff --git a/src/native/nt/procrun/apps/jar2exe/jar2exe.rc b/src/native/nt/procrun/apps/jar2exe/jar2exe.rc
new file mode 100644
index 0000000..4f40410
--- /dev/null
+++ b/src/native/nt/procrun/apps/jar2exe/jar2exe.rc
@@ -0,0 +1,55 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "jar2exe.h"
+
+#define RSTR_JAR2EXE "Java jar launcher"
+
+IDI_MAINICON         ICON                   "../../resources/procrunw.ico" 
+
+1 VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "040904b0"
+    BEGIN
+      VALUE "Comments", "\0"
+      VALUE "CompanyName", "Apache Software Foundation\0"
+      VALUE "FileDescription", RSTR_JAR2EXE "\0"
+      VALUE "FileVersion", PRG_VERSION
+      VALUE "InternalName", RSTR_JAR2EXE "\0"
+      VALUE "LegalCopyright", "Copyright � 2000-2003 The Apache Software Foundation.\0"
+      VALUE "OriginalFilename", "jar2exe.exe\0"
+      VALUE "ProductName", RSTR_JAR2EXE "\0"
+      VALUE "ProductVersion", PRG_VERSION
+    END
+  END
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x409, 1200
+  END
+END 
diff --git a/src/native/nt/procrun/testchild/testchild.vcproj b/src/native/nt/procrun/apps/jar2exe/jar2exe.vcproj
similarity index 51%
copy from src/native/nt/procrun/testchild/testchild.vcproj
copy to src/native/nt/procrun/apps/jar2exe/jar2exe.vcproj
index e3cacb1..b24ced4 100644
--- a/src/native/nt/procrun/testchild/testchild.vcproj
+++ b/src/native/nt/procrun/apps/jar2exe/jar2exe.vcproj
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding = "windows-1250"?>
+<?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="7.00"
-	Name="testchild"
-	ProjectGUID="{C815B005-1292-47F7-9052-F46676CE2879}"
+	Version="7.10"
+	Name="jar2exe"
+	ProjectGUID="{DA9F3DDA-F85A-492A-B914-6A361429FC41}"
 	Keyword="Win32Proj">
 	<Platforms>
 		<Platform
@@ -12,13 +12,14 @@
 	<Configurations>
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="Debug"
-			IntermediateDirectory="Debug"
+			OutputDirectory="..\..\obj\Debug"
+			IntermediateDirectory="..\..\obj\Debug"
 			ConfigurationType="1"
 			CharacterSet="2">
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
+				AdditionalIncludeDirectories=".\;..\..\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -31,10 +32,11 @@
 				Name="VCCustomBuildTool"/>
 			<Tool
 				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
+				AdditionalDependencies="shlwapi.lib"
+				OutputFile="../../bin/jar2exe.exe"
 				LinkIncremental="2"
 				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/testchild.pdb"
+				ProgramDatabaseFile="$(OutDir)/jar2exe.pdb"
 				SubSystem="1"
 				TargetMachine="1"/>
 			<Tool
@@ -46,38 +48,43 @@
 			<Tool
 				Name="VCPreLinkEventTool"/>
 			<Tool
-				Name="VCResourceCompilerTool"/>
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
 			<Tool
 				Name="VCWebServiceProxyGeneratorTool"/>
 			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
 				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="Release"
-			IntermediateDirectory="Release"
+			OutputDirectory="..\..\obj\Release"
+			IntermediateDirectory="..\..\obj\Release"
 			ConfigurationType="1"
 			CharacterSet="2">
 			<Tool
 				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
+				AdditionalIncludeDirectories=".\;..\..\include"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-				StringPooling="TRUE"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="TRUE"
+				RuntimeLibrary="0"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
 				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
+				DebugInformationFormat="0"/>
 			<Tool
 				Name="VCCustomBuildTool"/>
 			<Tool
 				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
+				AdditionalDependencies="shlwapi.lib"
+				OutputFile="../../bin/jar2exe.exe"
 				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
+				SuppressStartupBanner="TRUE"
+				GenerateDebugInformation="FALSE"
 				SubSystem="1"
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
@@ -91,28 +98,46 @@
 			<Tool
 				Name="VCPreLinkEventTool"/>
 			<Tool
-				Name="VCResourceCompilerTool"/>
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
 			<Tool
 				Name="VCWebServiceProxyGeneratorTool"/>
 			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
 				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
 	</Configurations>
+	<References>
+	</References>
 	<Files>
 		<Filter
 			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
-				RelativePath="testchild.c">
+				RelativePath=".\jar2exe.c">
 			</File>
 		</Filter>
 		<Filter
 			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc">
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\jar2exe.h">
+			</File>
 		</Filter>
 		<Filter
 			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+			<File
+				RelativePath=".\jar2exe.rc">
+			</File>
 		</Filter>
 	</Files>
 	<Globals>
diff --git a/src/native/nt/procrun/apps/prunmgr/prunmgr.c b/src/native/nt/procrun/apps/prunmgr/prunmgr.c
new file mode 100644
index 0000000..3bca94f
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunmgr/prunmgr.c
@@ -0,0 +1,1698 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* ====================================================================
+ * prunsrv -- Service Runner.
+ * Contributed by Mladen Turk <mturk at apache.org>
+ * 05 Aug 2003
+ * ==================================================================== 
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI  1
+#include "apxwin.h"
+#include "prunmgr.h"
+
+LPAPXGUISTORE _gui_store  = NULL;
+#define PRUNMGR_CLASS      TEXT("PRUNMGR")
+#define TMNU_CONF          TEXT("Configure...")
+#define TMNU_START         TEXT("Start service")
+#define TMNU_STOP          TEXT("Stop service")
+#define TMNU_EXIT          TEXT("Exit")
+#define TMNU_ABOUT         TEXT("About")
+
+/* Display only Started/Paused status */
+#define STAT_STARTED        TEXT("Started")
+#define STAT_PAUSED         TEXT("Paused")
+#define STAT_STOPPED        TEXT("Stopped")
+#define STAT_DISABLED       TEXT("Disabled")
+#define STAT_NONE           TEXT("")
+#define STAT_SYSTEM         L"LocalSystem"
+
+#define LOGL_ERROR          L"Error"
+#define LOGL_DEBUG          L"Debug"
+#define LOGL_INFO           L"Info"
+#define LOGL_WARN           L"Warning"
+
+
+#define START_AUTO           L"Automatic"
+#define START_MANUAL         L"Manual"
+#define START_DISABLED       L"Disabled"
+#define START_BOOT           L"Boot"
+#define START_SYSTEM         L"SystemInit"
+#define EMPTY_PASSWORD       L"               " 
+
+/* Main application pool */
+APXHANDLE hPool     = NULL;
+APXHANDLE hService  = NULL;
+APXHANDLE hRegistry = NULL;
+APXHANDLE hRegserv  = NULL;
+HICON     hIcoRun   = NULL;
+HICON     hIcoStop  = NULL;
+
+LPAPXSERVENTRY _currentEntry = NULL;
+
+BOOL      bEnableTry = FALSE;
+DWORD     startPage  = 0;
+
+static LPCWSTR  _s_log          = L"Log";
+static LPCWSTR  _s_java         = L"Java";
+static LPCWSTR  _s_start        = L"Start";
+static LPCWSTR  _s_stop         = L"Stop";
+
+/* Allowed procrun commands */
+static LPCWSTR _commands[] = {
+    L"ES",      /* 1 Manage Service (default)*/
+    L"MS",      /* 2 Monitor Service */
+    L"MR",      /* 3 Monitor Service and start if not runing */
+    L"MQ",      /* 4 Quit all running Monitor applications */
+    NULL
+};
+
+/* Allowed procrun parameters */
+static APXCMDLINEOPT _options[] = {
+/* 0  */    { L"AllowMultiInstances", NULL, NULL,   APXCMDOPT_INT, NULL, 0},
+            /* NULL terminate the array */
+            { NULL }
+};
+
+/* Create RBUTTON try menu 
+ * Configure... (default, or lbutton dblclick)
+ * Start <service name>
+ * Stop  <service name>
+ * Exit
+ * Logo
+ */
+static void createRbuttonTryMenu(HWND hWnd)
+{
+    HMENU hMnu;
+    POINT pt;
+    BOOL canStop  = FALSE;
+    BOOL canStart = FALSE;
+    hMnu = CreatePopupMenu();
+    
+    if (_currentEntry) {        
+        if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING) {
+            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP)
+                canStop = TRUE;
+        }
+        else if (_currentEntry->stServiceStatus.dwCurrentState == SERVICE_STOPPED) {
+            if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED)
+                canStart = TRUE;
+        }
+    }
+    apxAppendMenuItem(hMnu, IDM_TM_CONFIG, TMNU_CONF,  TRUE, TRUE);
+    apxAppendMenuItem(hMnu, IDM_TM_START,  TMNU_START, FALSE, canStart);
+    apxAppendMenuItem(hMnu, IDM_TM_STOP,   TMNU_STOP,  FALSE, canStop);
+    apxAppendMenuItem(hMnu, IDM_TM_EXIT,   TMNU_EXIT,  FALSE, TRUE);
+    apxAppendMenuItem(hMnu,    -1, NULL,   FALSE, FALSE);
+    apxAppendMenuItem(hMnu, IDM_TM_ABOUT,  TMNU_ABOUT, FALSE, TRUE);
+    
+    /* Ensure we have a focus */
+    if (!SetForegroundWindow(hWnd))
+        SetForegroundWindow(NULL);
+    GetCursorPos(&pt);
+    /* Display the try menu */
+    TrackPopupMenu(hMnu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
+                   pt.x, pt.y, 0, hWnd, NULL);
+    DestroyMenu(hMnu); 
+}
+
+/* wParam progress dialog handle
+ */
+static BOOL __startServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                   WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            if (IS_INVALID_HANDLE(hService)) {
+                EndDialog(hDlg, IDOK);
+                PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                            MAKEWPARAM(IDMS_REFRESH, 0), 0);
+                return FALSE;
+            }
+            if (apxServiceControl(hService, SERVICE_CONTROL_CONTINUE, WM_USER+2,
+                                  __startServiceCallback, hDlg)) {
+                _currentEntry->stServiceStatus.dwCurrentState = SERVICE_RUNNING;
+                _currentEntry->stStatusProcess.dwCurrentState = SERVICE_RUNNING;
+                                
+            }
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(500);
+            break;
+    }
+    return TRUE;
+} 
+
+static BOOL __stopServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                   WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            if (IS_INVALID_HANDLE(hService))
+                return FALSE;
+            if (apxServiceControl(hService, SERVICE_CONTROL_STOP, WM_USER+2,
+                                  __stopServiceCallback, hDlg)) {
+            }
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            if (wParam == 4)
+                AplCopyMemory(&_currentEntry->stServiceStatus,
+                              (LPVOID)lParam, sizeof(SERVICE_STATUS));
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(100);
+            break;
+    }
+    return TRUE;
+}
+
+static BOOL __restartServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                     WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            if (IS_INVALID_HANDLE(hService))
+                return FALSE;
+            /* TODO: use 128 as controll code */
+            if (apxServiceControl(hService, 128, WM_USER+2,
+                                  __restartServiceCallback, hDlg)) {
+                                
+            }
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            if (wParam == 4)
+                AplCopyMemory(&_currentEntry->stServiceStatus,
+                              (LPVOID)lParam, sizeof(SERVICE_STATUS));
+
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(100);
+            break;
+    }
+    return TRUE;
+}
+
+static BOOL __pauseServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                   WPARAM wParam, LPARAM lParam)
+{
+    HWND hDlg = (HWND)hObject;
+    switch (uMsg) {
+        case WM_USER+1:
+            hDlg = (HWND)lParam;
+            if (IS_INVALID_HANDLE(hService))
+                return FALSE;
+            if (apxServiceControl(hService, SERVICE_CONTROL_PAUSE, WM_USER+2,
+                                  __pauseServiceCallback, hDlg)) {
+            }
+            EndDialog(hDlg, IDOK);
+            PostMessage(_gui_store->hMainWnd, WM_COMMAND,
+                        MAKEWPARAM(IDMS_REFRESH, 0), 0);
+        break;
+        case WM_USER+2:
+            if (wParam == 4)
+                AplCopyMemory(&_currentEntry->stServiceStatus,
+                             (LPVOID)lParam, sizeof(SERVICE_STATUS));
+            SendMessage(hDlg, WM_USER+1, 0, 0);
+            Sleep(100);
+            break;
+    }
+    return TRUE;
+}
+
+static DWORD  _propertyChanged;
+static BOOL   _propertyOpened = FALSE;
+static HWND   _propertyHwnd = NULL;
+/* Service property pages */
+int CALLBACK __propertyCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
+{
+    switch(uMsg) {
+        case PSCB_PRECREATE:       
+           {
+                LPDLGTEMPLATE  lpTemplate = (LPDLGTEMPLATE)lParam;
+                if (!(lpTemplate->style & WS_SYSMENU))
+                    lpTemplate->style |= WS_SYSMENU;
+                _propertyHwnd = hwndPropSheet;
+
+                _propertyChanged = 0;
+                _propertyOpened = TRUE;
+                return TRUE;
+            }
+        break;
+        case PSCB_INITIALIZED:
+        break;
+    }
+    return TRUE;
+}
+
+BOOL __generalPropertySave(HWND hDlg) 
+{
+    WCHAR szN[256];
+    WCHAR szD[256];
+    DWORD dwStartType = SERVICE_NO_CHANGE;
+    int i;
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 1);
+
+    if (IS_INVALID_HANDLE(hService))
+        return FALSE;
+    GetDlgItemTextW(hDlg, IDC_PPSGDISP, szN, 255);
+    GetDlgItemTextW(hDlg, IDC_PPSGDESC, szD, 1023);
+    i = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST));
+    if (i == 0)
+        dwStartType = SERVICE_AUTO_START;
+    else if (i == 1)
+        dwStartType = SERVICE_DEMAND_START;
+    else if (i == 2)
+        dwStartType = SERVICE_DISABLED;
+    apxServiceSetNames(hService, NULL, szN, szD, NULL, NULL);
+    apxServiceSetOptions(hService, SERVICE_NO_CHANGE, dwStartType, SERVICE_NO_CHANGE);
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+
+    return TRUE;
+}
+
+BOOL __generalLogonSave(HWND hDlg) 
+{
+    WCHAR szU[64];
+    WCHAR szP[64];
+    WCHAR szC[64];
+    DWORD dwStartType = SERVICE_NO_CHANGE;
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 2)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 2);
+
+    if (IS_INVALID_HANDLE(hService))
+        return FALSE;
+    GetDlgItemTextW(hDlg, IDC_PPSLUSER,  szU, 63);
+    GetDlgItemTextW(hDlg, IDC_PPSLPASS,  szP, 63);
+    GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+    
+    if (lstrlenW(szU) && lstrcmpiW(szU, STAT_SYSTEM)) {
+        if (szP[0] != L' ' &&  szC[0] != L' ' && !lstrcmpW(szP, szC))
+            apxServiceSetNames(hService, NULL, NULL, NULL, szU, szP);
+        else {
+            MessageBoxW(hDlg, apxLoadResourceW(IDS_VALIDPASS, 0),
+                        apxLoadResourceW(IDS_APPLICATION, 1),
+                        MB_OK | MB_ICONSTOP);
+            return FALSE;
+        }
+    }             
+    else {
+        if (IsDlgButtonChecked(hDlg, IDC_PPSLID) == BST_CHECKED)
+            apxServiceSetOptions(hService,
+                _currentEntry->stServiceStatus.dwServiceType | SERVICE_INTERACTIVE_PROCESS,
+                SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+        else
+            apxServiceSetOptions(hService,
+                _currentEntry->stServiceStatus.dwServiceType & ~SERVICE_INTERACTIVE_PROCESS,
+                SERVICE_NO_CHANGE, SERVICE_NO_CHANGE);
+    }
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+    return TRUE;
+}
+
+BOOL __generalLoggingSave(HWND hDlg) 
+{
+    WCHAR szB[SIZ_DESLEN];
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 3)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 3);
+
+    if (IS_INVALID_HANDLE(hService))
+        return FALSE;
+
+    GetDlgItemTextW(hDlg, IDC_PPLGLEVEL,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Level", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPLGPATH,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Path", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPLGPREFIX,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Prefix", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPLGSTDOUT,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdOutput", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPLGSTDERR,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdError", szB); 
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+    return TRUE;
+}
+
+BOOL __generalJvmSave(HWND hDlg) 
+{
+    WCHAR szB[SIZ_DESLEN];
+    LPWSTR p, s;
+    DWORD  l;
+    if (!(TST_BIT_FLAG(_propertyChanged, 4)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 4);
+
+    if (IS_INVALID_HANDLE(hService))
+        return FALSE;
+    if (!IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
+        GetDlgItemTextW(hDlg, IDC_PPJJVM,  szB, SIZ_DESMAX);
+    }
+    else
+        lstrcpyW(szB, L"auto");
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Jvm", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPJCLASSPATH,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"Classpath", szB); 
+    
+    l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPJOPTIONS));
+    p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+    GetDlgItemTextW(hDlg, IDC_PPJOPTIONS,  p, l + 1);
+    s = apxCRLFToMszW(hPool, p, &l);
+    apxFree(p);
+    apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+                         _s_java, L"Options", s, l);
+    if (!GetDlgItemTextW(hDlg, IDC_PPJMS,  szB, SIZ_DESMAX))
+        szB[0] = L'\0';
+
+    apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMs",
+                       apxAtoulW(szB));
+    if (!GetDlgItemTextW(hDlg, IDC_PPJMX,  szB, SIZ_DESMAX))
+        szB[0] = L'\0';
+    apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmMx",
+                       apxAtoulW(szB));
+    if (!GetDlgItemTextW(hDlg, IDC_PPJSS,  szB, SIZ_DESMAX))
+        szB[0] = L'\0';
+    apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_java, L"JvmSs",
+                       apxAtoulW(szB));
+    apxFree(s);
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+    return TRUE;
+}
+
+BOOL __generalStartSave(HWND hDlg) 
+{
+    WCHAR szB[SIZ_DESLEN];
+    LPWSTR p, s;
+    DWORD  l;
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 5)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 5);
+
+    if (IS_INVALID_HANDLE(hService))
+        return FALSE;
+
+    GetDlgItemTextW(hDlg, IDC_PPRCLASS,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Class", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPRIMAGE,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Image", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPRWPATH,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"WorkingPath", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPRMETHOD,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Method", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPRMODE,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_start, L"Mode", szB); 
+    
+    l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPRARGS));
+    p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+    GetDlgItemTextW(hDlg, IDC_PPRARGS,  p, l + 1);
+    s = apxCRLFToMszW(hPool, p, &l);
+    apxFree(p);
+    apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+                         _s_start, L"Params", s, l);
+    apxFree(s);
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+    return TRUE;
+}
+
+BOOL __generalStopSave(HWND hDlg) 
+{
+    WCHAR szB[SIZ_DESLEN];
+    LPWSTR p, s;
+    DWORD  l;
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 6)))
+        return TRUE;
+    CLR_BIT_FLAG(_propertyChanged, 6);
+
+    if (IS_INVALID_HANDLE(hService))
+        return FALSE;
+
+    GetDlgItemTextW(hDlg, IDC_PPSCLASS,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Class", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPSIMAGE,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Image", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPSWPATH,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"WorkingPath", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPSMETHOD,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Method", szB); 
+    GetDlgItemTextW(hDlg, IDC_PPSTIMEOUT,  szB, SIZ_DESMAX);
+    apxRegistrySetNumW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Timeout", apxAtoulW(szB)); 
+    GetDlgItemTextW(hDlg, IDC_PPSMODE,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_stop, L"Mode", szB); 
+    
+    l = GetWindowTextLength(GetDlgItem(hDlg, IDC_PPSARGS));
+    p = apxPoolAlloc(hPool, (l + 2) * sizeof(WCHAR));
+    GetDlgItemTextW(hDlg, IDC_PPSARGS,  p, l + 1);
+    s = apxCRLFToMszW(hPool, p, &l);
+    apxFree(p);
+    apxRegistrySetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+                         _s_stop, L"Params", s, l);
+    apxFree(s);
+
+    if (!(TST_BIT_FLAG(_propertyChanged, 1)))
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, MAKEWPARAM(IDMS_REFRESH, 0), 0);
+    return TRUE;
+}
+
+void __generalPropertyRefresh(HWND hDlg)
+{
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), FALSE);
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), FALSE);
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), FALSE);
+    Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), FALSE);
+    switch (_currentEntry->stServiceStatus.dwCurrentState) {
+        case SERVICE_RUNNING:
+            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP ||
+                _currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTOP), TRUE);
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STARTED);
+            }
+            else
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+            if (_currentEntry->stServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) {
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGPAUSE), TRUE);
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+            }
+        break;
+        case SERVICE_PAUSED:
+            Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+            Button_Enable(GetDlgItem(hDlg, IDC_PPSGRESTART), TRUE);
+            SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_PAUSED);
+        break;
+        case SERVICE_STOPPED:
+            if (_currentEntry->lpConfig->dwStartType != SERVICE_DISABLED) {
+                Button_Enable(GetDlgItem(hDlg, IDC_PPSGSTART), TRUE);
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_STOPPED);
+            }
+            else
+                SetDlgItemText(hDlg, IDC_PPSGSTATUS, STAT_DISABLED);
+        break;
+        default:
+        break;
+    }
+}
+
+static BOOL bpropCentered = FALSE;
+LRESULT CALLBACK __generalProperty(HWND hDlg,
+                                   UINT uMessage,
+                                   WPARAM wParam,
+                                   LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    WCHAR       szBuf[1024]; 
+
+    switch (uMessage) { 
+        case WM_INITDIALOG: 
+            {              
+                if (!bEnableTry)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                else if (!bpropCentered)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                bpropCentered = TRUE;
+                startPage = 0;
+                if (!bEnableTry)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSGDISP), EM_LIMITTEXT, 255, 0);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSGDESC), EM_LIMITTEXT, 1023, 0);
+
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_AUTO);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_MANUAL);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSGCMBST), START_DISABLED);
+                if (_currentEntry->lpConfig->dwStartType == SERVICE_AUTO_START)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 0);
+                else if (_currentEntry->lpConfig->dwStartType == SERVICE_DEMAND_START)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 1);
+                else if (_currentEntry->lpConfig->dwStartType == SERVICE_DISABLED)
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSGCMBST), 2);
+
+                SetDlgItemTextW(hDlg, IDC_PPSGNAME, _currentEntry->szServiceName);
+                SetDlgItemTextW(hDlg, IDC_PPSGDISP, _currentEntry->lpConfig->lpDisplayName);
+                SetDlgItemTextW(hDlg, IDC_PPSGDESC, _currentEntry->szServiceDescription);
+                SetDlgItemTextW(hDlg, IDC_PPSGDEXE, _currentEntry->lpConfig->lpBinaryPathName);
+                __generalPropertyRefresh(hDlg);
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPSGCMBST:
+                    if (HIWORD(wParam) == CBN_SELCHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 1);
+                    }
+                break;
+                case IDC_PPSGDISP:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        GetDlgItemTextW(hDlg, IDC_PPSGDISP, szBuf, 255);
+                        if (!lstrcmpW(szBuf, _currentEntry->lpConfig->lpDisplayName)) {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 1);
+                        }
+                        else {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 1);
+                        }
+                    }
+                break;
+                case IDC_PPSGDESC:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        GetDlgItemTextW(hDlg, IDC_PPSGDESC, szBuf, 1023);
+                        if (!lstrcmpW(szBuf, _currentEntry->szServiceDescription)) {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 1);
+                        }
+                        else {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 1);
+                        }
+                    }
+                break;
+                case IDC_PPSGSTART:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSSTART, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __startServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+                case IDC_PPSGSTOP:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSSTOP, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __stopServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+                case IDC_PPSGPAUSE:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSPAUSE, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __pauseServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+                case IDC_PPSGRESTART:
+                    apxProgressBox(hDlg, apxLoadResource(IDS_HSRESTART, 0),
+                                   _currentEntry->lpConfig->lpDisplayName,
+                                   __restartServiceCallback, NULL);
+                    __generalPropertyRefresh(hDlg);
+                break;
+            }
+        break;
+        case WM_NOTIFY:           
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalPropertySave(hDlg)) {
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                    }
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 1);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+                default:
+                break;
+            }
+        break;
+        default:
+        break;
+    }
+ 
+    return FALSE;
+}
+
+LRESULT CALLBACK __logonProperty(HWND hDlg,
+                                 UINT uMessage,
+                                 WPARAM wParam,
+                                 LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    WCHAR       szBuf[1024]; 
+    switch (uMessage) { 
+        case WM_INITDIALOG:
+            {
+                BOOL           bAccount = FALSE;
+                startPage = 1;
+                if (!bpropCentered)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                bpropCentered = TRUE;
+
+                SendMessage(GetDlgItem(hDlg, IDC_PPSLUSER), EM_LIMITTEXT, 63, 0);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSLPASS), EM_LIMITTEXT, 63, 0);
+                SendMessage(GetDlgItem(hDlg, IDC_PPSLCPASS), EM_LIMITTEXT, 63, 0);
+                /* Check if we use LocalSystem or user defined account */
+                if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+                    bAccount = TRUE;
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLUA);
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+                    SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+                    SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+                }
+                else {
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, IDC_PPSLLS);
+                    if (_currentEntry->lpConfig->dwServiceType & 
+                        SERVICE_INTERACTIVE_PROCESS)
+                        CheckDlgButton(hDlg, IDC_PPSLID, BST_CHECKED);
+                }
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), !bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), bAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), bAccount);
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPSLLS:
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, L"");
+                    SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
+                    SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), FALSE);
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);                     
+                    if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    else {
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                        CLR_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    break;
+                case IDC_PPSLUA:
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, _currentEntry->szObjectName);
+                    SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
+                    SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLPASS), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDL_PPSLCPASS), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLCPASS), TRUE);
+                    CheckRadioButton(hDlg, IDC_PPSLLS, IDC_PPSLUA, (INT)wParam);                     
+                    if (lstrcmpW(_currentEntry->szObjectName, STAT_SYSTEM)) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    else {
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                        CLR_BIT_FLAG(_propertyChanged, 2);
+                    }
+                    break;
+                case IDC_PPSLID:
+                    PropSheet_Changed(GetParent(hDlg), hDlg); 
+                    SET_BIT_FLAG(_propertyChanged, 2);
+                break;
+                case IDC_PPSLUSER:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        GetDlgItemTextW(hDlg, IDC_PPSLUSER, szBuf, 63);
+                        if (!lstrcmpiW(szBuf, _currentEntry->szObjectName)) {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 2);
+                        }
+                        else {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 2);
+                        }
+                    }
+                break;
+                case IDC_PPSLPASS:
+                case IDC_PPSLCPASS:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        WCHAR szP[64];
+                        WCHAR szC[64];
+                        GetDlgItemTextW(hDlg, IDC_PPSLPASS, szP, 63);
+                        GetDlgItemTextW(hDlg, IDC_PPSLCPASS, szC, 63);
+                        /* check for valid password match */
+                        if (szP[0] == L' ' &&  szC[0] == L' ') {
+                            PropSheet_UnChanged(GetParent(hDlg), hDlg);
+                            CLR_BIT_FLAG(_propertyChanged, 2);
+                        }
+                        else if (!lstrcmpW(szP, szC)) {
+                            PropSheet_Changed(GetParent(hDlg), hDlg);
+                            SET_BIT_FLAG(_propertyChanged, 2);
+                        }
+                    }
+                break;
+                case IDC_PPSLBROWSE:
+                    {
+                        WCHAR szUser[SIZ_RESLEN];
+                        if (apxDlgSelectUser(hDlg, szUser))
+                            SetDlgItemTextW(hDlg, IDC_PPSLUSER, szUser);
+                    }
+                break;
+            }
+        break;
+        case WM_NOTIFY:
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalLogonSave(hDlg))
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 2);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+            }
+        break;
+
+        default:
+        break;
+    }
+    return FALSE;
+}
+
+LRESULT CALLBACK __loggingProperty(HWND hDlg,
+                                   UINT uMessage,
+                                   WPARAM wParam,
+                                   LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    LPWSTR      lpBuf;
+
+    switch (uMessage) { 
+        case WM_INITDIALOG: 
+            {
+                LPWSTR b;
+                startPage = 2;
+                if (!bpropCentered)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                bpropCentered = TRUE;
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_ERROR);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_INFO);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_WARN);
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPLGLEVEL), LOGL_DEBUG);
+                if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_log, L"Level")) != NULL) {
+                    if (!lstrcmpiW(b, LOGL_ERROR))
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
+                    else if (!lstrcmpiW(b, LOGL_INFO))
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 1);
+                    else if (!lstrcmpiW(b, LOGL_WARN))
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 2);
+                    else
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 3);
+                    apxFree(b);
+                }
+                else
+                    ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPLGLEVEL), 0);
+                if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_log, L"Path")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPLGPATH, b);                    
+                    apxFree(b);
+                }
+                if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_log, L"StdOutput")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);                    
+                    apxFree(b);
+                }
+                if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_log, L"StdError")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, b);                    
+                    apxFree(b);
+                }                
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPLGLEVEL:
+                    if (HIWORD(wParam) == CBN_SELCHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 3);
+                    }
+                break;
+                case IDC_PPLGPATH:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 3);                    
+                    }
+                break;
+                case IDC_PPLGPREFIX:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 3);                    
+                    }
+                break;
+                case IDC_PPLGSTDERR:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 3);                    
+                    }
+                break;
+                case IDC_PPLGSTDOUT:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 3);                    
+                    }
+                break;
+                case IDC_PPLGBPATH:
+                    lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_LGPATHTITLE, 0),
+                                                NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPLGPATH, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 3);
+                    }
+                break;
+                case IDC_PPLGBSTDOUT:
+                    lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDOUT, 0),
+                                            apxLoadResourceW(IDS_ALLFILES, 1), NULL,
+                                            NULL, FALSE, NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 3);
+                    }
+                break;
+                case IDC_PPLGBSTDERR:
+                    lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_LGSTDERR, 0),
+                                            apxLoadResourceW(IDS_ALLFILES, 1), NULL,
+                                            NULL, FALSE, NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPLGSTDERR, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 3);
+                    }
+                break;
+            }
+        break;
+        case WM_NOTIFY:
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalLoggingSave(hDlg))
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 3);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+            }
+        break;
+
+        default:
+        break;
+    }
+    return FALSE;
+}
+
+LRESULT CALLBACK __jvmProperty(HWND hDlg,
+                               UINT uMessage,
+                               WPARAM wParam,
+                               LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    LPWSTR      lpBuf, b;
+    DWORD       v;
+    CHAR        bn[32];
+
+    switch (uMessage) { 
+        case WM_INITDIALOG: 
+            {
+                startPage = 3;
+                if (!bpropCentered)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                bpropCentered = TRUE;
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_java, L"Jvm")) != NULL) {
+                    if (!lstrcmpiW(lpBuf, L"auto")) {
+                        CheckDlgButton(hDlg, IDC_PPJAUTO, BST_CHECKED);
+                        apxFree(lpBuf);
+                        lpBuf = apxGetJavaSoftRuntimeLib(hPool);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
+                    }
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+                        apxFree(lpBuf);
+                    }
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_java, L"Classpath")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPJCLASSPATH, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_java, L"Options", NULL, NULL)) != NULL) {
+                    LPWSTR p = apxMszToCRLFW(hPool, lpBuf);
+                    SetDlgItemTextW(hDlg, IDC_PPJOPTIONS, p);
+                    apxFree(lpBuf);
+                    apxFree(p);
+                }
+                v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+                                          _s_java, L"JvmMs");
+                if (v && v != 0xFFFFFFFF) {
+                    wsprintfA(bn, "%d", v);
+                    SetDlgItemTextA(hDlg, IDC_PPJMS, bn);
+                }
+                v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+                                          _s_java, L"JvmMx");
+                if (v && v != 0xFFFFFFFF) {
+                    wsprintfA(bn, "%d", v);
+                    SetDlgItemTextA(hDlg, IDC_PPJMX, bn);
+                }
+                v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+                                          _s_java, L"JvmSs");
+                if (v && v != 0xFFFFFFFF) {
+                    wsprintfA(bn, "%d", v);
+                    SetDlgItemTextA(hDlg, IDC_PPJSS, bn);
+                }
+
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPJBJVM:
+                    b = apxGetJavaSoftHome(hPool, TRUE);
+                    lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPJBJVM, 0),
+                                            apxLoadResourceW(IDS_DLLFILES, 1), NULL,
+                                            b,
+                                            TRUE, NULL);
+                    apxFree(b);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 4);
+                    }
+                break;
+                case IDC_PPJAUTO:
+                    PropSheet_Changed(GetParent(hDlg), hDlg); 
+                    SET_BIT_FLAG(_propertyChanged, 4);
+                    if (IsDlgButtonChecked(hDlg, IDC_PPJAUTO)) {
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), FALSE);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), FALSE);
+                        lpBuf = apxGetJavaSoftRuntimeLib(hPool);
+                        if (lpBuf) {
+                            SetDlgItemTextW(hDlg, IDC_PPJJVM, lpBuf);
+                            apxFree(lpBuf);
+                        }
+                    }
+                    else {
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPJJVM), TRUE);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPJBJVM), TRUE);
+                    }
+                break;
+                case IDC_PPJJVM:
+                case IDC_PPJCLASSPATH:
+                case IDC_PPJOPTIONS:
+                case IDC_PPJMX:
+                case IDC_PPJMS:
+                case IDC_PPJSS:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 4);
+                    }
+                break;
+            }
+        break;
+        case WM_NOTIFY:
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalJvmSave(hDlg))
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 4);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+            }
+        break;
+
+        default:
+        break;
+    }
+    return FALSE;
+}
+
+LRESULT CALLBACK __startProperty(HWND hDlg,
+                                 UINT uMessage,
+                                 WPARAM wParam,
+                                 LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    LPWSTR      lpBuf, b;
+
+    switch (uMessage) { 
+        case WM_INITDIALOG: 
+            {
+                startPage = 4;
+                if (!bpropCentered)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                bpropCentered = TRUE;
+
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"");
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), L"jvm");
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPRMODE), _s_java);
+
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_start, L"Class")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPRCLASS, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_start, L"Image")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_start, L"WorkingPath")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_start, L"Method")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPRMETHOD, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_start, L"Params", NULL, NULL)) != NULL) {
+                    b = apxMszToCRLFW(hPool, lpBuf);
+                    SetDlgItemTextW(hDlg, IDC_PPRARGS, b);
+                    apxFree(lpBuf);
+                    apxFree(b);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_start, L"Mode")) != NULL) {
+                    if (!lstrcmpiW(lpBuf, L"jvm")) {
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 1);
+
+                    }
+                    else if (!lstrcmpiW(lpBuf, _s_java)) {
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 2);
+                    }
+                    else {
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPRMODE), 0);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
+                    }
+                    apxFree(lpBuf);
+                }
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPRBWPATH:
+                    lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
+                                                NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPRWPATH, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 5);
+                    }
+                break;
+                case IDC_PPRBIMAGE:
+                    lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
+                                            apxLoadResourceW(IDS_EXEFILES, 1), NULL,
+                                            NULL, TRUE, NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPRIMAGE, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 5);
+                    }
+                break;
+                case IDC_PPRCLASS:
+                case IDC_PPRMETHOD:
+                case IDC_PPRARGS:
+                case IDC_PPRIMAGE:
+                case IDC_PPRWPATH:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 5);
+                    }
+                break;
+                case IDC_PPRMODE:
+                    if (HIWORD(wParam) == CBN_SELCHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 5);
+                        if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPRMODE))) {
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), FALSE);
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), FALSE);
+                        }
+                        else {
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPRIMAGE), TRUE);
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPRBIMAGE), TRUE);
+                        }
+                    }
+                break;
+
+            }
+        break;
+        case WM_NOTIFY:
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalStartSave(hDlg))
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 5);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+            }
+        break;
+
+        default:
+        break;
+    }
+    return FALSE;
+}
+
+LRESULT CALLBACK __stopProperty(HWND hDlg,
+                                UINT uMessage,
+                                WPARAM wParam,
+                                LPARAM lParam)
+{
+    LPPSHNOTIFY lpShn;
+    LPWSTR      lpBuf, b;
+    DWORD       v;
+
+    switch (uMessage) { 
+        case WM_INITDIALOG: 
+            {
+                startPage = 5;
+                if (!bpropCentered)
+                    apxCenterWindow(GetParent(hDlg), NULL);
+                bpropCentered = TRUE;
+
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"");
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), L"jvm");
+                ComboBox_AddStringW(GetDlgItem(hDlg, IDC_PPSMODE), _s_java);
+
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_stop, L"Class")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPSCLASS, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_stop, L"Image")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_stop, L"WorkingPath")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_stop, L"Method")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPSMETHOD, lpBuf);
+                    apxFree(lpBuf);
+                }
+                if ((lpBuf = apxRegistryGetMzStrW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_stop, L"Params", NULL, NULL)) != NULL) {
+                    b = apxMszToCRLFW(hPool, lpBuf);
+                    SetDlgItemTextW(hDlg, IDC_PPSARGS, b);
+                    apxFree(lpBuf);
+                    apxFree(b);
+                }
+                v = apxRegistryGetNumberW(hRegserv, APXREG_PARAMSOFTWARE,
+                                          _s_stop, L"Timeout");
+                {
+                    CHAR bn[32];
+                    wsprintfA(bn, "%d", v);
+                    SetDlgItemTextA(hDlg, IDC_PPSTIMEOUT, bn);
+                }
+                if ((lpBuf = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                                   _s_stop, L"Mode")) != NULL) {
+                    if (!lstrcmpiW(lpBuf, L"jvm")) {
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 1);
+
+                    }
+                    else if (!lstrcmpiW(lpBuf, _s_java)) {
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 2);
+                    }
+                    else {
+                        ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PPSMODE), 0);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
+                        EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
+                    }
+                    apxFree(lpBuf);
+                }
+            }
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDC_PPSBWPATH:
+                    lpBuf = apxBrowseForFolderW(hDlg, apxLoadResourceW(IDS_PPWPATH, 0),
+                                                NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPSWPATH, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 6);
+                    }
+                break;
+                case IDC_PPSBIMAGE:
+                    lpBuf = apxGetFileNameW(hDlg, apxLoadResourceW(IDS_PPIMAGE, 0),
+                                            apxLoadResourceW(IDS_EXEFILES, 1), NULL,
+                                            NULL, TRUE, NULL);
+                    if (lpBuf) {
+                        SetDlgItemTextW(hDlg, IDC_PPSIMAGE, lpBuf);                    
+                        apxFree(lpBuf);
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 6);
+                    }
+                break;
+                case IDC_PPSCLASS:
+                case IDC_PPSMETHOD:
+                case IDC_PPSTIMEOUT:
+                case IDC_PPSARGS:
+                case IDC_PPSIMAGE:
+                case IDC_PPSWPATH:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 6);
+                    }
+                break;
+                case IDC_PPSMODE:
+                    if (HIWORD(wParam) == CBN_SELCHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg); 
+                        SET_BIT_FLAG(_propertyChanged, 6);
+                        if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PPSMODE))) {
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), FALSE);
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), FALSE);
+                        }
+                        else {
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPSIMAGE), TRUE);
+                            EnableWindow(GetDlgItem(hDlg, IDC_PPSBIMAGE), TRUE);
+                        }
+                    }
+                break;
+
+            }
+        break;
+        case WM_NOTIFY:
+            lpShn = (LPPSHNOTIFY )lParam;
+            switch (lpShn->hdr.code) {
+                case PSN_APPLY:   /* sent when OK or Apply button pressed */ 
+                    if (__generalStopSave(hDlg))
+                        PropSheet_UnChanged(GetParent(hDlg), hDlg); 
+                    else {
+                        SET_BIT_FLAG(_propertyChanged, 6);
+                        SetWindowLong(hDlg, DWL_MSGRESULT,
+                                      PSNRET_INVALID_NOCHANGEPAGE);
+                        return TRUE;                        
+                    }
+
+                break;
+            }
+        break;
+
+        default:
+        break;
+    }
+    return FALSE;
+}
+
+void __initPpage(PROPSHEETPAGEW *lpPage, INT iDlg, INT iTitle, DLGPROC pfnDlgProc)
+{
+    lpPage->dwSize      = sizeof(PROPSHEETPAGE);
+    lpPage->dwFlags     = PSP_USETITLE;
+    lpPage->hInstance   = _gui_store->hInstance;
+    lpPage->pszTemplate = MAKEINTRESOURCEW(iDlg);
+    lpPage->pszIcon     = NULL;
+    lpPage->pfnDlgProc  = pfnDlgProc;
+    lpPage->pszTitle    = MAKEINTRESOURCEW(iTitle);
+    lpPage->lParam      = 0;
+}
+
+void ShowServiceProperties(HWND hWnd)
+{
+    PROPSHEETPAGEW   psP[6];
+    PROPSHEETHEADERW psH; 
+    WCHAR           szT[1024] = {0};
+    
+    if (_propertyOpened) {
+        SetForegroundWindow(_gui_store->hMainWnd);
+        return;
+    }
+    __initPpage(&psP[0], IDD_PROPPAGE_SGENERAL, IDS_PPGENERAL, 
+                __generalProperty);
+    __initPpage(&psP[1], IDD_PROPPAGE_LOGON, IDS_PPLOGON, 
+                __logonProperty);
+    __initPpage(&psP[2], IDD_PROPPAGE_LOGGING, IDS_PPLOGGING, 
+                __loggingProperty);
+    __initPpage(&psP[3], IDD_PROPPAGE_JVM, IDS_PPJAVAVM, 
+                __jvmProperty);
+    __initPpage(&psP[4], IDD_PROPPAGE_START, IDS_PPSTART, 
+                __startProperty);
+    __initPpage(&psP[5], IDD_PROPPAGE_STOP, IDS_PPSTOP, 
+                __stopProperty);
+
+    if (_currentEntry && _currentEntry->lpConfig)
+        lstrcpyW(szT, _currentEntry->lpConfig->lpDisplayName);
+    else
+        return;
+    lstrcatW(szT, L" Properties");
+
+    psH.dwSize           = sizeof(PROPSHEETHEADER);
+    psH.dwFlags          = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
+    psH.hwndParent       = bEnableTry ? hWnd : NULL;
+    psH.hInstance        = _gui_store->hInstance;
+    psH.pszIcon          = MAKEINTRESOURCEW(IDI_MAINICON);
+    psH.pszCaption       = szT;
+    psH.nPages           = 6;
+    psH.ppsp             = (LPCPROPSHEETPAGEW) &psP;
+    psH.pfnCallback      = (PFNPROPSHEETCALLBACK)__propertyCallback;
+    psH.nStartPage       = startPage;   
+    
+    PropertySheetW(&psH);
+    _propertyOpened = FALSE;
+    if (!bEnableTry)
+        PostQuitMessage(0);
+     bpropCentered = FALSE;
+
+}
+
+
+LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg,
+                             WPARAM wParam, LPARAM lParam) 
+{
+    switch (uMsg) {
+        case WM_CREATE:
+            if (bEnableTry) {
+                if (_currentEntry && _currentEntry->lpConfig) {
+                    BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
+                    apxManageTryIconW(hWnd, NIM_ADD, NULL,
+                                      _currentEntry->lpConfig->lpDisplayName,
+                                      isRunning ? hIcoRun : hIcoStop);
+                }
+                else {
+                    apxManageTryIconA(hWnd, NIM_ADD, NULL,
+                                      apxLoadResourceA(IDS_APPLICATION, 0),
+                                      NULL);
+                }
+            }
+            else
+                ShowServiceProperties(hWnd);
+
+        break;
+        case WM_COMMAND:
+            switch(LOWORD(wParam)) { 
+                case IDM_TM_CONFIG:
+                    ShowServiceProperties(hWnd);
+                break;
+                case IDM_TM_ABOUT:
+                    apxAboutBox(hWnd); 
+                break;
+                case IDM_TM_EXIT:
+                    SendMessage(hWnd, WM_CLOSE, 0, 0);                
+                break;
+                case IDM_TM_START:
+                    if (!_propertyOpened)
+                        apxProgressBox(hWnd, apxLoadResource(IDS_HSSTART, 0),
+                                       _currentEntry->lpConfig->lpDisplayName,
+                                       __startServiceCallback, NULL); 
+                break;
+                case IDM_TM_STOP:
+                    if (!_propertyOpened)
+                        apxProgressBox(hWnd, apxLoadResource(IDS_HSSTOP, 0),
+                                       _currentEntry->lpConfig->lpDisplayName,
+                                       __stopServiceCallback, NULL);
+                break;
+                case IDM_TM_PAUSE:
+                    if (!_propertyOpened)
+                        apxProgressBox(hWnd, apxLoadResource(IDS_HSPAUSE, 0),
+                                       _currentEntry->lpConfig->lpDisplayName,
+                                       __pauseServiceCallback, NULL);
+                break;
+                case IDM_TM_RESTART:
+                    if (!_propertyOpened)
+                        apxProgressBox(hWnd, apxLoadResource(IDS_HSRESTART, 0),
+                                       _currentEntry->lpConfig->lpDisplayName,
+                                       __restartServiceCallback, NULL);
+                break; 
+                case IDMS_REFRESH:
+                    if (bEnableTry && 
+                        (_currentEntry = apxServiceEntry(hService, TRUE)) != NULL) {
+                        BOOL isRunning = _currentEntry->stServiceStatus.dwCurrentState == SERVICE_RUNNING;
+                        apxManageTryIconW(hWnd, NIM_MODIFY, NULL,
+                                          _currentEntry->lpConfig->lpDisplayName,
+                                          isRunning ? hIcoRun : hIcoStop);                        
+                    }
+                break;
+
+            }
+        break;
+        case WM_TRAYMESSAGE:
+            switch(lParam) {
+                case WM_LBUTTONDBLCLK:
+                    ShowServiceProperties(hWnd);
+                break;
+                case WM_RBUTTONUP:
+                    _currentEntry = apxServiceEntry(hService, TRUE);
+                    createRbuttonTryMenu(hWnd);
+                break;
+            }
+        break;
+        case WM_QUIT:
+            return DefWindowProc(hWnd, uMsg, wParam, lParam); 
+        break;
+        case WM_DESTROY:
+            if (bEnableTry)
+                apxManageTryIconA(hWnd, NIM_DELETE, NULL, NULL, NULL);
+            PostQuitMessage(0);
+        break;
+        default:
+            return DefWindowProc(hWnd, uMsg, wParam, lParam); 
+        break;
+    }
+
+    return FALSE; 
+}
+
+static BOOL loadConfiguration()
+{
+    return TRUE;
+}
+
+static BOOL saveConfiguration()
+{
+    return TRUE;
+}
+
+/* Main program entry
+ * Since we are inependant from CRT
+ * the arguments are not used
+ */
+#ifdef _NO_CRTLIBRARY
+int xMain(void)
+#else
+int WINAPI WinMain(HINSTANCE hInstance,
+                   HINSTANCE hPrevInstance,
+                   LPSTR lpCmdLine,
+                   int nCmdShow)
+#endif
+{
+    MSG    msg;
+    LPAPXCMDLINE lpCmdline;
+    HANDLE mutex = NULL;
+    BOOL quiet = FALSE;
+
+    apxHandleManagerInitialize();
+    hPool     = apxPoolCreate(NULL, 0);
+
+    /* Parse the command line */
+    if ((lpCmdline = apxCmdlineParse(hPool, _options, _commands)) == NULL) {
+        /* TODO: dispalay error message */
+        apxDisplayError(TRUE, NULL, 0, "Error parsing command line");
+        goto cleanup;
+    }
+
+    if (!lpCmdline->dwCmdIndex) {
+        /* Skip sytem error message */
+        SetLastError(ERROR_SUCCESS);
+        apxDisplayError(TRUE, NULL, 0, 
+                        apxLoadResourceA(IDS_ERRORCMD, 0),
+                        lpCmdLine);
+        goto cleanup;
+    }
+    else if (lpCmdline->dwCmdIndex == 4)
+        quiet = TRUE;
+    else if (lpCmdline->dwCmdIndex >= 2)
+        bEnableTry = TRUE;
+    hService = apxCreateService(hPool, SC_MANAGER_CONNECT, FALSE);
+    if (IS_INVALID_HANDLE(hService)) {
+        if (!quiet)
+            apxDisplayError(TRUE, NULL, 0, "Unable to open the Service Manager");
+        goto cleanup;
+    }
+    /* Open the main service handle */
+    if (!apxServiceOpen(hService, lpCmdline->szApplication,
+                        GENERIC_READ | GENERIC_EXECUTE)) {
+        LPWSTR w = lpCmdline->szApplication + lstrlenW(lpCmdline->szApplication) - 1;
+        if (*w == L'w')
+            *w = L'\0';
+        if (!apxServiceOpen(hService, lpCmdline->szApplication,
+                            GENERIC_READ | GENERIC_EXECUTE)) {
+            if (!quiet)
+                apxDisplayError(TRUE, NULL, 0, "Unable to open the service '%S'",
+                                lpCmdline->szApplication);
+            goto cleanup;
+        }
+    }
+    /* Obtain service parameters and status */
+    if (!(_currentEntry = apxServiceEntry(hService, TRUE))) {
+        if (!quiet)
+            apxDisplayError(TRUE, NULL, 0, "Unable to query the service '%S' status",
+                            lpCmdline->szApplication);
+        goto cleanup;
+    }
+#ifdef _UNICODE
+    _gui_store = apxGuiInitialize(MainWndProc, lpCmdline->szApplication);
+#else
+    {
+        CHAR szApp[MAX_PATH];
+        _gui_store = apxGuiInitialize(MainWndProc,
+                                  WideToAscii(lpCmdline->szApplication, szApp));
+    }
+#endif
+    if (!_gui_store) {
+        if (!quiet)
+            apxDisplayError(TRUE, NULL, 0, "Unable to initialize GUI manager");
+        goto cleanup;
+    }
+    hIcoRun  = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONRUN),
+                         IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);  
+    hIcoStop = LoadImage(_gui_store->hInstance, MAKEINTRESOURCE(IDI_ICONSTOP),
+                         IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);  
+    
+    /* Handle //MQ// option */
+    if (lpCmdline->dwCmdIndex == 4) {
+        HANDLE hOther = FindWindow(_gui_store->szWndClass, NULL);
+        if (hOther)
+            SendMessage(hOther, WM_CLOSE, 0, 0);
+        goto cleanup;
+    }
+
+    if (!_options[0].dwValue) {
+        mutex = CreateMutex(NULL, FALSE, _gui_store->szWndMutex);
+        if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) { 
+            /* Skip sytem error message */
+            SetLastError(ERROR_SUCCESS);
+            if (!quiet)
+                apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ALREAY_RUNING, 0),
+                                lpCmdline->szApplication);
+            goto cleanup;
+        }
+    }
+    hRegistry = apxCreateRegistry(hPool, KEY_ALL_ACCESS, NULL,
+                                  apxLoadResource(IDS_APPLICATION, 0),
+                                  APXREG_USER);
+    loadConfiguration();
+    hRegserv = apxCreateRegistryW(hPool, KEY_READ | KEY_WRITE, PRG_REGROOT,
+                                  lpCmdline->szApplication,
+                                  APXREG_SOFTWARE | APXREG_SERVICE);
+
+    if (IS_INVALID_HANDLE(hRegserv)) {
+        if (!quiet)
+            apxDisplayError(TRUE, NULL, 0, apxLoadResourceA(IDS_ERRSREG, 0));
+        return FALSE;
+    }
+    /* Create main invisible window */
+    _gui_store->hMainWnd = CreateWindow(_gui_store->szWndClass,
+                                        apxLoadResource(IDS_APPLICATION, 0),
+                                        0, 0, 0, 0, 0,
+                                        NULL, NULL,
+                                        _gui_store->hInstance,
+                                        NULL);
+
+    if (!_gui_store->hMainWnd) {
+        goto cleanup;
+    }
+    if (lpCmdline->dwCmdIndex == 3)
+        PostMessage(_gui_store->hMainWnd, WM_COMMAND, IDM_TM_START, 0);
+
+    while (GetMessage(&msg, NULL, 0, 0))  {
+        if(!TranslateAccelerator(_gui_store->hMainWnd,
+                                 _gui_store->hAccel, &msg)) {
+            TranslateMessage(&msg);
+            DispatchMessage(&msg);
+        }
+    }
+    saveConfiguration();
+
+cleanup:
+    if (hIcoStop)
+        DestroyIcon(hIcoStop);
+    if (hIcoRun)
+        DestroyIcon(hIcoRun);
+    if (mutex)
+        CloseHandle(mutex);
+    if (lpCmdline)
+        apxCmdlineFree(lpCmdline);
+    apxCloseHandle(hService);
+    apxHandleManagerDestroy();
+    ExitProcess(0);
+    return 0;
+}
+
diff --git a/src/native/nt/procrun/apps/prunmgr/prunmgr.h b/src/native/nt/procrun/apps/prunmgr/prunmgr.h
new file mode 100644
index 0000000..11b4a8d
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunmgr/prunmgr.h
@@ -0,0 +1,138 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* ====================================================================
+ * jar2exe -- convert .jar file to WIN32 executable.
+ * Contributed by Mladen Turk <mturk at apache.org>
+ * 05 Aug 2003
+ * ==================================================================== 
+ */
+
+#ifndef _PRUNMGR_H
+#define _PRUNMGR_H
+
+#undef  PRG_VERSION
+#define PRG_VERSION    "1.0.0.0" 
+#define PRG_REGROOT   L"Apache Software Foundation\\Procrun 2.0"
+
+#define IDM_TM_EXIT                     2000
+#define IDM_TM_START                    2001
+#define IDM_TM_STOP                     2002
+#define IDM_TM_PAUSE                    2003
+#define IDM_TM_RESTART                  2004
+#define IDM_TM_CONFIG                   2005
+#define IDM_TM_ABOUT                    2006
+
+#define IDMS_REFRESH                    2020
+
+#define IDI_ICONSTOP                    2030
+#define IDI_ICONRUN                     2031
+
+
+
+/* Property pages */
+
+#define IDD_PROPPAGE_SGENERAL           2600
+#define IDC_PPSGNAME                    2601
+#define IDC_PPSGDISP                    2602
+#define IDC_PPSGDESC                    2603
+#define IDC_PPSGDEXE                    2604
+#define IDC_PPSGCMBST                   2605
+#define IDC_PPSGSTATUS                  2606
+#define IDC_PPSGSTART                   2607
+#define IDC_PPSGSTOP                    2608
+#define IDC_PPSGPAUSE                   2609
+#define IDC_PPSGRESTART                 2610
+
+#define IDD_PROPPAGE_LOGON              2620
+#define IDC_PPSLLS                      2621
+#define IDC_PPSLID                      2622
+#define IDC_PPSLUA                      2623
+#define IDC_PPSLUSER                    2624
+#define IDC_PPSLBROWSE                  2625
+#define IDC_PPSLPASS                    2626
+#define IDC_PPSLCPASS                   2627
+#define IDL_PPSLPASS                    2628
+#define IDL_PPSLCPASS                   2629
+
+#define IDD_PROPPAGE_LOGGING            2640
+#define IDC_PPLGLEVEL                   2641
+#define IDC_PPLGPATH                    2642
+#define IDC_PPLGBPATH                   2643
+#define IDC_PPLGPREFIX                  2644
+#define IDC_PPLGSTDOUT                  2645
+#define IDC_PPLGBSTDOUT                 2646
+#define IDC_PPLGSTDERR                  2647
+#define IDC_PPLGBSTDERR                 2648
+
+#define IDD_PROPPAGE_JVM                2660
+#define IDC_PPJAUTO                     2661
+#define IDC_PPJJVM                      2662
+#define IDC_PPJBJVM                     2663
+#define IDC_PPJCLASSPATH                2664
+#define IDC_PPJOPTIONS                  2665
+#define IDC_PPJMS                       2666
+#define IDC_PPJMX                       2667
+#define IDC_PPJSS                       2668
+
+#define IDD_PROPPAGE_START              2680
+#define IDC_PPRCLASS                    2681
+#define IDC_PPRIMAGE                    2682
+#define IDC_PPRBIMAGE                   2683
+#define IDC_PPRWPATH                    2684
+#define IDC_PPRBWPATH                   2685
+#define IDC_PPRMETHOD                   2686
+#define IDC_PPRARGS                     2687
+#define IDC_PPRTIMEOUT                  2688
+#define IDC_PPRMODE                     2689
+
+#define IDD_PROPPAGE_STOP               2700
+#define IDC_PPSCLASS                    2701
+#define IDC_PPSIMAGE                    2702
+#define IDC_PPSBIMAGE                   2703
+#define IDC_PPSWPATH                    2704
+#define IDC_PPSBWPATH                   2705
+#define IDC_PPSMETHOD                   2706
+#define IDC_PPSARGS                     2707
+#define IDC_PPSTIMEOUT                  2708
+#define IDC_PPSMODE                     2709
+
+#define IDS_ALREAY_RUNING               3100
+#define IDS_ERRORCMD                    3101
+#define IDS_HSSTART                     3102
+#define IDS_HSSTOP                      3103
+#define IDS_HSPAUSE                     3104
+#define IDS_HSRESTART                   3105
+#define IDS_VALIDPASS                   3106
+#define IDS_PPGENERAL                   3107
+#define IDS_PPLOGON                     3108
+#define IDS_PPLOGGING                   3109
+#define IDS_PPJAVAVM                    3110
+#define IDS_PPSTART                     3111
+#define IDS_PPSTOP                      3112
+#define IDS_LGPATHTITLE                 3113
+#define IDS_ALLFILES                    3114
+#define IDS_DLLFILES                    3115
+#define IDS_EXEFILES                    3116
+#define IDS_LGSTDERR                    3117
+#define IDS_LGSTDOUT                    3118
+#define IDS_PPJBJVM                     3119
+#define IDS_PPWPATH                     3120
+#define IDS_PPIMAGE                     3121
+#define IDS_ERRSREG                     3122
+
+#define IDS_NOTIMPLEMENTED              3199
+ 
+#endif /* _PRUNMGR_H */
diff --git a/src/native/nt/procrun/apps/prunmgr/prunmgr.manifest b/src/native/nt/procrun/apps/prunmgr/prunmgr.manifest
new file mode 100644
index 0000000..67ca946
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunmgr/prunmgr.manifest
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
+<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="Apache.Procrun.Prunmgr" type="win32" /> 
+<description>Procrun Service Manager</description> 
+<dependency> 
+<dependentAssembly> 
+<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> 
+</dependentAssembly> 
+</dependency> 
+</assembly> 
diff --git a/src/native/nt/procrun/apps/prunmgr/prunmgr.rc b/src/native/nt/procrun/apps/prunmgr/prunmgr.rc
new file mode 100644
index 0000000..b8c3e94
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunmgr/prunmgr.rc
@@ -0,0 +1,288 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "prunmgr.h"
+
+#define RSTR_PSM        "Procrun Service Manager"
+#define RSTR_SCMATS     "Service Manager is attempting to "
+ 
+IDI_MAINICON         ICON                   "../../resources/procrunw.ico" 
+IDI_ICONSTOP         ICON                   "../../resources/procruns.ico" 
+IDI_ICONRUN          ICON                   "../../resources/procrunr.ico" 
+IDR_LICENSE          RTF                    "../../resources/license.rtf"
+BMP_JAKARTA          BITMAP                 "../../resources/jakarta.bmp"
+
+#if 0 
+BMP_APMNUHDR         BITMAP                 "../../resources/apmnuhdr.bmp"
+#endif
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "prunmgr.manifest"
+
+IDD_ABOUTBOX DIALOGEX 0, 0, 337, 187
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "Apache Service Manager"
+FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
+BEGIN
+    DEFPUSHBUTTON   "&OK",IDOK,285,150,50,14
+    CONTROL         "",IDC_LICENSE,"RichEdit20A",ES_MULTILINE | 
+                    ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
+    CONTROL         "BMP_JAKARTA",IDC_STATIC,"Static",SS_BITMAP|0x00000040L,0,0,337,30
+    LTEXT           " ",IDC_ABOUTAPP,2,150,270,12
+    LTEXT           "Copyright � 2000-2003 The Apache Software Foundation.",IDC_STATIC,2,160,270,12
+    LTEXT           "http://www.jakarta.org",IDC_STATIC,2,170,270,12 
+    PUSHBUTTON      "&System Info",IAB_SYSINF,285,170,50,14
+END
+
+IDD_PROGRESS DIALOGEX 0, 0, 322, 92
+STYLE DS_SYSMODAL | DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | 
+    WS_CAPTION | WS_SYSMENU
+EXSTYLE WS_EX_TOPMOST
+CAPTION "Apache Service Manager"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    DEFPUSHBUTTON   "Cl&ose",IDOK,261,73,50,14
+    PUSHBUTTON      "&Cancel",IDCANCEL,202,73,50,14
+    LTEXT           " ",
+                    IDDP_HEAD,40,4,250,8
+    LTEXT           " ",IDDP_TEXT,40,15,250,44
+    CONTROL         "",IDDP_PROGRESS,"msctls_progress32",WS_BORDER,10,50,302,
+                    14
+    ICON            IDI_MAINICON,IDC_STATIC,10,4,20,20,0,WS_EX_TRANSPARENT
+END 
+
+IDD_SELUSER DIALOGEX 0, 0, 410, 201
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU |
+    WS_THICKFRAME
+EXSTYLE WS_EX_CONTEXTHELP
+CAPTION "Select User"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+    LTEXT           "Name:",IDSU_SELNAME,10,183,22,8
+    EDITTEXT        IDSU_SELECTED,48,200,213,14,ES_AUTOHSCROLL
+    DEFPUSHBUTTON   "OK",IDOK,292,180,50,14,WS_DISABLED
+    PUSHBUTTON      "Cancel",IDCANCEL,348,180,50,14
+    LTEXT           "Look In:",IDC_STATIC,10,9,27,8
+    CONTROL         "",IDSU_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | 
+                    LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | WS_BORDER | 
+                    WS_TABSTOP,0,26,410,149,WS_EX_CLIENTEDGE
+    CONTROL         "",IDSU_COMBO,"ComboBoxEx32",CBS_DROPDOWNLIST | 
+                    WS_VSCROLL | WS_TABSTOP,47,6,260,80
+END
+
+IDD_PROPPAGE_SGENERAL DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "Service Name: ",IDC_STATIC,10,8,52,8
+    LTEXT           "  ",IDC_PPSGNAME,70,8,240,8
+    LTEXT           "Display &name: ",IDC_STATIC,10,23,50,8
+    EDITTEXT        IDC_PPSGDISP,70,22,180,12,ES_AUTOHSCROLL
+    LTEXT           "&Description: ",IDC_STATIC,10,41,43,8
+    EDITTEXT        IDC_PPSGDESC,70,40,180,12,ES_AUTOHSCROLL
+    LTEXT           "Pat&h to executable:",IDC_STATIC,10,63,66,8
+    EDITTEXT        IDC_PPSGDEXE,10,75,240,12,ES_AUTOHSCROLL | WS_DISABLED
+    LTEXT           "Startup typ&e:",IDC_STATIC,10,94,46,8
+    COMBOBOX        IDC_PPSGCMBST,70,93,180,80,CBS_DROPDOWNLIST | WS_VSCROLL | 
+                    WS_TABSTOP
+    CONTROL         "",IDC_STATIC,"Static",SS_ETCHEDHORZ,10,128,240,1                    
+    LTEXT           "Service Status:",IDC_STATIC,10,138,52,8
+    LTEXT           "  ",IDC_PPSGSTATUS,70,138,240,8
+    PUSHBUTTON      "&Start",IDC_PPSGSTART,10,160,55,14,WS_DISABLED
+    PUSHBUTTON      "S&top",IDC_PPSGSTOP,71,160,55,14,WS_DISABLED
+    PUSHBUTTON      "&Pause",IDC_PPSGPAUSE,132,160,55,14,WS_DISABLED
+    PUSHBUTTON      "&Restart",IDC_PPSGRESTART,193,160,55,14,WS_DISABLED
+END
+
+IDD_PROPPAGE_LOGON DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "Log on as:",IDC_STATIC,10,8,51,8
+    CONTROL         "&Local System account",IDC_PPSLLS,"Button",
+                    BS_AUTORADIOBUTTON,10,23,85,10
+    CONTROL         "Allo&w service to interact with desktop",IDC_PPSLID,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,37,135,10
+    CONTROL         "&This account:",IDC_PPSLUA,"Button",BS_AUTORADIOBUTTON,
+                    10,59,61,10
+    EDITTEXT        IDC_PPSLUSER,86,58,114,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "&Browse...",IDC_PPSLBROWSE,205,57,50,14
+    LTEXT           "&Password:",IDL_PPSLPASS,21,76,36,8
+    EDITTEXT        IDC_PPSLPASS,86,75,114,12,ES_PASSWORD | ES_AUTOHSCROLL
+    LTEXT           "&Confirm Password:",IDL_PPSLCPASS,20,93,63,8
+    EDITTEXT        IDC_PPSLCPASS,86,92,114,12,ES_PASSWORD | ES_AUTOHSCROLL
+END
+
+IDD_PROPPAGE_LOGGING DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "&Level:",IDC_STATIC,10,18,46,8
+    COMBOBOX        IDC_PPLGLEVEL,70,17,180,80,CBS_DROPDOWNLIST | WS_VSCROLL | 
+                    WS_TABSTOP
+    LTEXT           "Log &path: ",IDC_STATIC,10,33,50,8
+    EDITTEXT        IDC_PPLGPATH,10,45,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPLGBPATH,232,44,18,14 
+    LTEXT           "Log prefix: ",IDC_STATIC,10,63,50,8
+    EDITTEXT        IDC_PPLGPREFIX,70,62,158,12,ES_AUTOHSCROLL
+    
+    LTEXT           "Redirect Stdout: ",IDC_STATIC,10,85,80,8
+    EDITTEXT        IDC_PPLGSTDOUT,10,97,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPLGBSTDOUT,232,96,18,14 
+    LTEXT           "Redirect Stderror: ",IDC_STATIC,10,115,80,8
+    EDITTEXT        IDC_PPLGSTDERR,10,127,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPLGBSTDERR,232,126,18,14 
+END
+
+IDD_PROPPAGE_JVM DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    CONTROL         " Use default",IDC_PPJAUTO,"Button",BS_AUTOCHECKBOX |
+                    WS_TABSTOP,10,8,72,12
+    LTEXT           "Java Virtual Machine: ",IDC_STATIC,10,23,80,8
+    EDITTEXT        IDC_PPJJVM,10,35,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPJBJVM,232,34,18,14 
+    LTEXT           "Java Classpath:",IDC_STATIC,10,53,66,8
+    EDITTEXT        IDC_PPJCLASSPATH,10,65,240,12,ES_AUTOHSCROLL
+    LTEXT           "Java Options:",IDC_STATIC,10,83,66,8
+    EDITTEXT        IDC_PPJOPTIONS,10,95,240,40,ES_MULTILINE | ES_AUTOHSCROLL | 
+                    ES_WANTRETURN | WS_VSCROLL
+    LTEXT           "Initial memory pool:",IDC_STATIC,10,140,80,8
+    EDITTEXT        IDC_PPJMS,90,139,100,12,ES_AUTOHSCROLL | ES_NUMBER
+    LTEXT           "MB",IDC_STATIC,195,140,25,8
+    LTEXT           "Maximum memory pool:",IDC_STATIC,10,156,80,8
+    EDITTEXT        IDC_PPJMX,90,155,100,12,ES_AUTOHSCROLL | ES_NUMBER
+    LTEXT           "MB",IDC_STATIC,195,156,25,8
+    LTEXT           "Thread stack size:",IDC_STATIC,10,172,80,8
+    EDITTEXT        IDC_PPJSS,90,171,100,12,ES_AUTOHSCROLL | ES_NUMBER
+    LTEXT           "KB",IDC_STATIC,195,172,25,8
+END
+
+IDD_PROPPAGE_START DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "&Class: ",IDC_STATIC,10,8,50,8
+    EDITTEXT        IDC_PPRCLASS,10,20,240,12,ES_AUTOHSCROLL
+    LTEXT           "Image: ",IDC_STATIC,10,38,80,8
+    EDITTEXT        IDC_PPRIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
+    PUSHBUTTON      "...",IDC_PPRBIMAGE,232,49,18,14,WS_DISABLED 
+    LTEXT           "Working Path: ",IDC_STATIC,10,68,80,8
+    EDITTEXT        IDC_PPRWPATH,10,80,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPRBWPATH,232,79,18,14
+    LTEXT           "&Method: ",IDC_STATIC,10,98,50,8
+    EDITTEXT        IDC_PPRMETHOD,70,97,180,12,ES_AUTOHSCROLL
+    LTEXT           "&Arguments: ",IDC_STATIC,10,115,50,8
+    EDITTEXT        IDC_PPRARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL | 
+                    ES_WANTRETURN | WS_VSCROLL
+    LTEXT           "&Timeout: ",IDC_STATIC,10,150,50,8
+    EDITTEXT        IDC_PPRTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | WS_DISABLED
+    LTEXT           "sec.",IDC_STATIC,175,150,25,8
+    LTEXT           "&Mode: ",IDC_STATIC,10,168,50,8
+    COMBOBOX        IDC_PPRMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL | 
+                    WS_TABSTOP
+END
+
+IDD_PROPPAGE_STOP DIALOGEX 0, 0, 260, 186
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    LTEXT           "&Class: ",IDC_STATIC,10,8,50,8
+    EDITTEXT        IDC_PPSCLASS,10,20,240,12,ES_AUTOHSCROLL
+    LTEXT           "Image: ",IDC_STATIC,10,38,80,8
+    EDITTEXT        IDC_PPSIMAGE,10,50,218,12,ES_AUTOHSCROLL | WS_DISABLED
+    PUSHBUTTON      "...",IDC_PPSBIMAGE,232,49,18,14,WS_DISABLED 
+    LTEXT           "Working Path: ",IDC_STATIC,10,68,80,8
+    EDITTEXT        IDC_PPSWPATH,10,80,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPSBWPATH,232,79,18,14 
+    LTEXT           "&Method: ",IDC_STATIC,10,98,50,8
+    EDITTEXT        IDC_PPSMETHOD,70,97,180,12,ES_AUTOHSCROLL
+    LTEXT           "&Arguments: ",IDC_STATIC,10,115,50,8
+    EDITTEXT        IDC_PPSARGS,70,114,180,30,ES_MULTILINE | ES_AUTOHSCROLL | 
+                    ES_WANTRETURN | WS_VSCROLL
+    LTEXT           "&Timeout: ",IDC_STATIC,10,150,50,8
+    EDITTEXT        IDC_PPSTIMEOUT,70,149,100,12,ES_AUTOHSCROLL | ES_NUMBER
+    LTEXT           "sec.",IDC_STATIC,175,150,25,8
+    LTEXT           "&Mode: ",IDC_STATIC,10,168,50,8
+    COMBOBOX        IDC_PPSMODE,70,167,180,80,CBS_DROPDOWNLIST | WS_VSCROLL | 
+                    WS_TABSTOP
+END
+
+STRINGTABLE 
+BEGIN
+    IDS_APPLICATION     RSTR_PSM
+    IDS_APPVERSION      "Version 1.0.0"
+    IDS_APPFULLNAME     RSTR_PSM " Version " PRG_VERSION
+    IDS_APPCOPYRIGHT    "Copyright � 2000-2004 The Apache Software Foundation"
+    IDS_APPDESCRIPTION  "Apache Procrun Service Management Tool"
+    IDS_ALREAY_RUNING   "An instance of '%S' application is already running"
+    IDS_ERRORCMD        "Unknown command line option '%s'\nSee the manual for command line usage."
+    IDS_HSSTART         RSTR_SCMATS "start the following service ..."
+    IDS_HSSTOP          RSTR_SCMATS "stop the following service ..."
+    IDS_HSRESTART       RSTR_SCMATS "to restart the following service ..."
+    IDS_HSPAUSE         RSTR_SCMATS "to pause the following service ..."
+    IDS_VALIDPASS       "Please enter a valid password"    
+    IDS_PPGENERAL       "General"
+    IDS_PPLOGON         "Log On"
+    IDS_PPLOGGING       "Logging"
+    IDS_PPJAVAVM        "Java"
+    IDS_PPSTART         "Startup"
+    IDS_PPSTOP          "Shutdown"
+    IDS_NOTIMPLEMENTED  "Sorry, but this feature is not implemented yet"         
+    IDS_LGPATHTITLE     "Select Log root folder"
+    IDS_ALLFILES        "All Files (*.*)\0*.*\0"
+    IDS_DLLFILES        "Dynamic Link Libraries (*.dll)\0*.dll\0"
+    IDS_EXEFILES        "Executables (*.exe)\0*.exe\0"
+    IDS_LGSTDOUT        "Select Stdoutput filename"
+    IDS_LGSTDERR        "Select Stderror filename"
+    IDS_PPJBJVM         "Select Java Virtual Machine DLL"    
+    IDS_PPWPATH         "Select Working path"    
+    IDS_PPIMAGE         "Select Executable Image"    
+    IDS_ERRSREG         "Unable to open the service registry key"
+END
+
+1 VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "040904b0"
+    BEGIN
+      VALUE "Comments", "Procrun Service Management Tool\0"
+      VALUE "CompanyName", "Apache Software Foundation\0"
+      VALUE "FileDescription", RSTR_PSM "\0"
+      VALUE "FileVersion", PRG_VERSION
+      VALUE "InternalName", RSTR_PSM "\0"
+      VALUE "LegalCopyright", "Copyright � 2000-2004 The Apache Software Foundation.\0"
+      VALUE "OriginalFilename", "prunmgr.exe\0"
+      VALUE "ProductName", RSTR_PSM "\0"
+      VALUE "ProductVersion", PRG_VERSION
+    END
+  END
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x409, 1200
+  END
+END
diff --git a/src/native/nt/procrun/apps/prunmgr/prunmgr.vcproj b/src/native/nt/procrun/apps/prunmgr/prunmgr.vcproj
new file mode 100644
index 0000000..cb5b5b5
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunmgr/prunmgr.vcproj
@@ -0,0 +1,244 @@
+<?xml version="1.0" encoding="windows-1250"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="prunmgr"
+	ProjectGUID="{98E56B10-BB3E-404A-A587-0FE95CFFB77B}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="..\..\obj\Debug"
+			IntermediateDirectory="..\..\obj\Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/prunmgrd.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/prunmgr.pdb"
+				SubSystem="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="..\..\obj\Release"
+			IntermediateDirectory="..\..\obj\Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				RuntimeLibrary="0"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/prunmgr.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug Unicode|Win32"
+			OutputDirectory="..\..\obj\$(ConfigurationName)"
+			IntermediateDirectory="..\..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_UNICODE;_WINDOWS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/prunmgrud.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/prunmgr.pdb"
+				SubSystem="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release Unicode|Win32"
+			OutputDirectory="..\..\obj\$(ConfigurationName)"
+			IntermediateDirectory="..\..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\;..\..\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_UNICODE;_WINDOWS"
+				RuntimeLibrary="0"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="shlwapi.lib comctl32.lib netapi32.lib"
+				OutputFile="../../bin/prunmgru.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\prunmgr.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\prunmgr.h">
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+			<File
+				RelativePath=".\prunmgr.rc">
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/apps/prunsrv/prunsrv.c b/src/native/nt/procrun/apps/prunsrv/prunsrv.c
new file mode 100644
index 0000000..72cc834
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunsrv/prunsrv.c
@@ -0,0 +1,1260 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* ====================================================================
+ * prunsrv -- Service Runner.
+ * Contributed by Mladen Turk <mturk at apache.org>
+ * 05 Aug 2003
+ * ==================================================================== 
+ */
+
+/* Force the JNI vprintf functions */
+#define _DEBUG_JNI  1
+#include "apxwin.h"
+#include "prunsrv.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <io.h>         /* _open_osfhandle */
+
+#define STDIN_FILENO  0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+typedef struct APX_STDWRAP {
+    LPCWSTR szLogPath;
+    LPCWSTR szStdOutFilename;
+    LPCWSTR szStdErrFilename;
+    HANDLE  hStdOutFile;
+    HANDLE  hStdErrFile;
+    FILE    *fpStdOutFile;
+    FILE    *fpStdErrFile;
+    FILE    fpStdOutSave;
+    FILE    fpStdErrSave;
+} APX_STDWRAP;
+
+/* Use static variables instead of #defines */
+static LPCWSTR      PRSRV_AUTO   = L"auto";
+static LPCWSTR      PRSRV_JAVA   = L"java";
+static LPCWSTR      PRSRV_JVM    = L"jvm";
+static LPCWSTR      PRSRV_MANUAL = L"manual";
+static LPCWSTR      PRSRV_JBIN   = L"\\bin\\java.exe";
+
+static LPWSTR       _service_name = NULL;
+/* Allowed procrun commands */
+static LPCWSTR _commands[] = {
+    L"TS",      /* 1 Run Service as console application (default)*/
+    L"RS",      /* 2 Run Service */
+    L"SS",      /* 3 Stop Service */
+    L"US",      /* 4 Update Service parameters */
+    L"IS",      /* 5 Install Service */
+    L"DS",      /* 6 Delete Service */
+    NULL
+};
+
+/* Allowed procrun parameters */
+static APXCMDLINEOPT _options[] = {
+
+/* 0  */    { L"Description",       L"Description",     NULL,           APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 1  */    { L"DisplayName",       L"DisplayName",     NULL,           APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 2  */    { L"Install",           L"ImagePath",       NULL,           APXCMDOPT_STE | APXCMDOPT_SRV, NULL, 0},
+/* 3  */    { L"Startup",           L"Startup",         NULL,           APXCMDOPT_STR | APXCMDOPT_SRV, NULL, 0},
+/* 4  */    { L"DependsOn",         L"DependsOn",       NULL,           APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 5  */    { L"Environment",       L"Environment",     NULL,           APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 6  */    { L"User",              L"User",            NULL,           APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 7  */    { L"Password",          L"Password",        NULL,           APXCMDOPT_BIN | APXCMDOPT_REG, NULL, 0},
+
+/* 8  */    { L"JavaHome",          L"JavaHome",        L"Java",        APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 9  */    { L"Jvm",               L"Jvm",             L"Java",        APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 10 */    { L"JvmOptions",        L"Options",         L"Java",        APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 11 */    { L"Classpath",         L"Classpath",       L"Java",        APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 12 */    { L"JvmMs",             L"JvmMs",           L"Java",        APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+/* 13 */    { L"JvmMx",             L"JvmMx",           L"Java",        APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+/* 14 */    { L"JvmSs",             L"JvmSs",           L"Java",        APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+
+/* 15 */    { L"StopImage",         L"Image",           L"Stop",        APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 16 */    { L"StopPath",          L"WorkingPath",     L"Stop",        APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 17 */    { L"StopClass",         L"Class",           L"Stop",        APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 18 */    { L"StopParams",        L"Params",          L"Stop",        APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 19 */    { L"StopMethod",        L"Method",          L"Stop",        APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 20 */    { L"StopMode",          L"Mode",            L"Stop",        APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 21 */    { L"StopTimeout",       L"Timeout",         L"Stop",        APXCMDOPT_INT | APXCMDOPT_REG, NULL, 0},
+
+/* 22 */    { L"StartImage",        L"Image",           L"Start",       APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 23 */    { L"StartPath",         L"WorkingPath",     L"Start",       APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 24 */    { L"StartClass",        L"Class",           L"Start",       APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 25 */    { L"StartParams",       L"Params",          L"Start",       APXCMDOPT_MSZ | APXCMDOPT_REG, NULL, 0},
+/* 26 */    { L"StartMethod",       L"Method",          L"Start",       APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 27 */    { L"StartMode",         L"Mode",            L"Start",       APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+
+/* 28 */    { L"LogPath",           L"Path",            L"Log",         APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 29 */    { L"LogPrefix",         L"Prefix",          L"Log",         APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 30 */    { L"LogLevel",          L"Level",           L"Log",         APXCMDOPT_STR | APXCMDOPT_REG, NULL, 0},
+/* 31 */    { L"StdError",          L"StdError",        L"Log",         APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+/* 32 */    { L"StdOutput",         L"StdOutput",       L"Log",         APXCMDOPT_STE | APXCMDOPT_REG, NULL, 0},
+            /* NULL terminate the array */
+            { NULL }
+};
+
+#define GET_OPT_V(x)  _options[x].szValue
+#define GET_OPT_I(x)  _options[x].dwValue
+#define GET_OPT_T(x)  _options[x].dwType
+
+#define ST_DESCRIPTION      GET_OPT_T(0)
+#define ST_DISPLAYNAME      GET_OPT_T(1)
+#define ST_INSTALL          GET_OPT_T(2)
+#define ST_STARTUP          GET_OPT_T(3)
+
+#define SO_DESCRIPTION      GET_OPT_V(0)
+#define SO_DISPLAYNAME      GET_OPT_V(1)
+#define SO_INSTALL          GET_OPT_V(2)
+#define SO_STARTUP          GET_OPT_V(3)
+#define SO_DEPENDSON        GET_OPT_V(4)
+#define SO_ENVIRONMENT      GET_OPT_V(5)
+
+#define SO_USER             GET_OPT_V(6)
+#define SO_PASSWORD         GET_OPT_V(7)
+
+#define SO_JAVAHOME         GET_OPT_V(8)
+#define SO_JVM              GET_OPT_V(9)
+#define SO_JVMOPTIONS       GET_OPT_V(10)
+#define SO_CLASSPATH        GET_OPT_V(11)
+#define SO_JVMMS            GET_OPT_I(12)
+#define SO_JVMMX            GET_OPT_I(13)
+#define SO_JVMSS            GET_OPT_I(14)
+
+#define SO_STOPIMAGE        GET_OPT_V(15)
+#define SO_STOPPATH         GET_OPT_V(16)
+#define SO_STOPCLASS        GET_OPT_V(17)
+#define SO_STOPPARAMS       GET_OPT_V(18)
+#define SO_STOPMETHOD       GET_OPT_V(19)
+#define SO_STOPMODE         GET_OPT_V(20)
+#define SO_STOPTIMEOUT      GET_OPT_I(21)
+
+#define SO_STARTIMAGE       GET_OPT_V(22)
+#define SO_STARTPATH        GET_OPT_V(23)
+#define SO_STARTCLASS       GET_OPT_V(24)
+#define SO_STARTPARAMS      GET_OPT_V(25)
+#define SO_STARTMETHOD      GET_OPT_V(26)
+#define SO_STARTMODE        GET_OPT_V(27)
+
+#define SO_LOGPATH          GET_OPT_V(28)
+#define SO_LOGPREFIX        GET_OPT_V(29)
+#define SO_LOGLEVEL         GET_OPT_V(30)
+
+#define SO_STDERROR         GET_OPT_V(31)
+#define SO_STDOUTPUT        GET_OPT_V(32)
+
+/* Main servic table entry
+ * filled at run-time
+ */
+static SERVICE_TABLE_ENTRYW _service_table[] = {
+        {NULL, NULL},
+        {NULL, NULL}
+};
+ 
+static SERVICE_STATUS        _service_status; 
+static SERVICE_STATUS_HANDLE _service_status_handle = NULL; 
+/* Set if launched by SCM   */
+static BOOL                  _service_mode = FALSE;
+/* JVM used as worker       */
+static BOOL                  _jni_startup  = FALSE;
+/* JVM used for shutdown    */
+static BOOL                  _jni_shutdown = FALSE;
+/* Global variables and objects */
+static APXHANDLE    gPool;
+static APXHANDLE    gWorker;
+static APX_STDWRAP  gStdwrap;           /* stdio/stderr redirection */
+
+static LPWSTR _jni_jvmpath              = NULL;   /* Path to jvm dll */
+static LPSTR  _jni_jvmoptions           = NULL;   /* Path to jvm options */
+
+static LPSTR  _jni_classpath            = NULL;
+static LPSTR  _jni_rparam               = NULL;    /* Startup  arguments */
+static LPSTR  _jni_sparam               = NULL;    /* Shutdown arguments */
+static LPSTR  _jni_rmethod              = NULL;    /* Startup  arguments */
+static LPSTR  _jni_smethod              = NULL;    /* Shutdown arguments */
+static CHAR   _jni_rclass[SIZ_RESLEN]   = {'\0'};  /* Startup  class */
+static CHAR   _jni_sclass[SIZ_RESLEN]   = {'\0'};  /* Shutdown class */
+
+static HANDLE gShutdownEvent = NULL;
+/* redirect console stdout/stderr to files 
+ * so that java messages can get logged
+ * If stderrfile is not specified it will
+ * go to stdoutfile.
+ */
+
+
+
+static BOOL redirectStdStreams(APX_STDWRAP *lpWrapper)
+{
+    BOOL aErr = FALSE;
+    BOOL aOut = FALSE;
+
+    /* Clear up the handles */    
+    lpWrapper->fpStdErrFile = NULL;
+    lpWrapper->fpStdOutFile = NULL;
+    
+    /* Save the original streams */
+    lpWrapper->fpStdOutSave = *stdout;
+    lpWrapper->fpStdErrSave = *stderr;
+
+    /* redirect to file or console */
+    if (lpWrapper->szStdOutFilename) {
+        if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
+            aOut = TRUE;
+            lpWrapper->szStdOutFilename = apxLogFile(gPool,
+                                                     lpWrapper->szLogPath,
+                                                     NULL,
+                                                     L"stdout_");
+        }
+        /* Delete the file if not in append mode
+         * XXX: See if we can use the params instead of that.
+         */
+        if (!aOut)
+            DeleteFileW(lpWrapper->szStdOutFilename);
+        lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
+                                             GENERIC_WRITE | GENERIC_READ,
+                                             FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                             NULL,
+                                             OPEN_ALWAYS,
+                                             FILE_ATTRIBUTE_NORMAL,
+                                             NULL);
+        if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
+            return FALSE;
+        /* Allways move to the end of file */
+        SetFilePointer(lpWrapper->hStdOutFile, 0, NULL, FILE_END);
+    }
+    else {
+        lpWrapper->hStdOutFile = CreateFileW(L"CONOUT$",
+                                             GENERIC_READ | GENERIC_WRITE, 
+                                             FILE_SHARE_READ | FILE_SHARE_WRITE, 
+                                             NULL,
+                                             OPEN_EXISTING,
+                                             0,
+                                             NULL); 
+        if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
+            return FALSE;
+    }
+    if (lpWrapper->szStdErrFilename) {
+        if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
+            aErr = TRUE;
+            lpWrapper->szStdErrFilename = apxLogFile(gPool,
+                                                     lpWrapper->szLogPath,
+                                                     NULL,
+                                                     L"stderr_");
+        }
+        if (!aErr)
+            DeleteFileW(lpWrapper->szStdErrFilename);
+        lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
+                                             GENERIC_WRITE | GENERIC_READ,
+                                             FILE_SHARE_READ | FILE_SHARE_WRITE,
+                                             NULL,
+                                             OPEN_ALWAYS,
+                                             FILE_ATTRIBUTE_NORMAL,
+                                             NULL);
+        if (IS_INVALID_HANDLE(lpWrapper->hStdErrFile))
+            return FALSE;
+        SetFilePointer(lpWrapper->hStdErrFile, 0, NULL, FILE_END);
+    }
+    else if (lpWrapper->szStdOutFilename) {
+        /* Use the same file handle for stderr as for stdout */
+        lpWrapper->szStdErrFilename = lpWrapper->szStdOutFilename;
+        lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
+    }
+    else {
+        lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
+    }
+    /* Open the stream buffers 
+     * This will redirect all printf to go to the redirected files.
+     * It is used for JNI vprintf functionality.
+     */
+    lpWrapper->fpStdOutFile = _fdopen(_open_osfhandle(
+                                      (intptr_t)lpWrapper->hStdOutFile,
+                                      _O_TEXT), "w");
+    lpWrapper->fpStdErrFile = _fdopen(_open_osfhandle(
+                                      (intptr_t)lpWrapper->hStdErrFile,
+                                      _O_TEXT), "w");
+    if (lpWrapper->fpStdOutFile) {
+        *stdout = *lpWrapper->fpStdOutFile;
+        setvbuf(stdout, NULL, _IONBF, 0);
+    }
+    if (lpWrapper->fpStdErrFile) {
+        *stderr = *lpWrapper->fpStdErrFile;
+        setvbuf(stderr, NULL, _IONBF, 0);
+    }
+    return TRUE;
+}
+
+static void cleanupStdStreams(APX_STDWRAP *lpWrapper)
+{
+    /* Close the redirectied streams */
+    if (lpWrapper->fpStdOutFile) {
+        fclose(lpWrapper->fpStdOutFile);
+        *stdout = lpWrapper->fpStdOutSave;
+    }
+    if (lpWrapper->fpStdErrFile) {
+        fclose(lpWrapper->fpStdErrFile);
+        *stderr = lpWrapper->fpStdErrSave;
+    }
+}
+
+/* Debuging functions */
+static void printUsage(LPAPXCMDLINE lpCmdline)
+{
+#ifdef _DEBUG
+    int i = 0;
+    fwprintf(stderr, L"Usage: %s //CMD//Servce [--options]\n",
+             lpCmdline->szExecutable);
+    fwprintf(stderr, L"  Commands:\n");
+    fwprintf(stderr, L"  //IS//ServiceName  Install Service\n");
+    fwprintf(stderr, L"  //US//ServiceName  Update Service parameters\n");
+    fwprintf(stderr, L"  //DS//ServiceName  Delete Service\n");
+    fwprintf(stderr, L"  //RS//ServiceName  Run Service\n");
+    fwprintf(stderr, L"  //SS//ServiceName  Stop Service\n");
+    fwprintf(stderr,
+             L"  //TS//ServiceName  Run Service as console application\n");
+    fwprintf(stderr, L"  Options:\n");
+    while (_options[i].szName) {
+        fwprintf(stderr, L"  --%s\n", _options[i].szName);
+        ++i;
+    }
+#endif
+}
+/* Display configuration parameters */
+static void dumpCmdline()
+{
+    int i = 0;
+    while (_options[i].szName) {
+        if (_options[i].dwType & APXCMDOPT_INT)
+            fwprintf(stderr, L"--%-16s %d\n", _options[i].szName,
+                     _options[i].dwValue);
+        else if (_options[i].szValue)
+            fwprintf(stderr, L"--%-16s %s\n", _options[i].szName,
+                     _options[i].szValue);
+        else
+            fwprintf(stderr, L"--%-16s <NULL>\n", _options[i].szName);
+        ++i;
+    }
+}
+
+static void setInprocEnvironment()
+{
+    LPWSTR p, e;
+
+    if (!SO_ENVIRONMENT)
+        return;    /* Nothing to do */
+    
+    for (p = SO_ENVIRONMENT; *p; p++) {
+        e = apxExpandStrW(gPool, p);
+        _wputenv(e);
+        apxFree(e);
+        while (*p)
+            p++;
+    }
+}
+
+/* Load the configuration from Registry
+ * loads only nonspecified items
+ */
+static BOOL loadConfiguration(LPAPXCMDLINE lpCmdline)
+{
+    APXHANDLE hRegistry;
+    int i = 0;
+
+    SetLastError(ERROR_SUCCESS);
+    hRegistry = apxCreateRegistryW(gPool, KEY_READ, PRG_REGROOT,
+                                   lpCmdline->szApplication,
+                                   APXREG_SOFTWARE | APXREG_SERVICE);
+    if (IS_INVALID_HANDLE(hRegistry)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return FALSE;
+    }
+    /* browse through options */
+    while (_options[i].szName) {
+        DWORD dwFrom;
+
+        dwFrom = (_options[i].dwType & APXCMDOPT_REG) ? APXREG_PARAMSOFTWARE : APXREG_SERVICE;
+        if (!(_options[i].dwType & APXCMDOPT_FOUND)) {
+            if (_options[i].dwType & APXCMDOPT_STR) {
+                _options[i].szValue = apxRegistryGetStringW(hRegistry,
+                                                            dwFrom,
+                                                            _options[i].szSubkey,
+                                                            _options[i].szRegistry);
+                /* Expand environment variables */
+                if (_options[i].szValue && (_options[i].dwType & APXCMDOPT_STE)) {
+                    LPWSTR exp = apxExpandStrW(gPool, _options[i].szValue);
+                    if (exp != _options[i].szValue)
+                        apxFree(_options[i].szValue);
+                    _options[i].szValue = exp;
+                }
+            }
+            else if (_options[i].dwType & APXCMDOPT_INT) {
+                _options[i].dwValue = apxRegistryGetNumberW(hRegistry,
+                                                            dwFrom,
+                                                            _options[i].szSubkey,
+                                                            _options[i].szRegistry);
+            }
+            else if (_options[i].dwType & APXCMDOPT_MSZ) {
+                _options[i].szValue = apxRegistryGetMzStrW(hRegistry,
+                                                           dwFrom,
+                                                           _options[i].szSubkey,
+                                                           _options[i].szRegistry,
+                                                           NULL,
+                                                           &(_options[i].dwValue));
+            }
+        }
+        /* Merge the command line options with registry */
+        else if (_options[i].dwType & APXCMDOPT_ADD) {
+            LPWSTR cv = _options[i].szValue;
+            LPWSTR ov = NULL;
+            if (_options[i].dwType & APXCMDOPT_MSZ) {
+                ov = apxRegistryGetMzStrW(hRegistry, dwFrom,
+                                          _options[i].szSubkey,
+                                          _options[i].szRegistry,
+                                          NULL,
+                                          &(_options[i].dwValue));
+                _options[i].szValue = apxMultiSzCombine(gPool, ov, cv,
+                                                        &(_options[i].dwValue));
+                if (ov)
+                    apxFree(ov);
+            }
+        }
+        ++i;
+    }
+    apxCloseHandle(hRegistry);
+#ifdef _DEBUG    
+    dumpCmdline();
+#endif
+    return TRUE;
+}
+
+/* Save changed configuration to registry
+ */
+static BOOL saveConfiguration(LPAPXCMDLINE lpCmdline)
+{
+    APXHANDLE hRegistry;
+    int i = 0;
+    hRegistry = apxCreateRegistryW(gPool, KEY_WRITE, PRG_REGROOT,
+                                   lpCmdline->szApplication,
+                                   APXREG_SOFTWARE | APXREG_SERVICE);
+    if (IS_INVALID_HANDLE(hRegistry))
+        return FALSE;
+    /* TODO: Use array size */
+    while (_options[i].szName) {
+        /* Skip the service params */
+        if ((_options[i].dwType & APXCMDOPT_SRV) ||
+            !(_options[i].dwType & APXCMDOPT_FOUND)) {
+                /* Skip non-modified version */
+        }
+        /* Update only modified params */
+        else if (_options[i].dwType & APXCMDOPT_STR)
+            apxRegistrySetStrW(hRegistry, APXREG_PARAMSOFTWARE,
+                               _options[i].szSubkey,
+                               _options[i].szRegistry,
+                               _options[i].szValue);
+        else if (_options[i].dwType & APXCMDOPT_INT)
+            apxRegistrySetNumW(hRegistry, APXREG_PARAMSOFTWARE,
+                               _options[i].szSubkey,
+                               _options[i].szRegistry,
+                               _options[i].dwValue);
+        else if (_options[i].dwType & APXCMDOPT_MSZ)
+            apxRegistrySetMzStrW(hRegistry, APXREG_PARAMSOFTWARE,
+                                 _options[i].szSubkey,
+                                 _options[i].szRegistry,
+                                 _options[i].szValue,
+                                 _options[i].dwValue);
+        ++i;
+    }
+    apxCloseHandle(hRegistry);
+    return TRUE;
+}
+
+/* Operations */
+static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
+{
+    APXHANDLE hService;
+    BOOL  rv;
+    DWORD dwStart = SERVICE_DEMAND_START;
+    WCHAR szImage[SIZ_HUGLEN];
+    
+    apxLogWrite(APXLOG_MARK_DEBUG "Installing service...");
+    hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
+    if (IS_INVALID_HANDLE(hService)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+        return FALSE;
+    }
+    /* Check the startup mode */
+    if ((ST_STARTUP & APXCMDOPT_FOUND) &&
+        lstrcmpiW(SO_STARTUP, PRSRV_AUTO) == 0)
+        dwStart = SERVICE_AUTO_START;
+    /* Check if --Install is provided */
+    if (!SO_INSTALL) {
+        lstrcpyW(szImage, lpCmdline->szExePath);
+        lstrcatW(szImage, L"\\");
+        lstrcatW(szImage, lpCmdline->szExecutable);
+        lstrcatW(szImage, L".exe");
+    }
+    else
+        lstrcpyW(szImage, SO_INSTALL);
+    /* Replace not needed qoutes */
+    apxStrQuoteInplaceW(szImage);
+    /* Add run-service command line option */
+    lstrcatW(szImage, L" //RS//");
+    lstrcatW(szImage, lpCmdline->szApplication);
+    SO_INSTALL = apxPoolStrdupW(gPool, szImage);
+    /* Ensure that option gets saved in the registry */
+    ST_INSTALL |= APXCMDOPT_FOUND;
+#ifdef _DEBUG
+    /* Display configured options */
+    dumpCmdline();
+#endif
+    apxLogWrite(APXLOG_MARK_INFO "Service %S name %S", lpCmdline->szApplication, 
+                SO_DISPLAYNAME);
+    rv = apxServiceInstall(hService, 
+                          lpCmdline->szApplication,
+                          SO_DISPLAYNAME,    /* --DisplayName  */
+                          SO_INSTALL,    
+                          SO_DEPENDSON,      /* --DependendsOn */
+                          SERVICE_WIN32_OWN_PROCESS,
+                          dwStart);
+    /* Set the --Description */
+    if (rv && (ST_DESCRIPTION & APXCMDOPT_FOUND)) {
+        apxLogWrite(APXLOG_MARK_DEBUG "Setting service description %S",
+                    SO_DESCRIPTION);
+        apxServiceSetNames(hService, NULL, NULL, SO_DESCRIPTION,
+                           NULL, NULL);
+    }
+    apxCloseHandle(hService);
+    if (rv) {
+        saveConfiguration(lpCmdline);
+        apxLogWrite(APXLOG_MARK_INFO "Service %S installed",
+                    lpCmdline->szApplication);
+    }
+    else
+        apxLogWrite(APXLOG_MARK_ERROR "Failed installing %S service",
+                    lpCmdline->szApplication);
+
+    return rv;
+}
+
+static BOOL docmdDeleteService(LPAPXCMDLINE lpCmdline)
+{
+    APXHANDLE hService;
+    BOOL  rv = FALSE;
+
+    apxLogWrite(APXLOG_MARK_INFO "Deleting service...");
+    hService = apxCreateService(gPool, SC_MANAGER_CONNECT, FALSE);
+    if (IS_INVALID_HANDLE(hService)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+        return FALSE;
+    }
+    /* Delete service will stop the service if running */
+    if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+        WCHAR szWndManagerClass[SIZ_RESLEN];
+        HANDLE hWndManager = NULL;
+        lstrcpyW(szWndManagerClass, lpCmdline->szApplication);
+        lstrcatW(szWndManagerClass, L"_CLASS");
+        /* Close the monitor application if running */
+        if ((hWndManager = FindWindowW(szWndManagerClass, NULL)) != NULL) {
+            SendMessage(hWndManager, WM_CLOSE, 0, 0);
+        }
+        rv = apxServiceDelete(hService);
+    }
+    if (rv) {
+        /* Delete all service registry settings */
+        apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, TRUE);
+        apxLogWrite(APXLOG_MARK_DEBUG "Service %S deleted",
+                    lpCmdline->szApplication);
+    }
+    else {
+        apxDisplayError(TRUE, NULL, 0, "Unable to delete %S service",
+                        lpCmdline->szApplication);
+    }
+    apxCloseHandle(hService);
+    apxLogWrite(APXLOG_MARK_INFO "Delete service finished.");
+    return rv;
+}
+
+static BOOL docmdStopService(LPAPXCMDLINE lpCmdline)
+{
+    APXHANDLE hService;
+    BOOL  rv = FALSE;
+
+    apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+    hService = apxCreateService(gPool, GENERIC_ALL, FALSE);
+    if (IS_INVALID_HANDLE(hService)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+        return FALSE;
+    }
+
+    SetLastError(ERROR_SUCCESS);
+    /* Open the service */
+    if (apxServiceOpen(hService, lpCmdline->szApplication,
+                       GENERIC_READ | GENERIC_EXECUTE)) {
+        rv = apxServiceControl(hService,
+                               SERVICE_CONTROL_STOP,
+                               0,
+                               NULL,
+                               NULL);
+        if (rv)
+            apxLogWrite(APXLOG_MARK_INFO "Service %S stopped",
+                        lpCmdline->szApplication);
+        else
+            apxLogWrite(APXLOG_MARK_ERROR "Failed to stop %S service",
+                        lpCmdline->szApplication);
+
+    }
+    else
+        apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
+                        lpCmdline->szApplication);
+    apxCloseHandle(hService);
+    apxLogWrite(APXLOG_MARK_INFO "Stop service finished.");
+    return rv;
+}
+
+static BOOL docmdUpdateService(LPAPXCMDLINE lpCmdline)
+{
+    APXHANDLE hService;
+    BOOL  rv = FALSE;
+
+    apxLogWrite(APXLOG_MARK_INFO "Updating service...");
+
+    hService = apxCreateService(gPool, SC_MANAGER_CREATE_SERVICE, FALSE);
+    if (IS_INVALID_HANDLE(hService)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Unable to open the Service Manager");
+        return FALSE;
+    }
+    SetLastError(0);
+    /* Open the service */
+    if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
+        apxServiceSetNames(hService,
+                           NULL,                /* Never update the ImagePath */
+                           SO_DISPLAYNAME,
+                           SO_DESCRIPTION,
+                           NULL,
+                           NULL);
+        /* Update the --Startup mode */
+        if (ST_STARTUP & APXCMDOPT_FOUND) {
+            DWORD dwStart = SERVICE_NO_CHANGE;
+            if (!lstrcmpiW(SO_STARTUP, PRSRV_AUTO))
+                dwStart = SERVICE_AUTO_START;
+            else if (!lstrcmpiW(SO_STARTUP, PRSRV_MANUAL))
+                dwStart = SERVICE_DEMAND_START;
+            apxServiceSetOptions(hService,
+                                 SERVICE_NO_CHANGE,
+                                 dwStart,
+                                 SERVICE_NO_CHANGE);
+    
+        }
+        apxLogWrite(APXLOG_MARK_INFO "Service %S updated",
+                    lpCmdline->szApplication);
+
+        saveConfiguration(lpCmdline);
+    }
+    else
+        apxDisplayError(TRUE, NULL, 0, "Unable to open %S service",
+                        lpCmdline->szApplication);
+    apxCloseHandle(hService);
+    apxLogWrite(APXLOG_MARK_INFO "Update service finished.");
+    return rv;
+}
+
+
+/* Report the service status to the SCM
+ */
+int reportServiceStatus(DWORD dwCurrentState,
+                        DWORD dwWin32ExitCode,
+                        DWORD dwWaitHint)
+{
+   static DWORD dwCheckPoint = 1;
+   BOOL fResult = TRUE;
+
+   if (_service_mode && _service_status_handle) {      
+       if (dwCurrentState == SERVICE_START_PENDING)
+            _service_status.dwControlsAccepted = 0;
+        else
+            _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+
+       _service_status.dwCurrentState  = dwCurrentState;
+       _service_status.dwWin32ExitCode = dwWin32ExitCode;
+       _service_status.dwWaitHint      = dwWaitHint;
+
+       if ((dwCurrentState == SERVICE_RUNNING) ||
+           (dwCurrentState == SERVICE_STOPPED))
+           _service_status.dwCheckPoint = 0;
+       else
+           _service_status.dwCheckPoint = dwCheckPoint++;
+       fResult = SetServiceStatus(_service_status_handle, &_service_status);
+       if (!fResult) {
+           /* TODO: Deal with error */
+       }
+   }
+   return fResult;
+}
+
+
+BOOL child_callback(APXHANDLE hObject, UINT uMsg,
+                    WPARAM wParam, LPARAM lParam)
+{
+    /* TODO: Make stdout and stderr buffers
+     * to prevent streams intermixing when there
+     * is no separate file for each stream
+     */
+    if (uMsg == WM_CHAR) {
+        int ch = LOWORD(wParam);
+        if (lParam)
+            fputc(ch, stderr);
+        else
+            fputc(ch, stdout);
+    }
+    return TRUE;
+}
+
+/* Executed when the service receives stop event */
+static DWORD serviceStop()
+{
+    APXHANDLE hWorker = NULL;
+    DWORD  rv = 0;
+    BOOL   wait_to_die = FALSE;
+    DWORD  timeout     = SO_STOPTIMEOUT * 1000;
+
+    apxLogWrite(APXLOG_MARK_INFO "Stopping service...");
+
+    if (IS_INVALID_HANDLE(gWorker)) {
+        apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
+        return TRUE;    /* Nothing to do */
+    }
+    if (_jni_shutdown) {
+        if (!SO_STARTPATH && SO_STOPPATH) {
+            /* If the Working path is specified change the current directory 
+             * but only if the start path wasn't specified already.
+             */
+            SetCurrentDirectoryW(SO_STARTPATH);
+        }
+        hWorker = apxCreateJava(gPool, _jni_jvmpath);
+        if (IS_INVALID_HANDLE(hWorker)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
+            return 1;
+        }
+        if (!apxJavaInitialize(hWorker, _jni_classpath, _jni_jvmoptions,
+                               SO_JVMMS, SO_JVMMX, SO_JVMSS, TRUE)) {
+            rv = 2;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
+            goto cleanup;
+        }
+        if (!apxJavaLoadMainClass(hWorker, _jni_sclass, _jni_smethod, _jni_sparam)) {
+            rv = 2;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s",
+                        _jni_rclass, _jni_classpath);
+            goto cleanup;
+        }
+        /* Create sutdown event */
+        gShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+        if (!apxJavaStart(hWorker)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed starting java");
+            rv = 3;
+        }
+        else {
+            apxLogWrite(APXLOG_MARK_DEBUG "Waiting for java jni stop worker to finish...");
+            apxJavaWait(hWorker, INFINITE, FALSE);        
+            apxLogWrite(APXLOG_MARK_DEBUG "Java jni stop worker finished.");
+        }
+        wait_to_die = TRUE;
+    } 
+    else if (SO_STOPMODE) { /* Only in case we have a stop mode */
+        DWORD nArgs;
+        LPWSTR *pArgs;
+        /* Redirect process */
+        hWorker = apxCreateProcessW(gPool, 
+                                    0,
+                                    child_callback,
+                                    SO_USER,
+                                    SO_PASSWORD,
+                                    FALSE);
+        if (IS_INVALID_HANDLE(hWorker)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
+            return 1;
+        }
+        if (!apxProcessSetExecutableW(hWorker, SO_STOPIMAGE)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
+                        SO_STARTIMAGE);
+            rv = 2;
+            goto cleanup;
+        }
+        /* Assemble the command line */
+        nArgs = apxMultiSzToArrayW(gPool, SO_STOPPARAMS, &pArgs);
+        /* Pass the argv to child process */
+        if (!apxProcessSetCommandArgsW(hWorker, SO_STOPIMAGE,
+                                       nArgs, pArgs)) {
+            rv = 3;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
+                        nArgs);
+            goto cleanup;
+        }
+        /* Set the working path */
+        if (!apxProcessSetWorkingPathW(hWorker, SO_STOPPATH)) {
+            rv = 4;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
+                        SO_STOPPATH);
+            goto cleanup;
+        }
+        /* Finally execute the child process 
+         */
+        if (!apxProcessExecute(hWorker)) {
+            rv = 5;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
+            goto cleanup;
+        } else {
+            apxLogWrite(APXLOG_MARK_DEBUG "Waiting stop worker to finish...");
+            apxHandleWait(hWorker, INFINITE, FALSE);        
+            apxLogWrite(APXLOG_MARK_DEBUG "Stop worker finished.");
+        }
+        wait_to_die = TRUE;
+    }
+cleanup:
+    /* Close Java JNI handle or stop worker
+     * If this is the single JVM instance it will unload
+     * the JVM dll too.
+     * The worker will be closed on service exit.
+     */
+    if (!IS_INVALID_HANDLE(hWorker))
+        apxCloseHandle(hWorker);
+    SetEvent(gShutdownEvent);
+    if (timeout > 0x7FFFFFFF)
+        timeout = INFINITE;     /* If the timeout was '-1' wait forewer */ 
+    if (wait_to_die && !timeout)
+        timeout = 300 * 1000;   /* Use the 5 minute default shutdown */
+
+    if (timeout) {  
+        FILETIME fts, fte;
+        ULARGE_INTEGER s, e;
+        DWORD    nms;
+        /* Wait to give it a chance to die naturally, then kill it. */
+        apxLogWrite(APXLOG_MARK_DEBUG "Waiting for worker to die naturally...");
+        GetSystemTimeAsFileTime(&fts);
+        rv = apxHandleWait(gWorker, timeout, TRUE);
+        GetSystemTimeAsFileTime(&fte);
+        s.LowPart  = fts.dwLowDateTime;
+        s.HighPart = fts.dwHighDateTime;
+        e.LowPart  = fte.dwLowDateTime;
+        e.HighPart = fte.dwHighDateTime;
+        nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
+        if (rv == WAIT_OBJECT_0) {
+            rv = 0;
+            apxLogWrite(APXLOG_MARK_DEBUG "Worker finished gracefully in %d ms.", nms);
+        }
+        else
+            apxLogWrite(APXLOG_MARK_DEBUG "Worker was killed in %d ms.", nms);
+    }
+    else {
+        apxLogWrite(APXLOG_MARK_DEBUG "Sending WM_CLOSE to worker");
+        apxHandleSendMessage(gWorker, WM_CLOSE, 0, 0);
+    }
+
+    apxLogWrite(APXLOG_MARK_INFO "Service stopped.");
+    return rv;
+}
+
+/* Executed when the service receives start event */
+static DWORD serviceStart()
+{
+    DWORD  rv = 0;
+    DWORD  nArgs;
+    LPWSTR *pArgs;
+    FILETIME fts;
+
+    apxLogWrite(APXLOG_MARK_INFO "Starting service...");
+
+    if (!IS_INVALID_HANDLE(gWorker)) {
+        apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
+        return TRUE;    /* Nothing to do */
+    }
+    GetSystemTimeAsFileTime(&fts);
+    if (_jni_startup) {
+        if (SO_STARTPATH) {
+            /* If the Working path is specified change the current directory */
+            SetCurrentDirectoryW(SO_STARTPATH);
+        }
+        /* Set the environment using putenv, so JVM can use it */
+        setInprocEnvironment();
+        /* Create the JVM glbal worker */
+        gWorker = apxCreateJava(gPool, _jni_jvmpath);
+        if (IS_INVALID_HANDLE(gWorker)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed creating java %S", _jni_jvmpath);
+            return 1;
+        }
+        if (!apxJavaInitialize(gWorker, _jni_classpath, _jni_jvmoptions,
+                               SO_JVMMS, SO_JVMMX, SO_JVMSS, _service_mode)) {
+            rv = 2;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
+            goto cleanup;
+        }
+        if (!apxJavaLoadMainClass(gWorker, _jni_rclass, _jni_rmethod, _jni_rparam)) {
+            rv = 3;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed loading main %s class %s", _jni_rclass, _jni_classpath);
+            goto cleanup;
+        }
+        apxJavaSetOut(gWorker, TRUE,  gStdwrap.szStdErrFilename);
+        apxJavaSetOut(gWorker, FALSE, gStdwrap.szStdOutFilename);
+        if (!apxJavaStart(gWorker)) {
+            rv = 4;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed starting Java");
+            goto cleanup;
+        }
+        apxLogWrite(APXLOG_MARK_DEBUG "Java started %s", _jni_rclass);
+    }
+    else {
+        /* Redirect process */
+        gWorker = apxCreateProcessW(gPool, 
+                                    0,
+                                    child_callback,
+                                    SO_USER,
+                                    SO_PASSWORD,
+                                    FALSE);
+        if (IS_INVALID_HANDLE(gWorker)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed creating process");
+            return 1;
+        }
+        if (!apxProcessSetExecutableW(gWorker, SO_STARTIMAGE)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed setting process executable %S",
+                        SO_STARTIMAGE);
+            rv = 2;
+            goto cleanup;
+        }
+        /* Assemble the command line */
+        nArgs = apxMultiSzToArrayW(gPool, SO_STARTPARAMS, &pArgs);
+        /* Pass the argv to child process */
+        if (!apxProcessSetCommandArgsW(gWorker, SO_STARTIMAGE,
+                                       nArgs, pArgs)) {
+            rv = 3;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed setting process arguments (argc=%d)",
+                        nArgs);
+            goto cleanup;
+        }
+        /* Set the working path */
+        if (!apxProcessSetWorkingPathW(gWorker, SO_STARTPATH)) {
+            rv = 4;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed setting process working path to %S",
+                        SO_STARTPATH);
+            goto cleanup;
+        }
+        /* Finally execute the child process 
+         */
+        if (!apxProcessExecute(gWorker)) {
+            rv = 5;
+            apxLogWrite(APXLOG_MARK_ERROR "Failed executing process");
+            goto cleanup;
+        }
+    }
+    if (rv == 0) {
+        FILETIME fte;
+        ULARGE_INTEGER s, e;
+        DWORD    nms;
+        GetSystemTimeAsFileTime(&fte);
+        s.LowPart  = fts.dwLowDateTime;
+        s.HighPart = fts.dwHighDateTime;
+        e.LowPart  = fte.dwLowDateTime;
+        e.HighPart = fte.dwHighDateTime;
+        nms = (DWORD)((e.QuadPart - s.QuadPart) / 10000);
+        apxLogWrite(APXLOG_MARK_INFO "Service started in %d ms.", nms);
+    }
+    return rv;
+cleanup:
+    if (!IS_INVALID_HANDLE(gWorker))
+        apxCloseHandle(gWorker);    /* Close the worker handle */
+    gWorker = NULL;
+    return rv;    
+}
+
+/* Service controll handler
+ */
+void WINAPI service_ctrl_handler(DWORD dwCtrlCode)
+{
+    switch (dwCtrlCode) {
+        case SERVICE_CONTROL_STOP:
+            apxLogWrite(APXLOG_MARK_INFO "Service STOP signaled");
+            reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+            /* Call the stop handler that will actualy stop the service */
+            serviceStop();
+            return;
+        case SERVICE_CONTROL_INTERROGATE:
+        break;
+        default:
+        break;
+   }
+   reportServiceStatus(_service_status.dwCurrentState, NO_ERROR, 0);
+}
+
+/* Console control handler
+ * 
+ */
+BOOL WINAPI console_handler(DWORD dwCtrlType)
+{
+    switch (dwCtrlType) {
+        case CTRL_BREAK_EVENT:
+            apxLogWrite(APXLOG_MARK_INFO "Console CTRL+BREAK event signaled");
+            if (_service_mode) {
+                serviceStop();
+                return TRUE;
+            }
+            else
+                return FALSE;
+        case CTRL_C_EVENT:
+            apxLogWrite(APXLOG_MARK_INFO "Console CTRL+C event signaled");
+            serviceStop();
+            return TRUE;
+        case CTRL_CLOSE_EVENT:
+            apxLogWrite(APXLOG_MARK_INFO "Console CTRL+CLOSE event signaled");
+            serviceStop();
+            return TRUE;
+        case CTRL_SHUTDOWN_EVENT:
+            apxLogWrite(APXLOG_MARK_INFO "Console SHUTDOWN event signaled");
+            serviceStop();
+            return TRUE;
+        break;
+
+   }
+   return FALSE;
+}
+
+/* Main service execution loop */
+void WINAPI serviceMain(DWORD argc, LPTSTR *argv)
+{
+    DWORD rc;
+    _service_status.dwServiceType      = SERVICE_WIN32_OWN_PROCESS;
+    _service_status.dwCurrentState     = SERVICE_START_PENDING; 
+    _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
+                                         SERVICE_ACCEPT_PAUSE_CONTINUE; 
+    _service_status.dwWin32ExitCode    = 0; 
+    _service_status.dwCheckPoint       = 0; 
+    _service_status.dwWaitHint         = 0; 
+    _service_status.dwServiceSpecificExitCode = 0; 
+
+    apxLogWrite(APXLOG_MARK_DEBUG "Inside ServiceMain...");
+    
+    /* Check the StartMode */
+    if (SO_STARTMODE) {
+        if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
+            _jni_startup = TRUE;            
+            WideToAscii(SO_STARTCLASS, _jni_rclass);
+            /* Exchange all dots with slashes */
+            apxStrCharReplaceA(_jni_rclass, '.', '/');
+            _jni_rparam = MzWideToAscii(SO_STARTPARAMS, (LPSTR)SO_STARTPARAMS);
+        }
+        else if (!lstrcmpiW(SO_STARTMODE, PRSRV_JAVA)) {
+            LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
+            if (szJH) {
+                jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
+                lstrcpyW(jx, szJH);
+                lstrcatW(jx, PRSRV_JBIN);
+                SO_STARTPATH = szJH;
+            }
+            /* StartImage now contains the full path to the java.exe */
+            SO_STARTIMAGE = jx;
+        }
+    }
+    /* Check the StopMode */
+    if (SO_STOPMODE) {
+        if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
+            _jni_shutdown = TRUE;            
+            WideToAscii(SO_STOPCLASS, _jni_sclass);
+            apxStrCharReplaceA(_jni_sclass, '.', '/');
+            _jni_sparam = MzWideToAscii(SO_STOPPARAMS, (LPSTR)SO_STOPPARAMS);
+        }
+        else if (!lstrcmpiW(SO_STOPMODE, PRSRV_JAVA)) {
+            LPWSTR jx = NULL, szJH = apxGetJavaSoftHome(gPool, FALSE);
+            if (szJH) {
+                jx = apxPoolAlloc(gPool, (lstrlenW(szJH) + 16) * sizeof(WCHAR));
+                lstrcpyW(jx, szJH);
+                lstrcatW(jx, PRSRV_JBIN);
+                SO_STOPPATH = szJH;
+            }
+            /* StopImage now contains the full path to the java.exe */
+            SO_STOPIMAGE = jx;
+        }
+    }
+    /* Find the classpath */
+    if (_jni_shutdown || _jni_startup) {
+        if (SO_JVM) {
+            if (lstrcmpW(SO_JVM, PRSRV_AUTO))
+                _jni_jvmpath = SO_JVM;
+        }
+        if (SO_CLASSPATH)
+            _jni_classpath = WideToAscii(SO_CLASSPATH, (LPSTR)SO_CLASSPATH);
+        if (SO_STARTMETHOD)
+            _jni_rmethod = WideToAscii(SO_STARTMETHOD, (LPSTR)SO_STARTMETHOD);
+        if (SO_STOPMETHOD)
+            _jni_smethod = WideToAscii(SO_STOPMETHOD, (LPSTR)SO_STOPMETHOD);
+        if (SO_JVMOPTIONS) {
+            _jni_jvmoptions = MzWideToAscii(SO_JVMOPTIONS, (LPSTR)SO_JVMOPTIONS);
+        }
+    }
+    if (_service_mode) {
+        /* Register Service Control handler */
+        _service_status_handle = RegisterServiceCtrlHandlerW(_service_name,
+                                                              service_ctrl_handler); 
+        if (IS_INVALID_HANDLE(_service_status_handle)) {
+            apxLogWrite(APXLOG_MARK_ERROR "Failed to register Service Control for %S",
+                        _service_name);
+            goto cleanup;
+        }
+    }
+    reportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+    if ((rc = serviceStart()) == 0) {
+        /* Service is started */
+        DWORD rv;
+        reportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
+        apxLogWrite(APXLOG_MARK_DEBUG "Waitning worker to finish...");
+        /* Set console handler to capture CTRL events */
+        SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_handler, TRUE);
+
+        rv = apxHandleWait(gWorker, INFINITE, FALSE);
+        apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
+        reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+        fflush(stdout);
+    }
+    else {
+        apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
+        goto cleanup;
+    }
+    if (gShutdownEvent) {
+        /* Ensure that shutdown thread exits before us */
+        apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
+        WaitForSingleObject(gShutdownEvent, 60 * 1000);
+        apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
+        CloseHandle(gShutdownEvent);
+    }
+    reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+
+    return;
+cleanup:
+    /* Cleanup */
+    reportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, 0);
+    return;
+}
+
+
+/* Run the service in the debug mode */
+BOOL docmdDebugService(LPAPXCMDLINE lpCmdline)
+{
+    BOOL rv = FALSE;
+
+    _service_mode = FALSE;
+    apxLogWrite(APXLOG_MARK_INFO "Debuging Service...");
+    serviceMain(0, NULL);
+    apxLogWrite(APXLOG_MARK_INFO "Debug service finished.");
+    
+    return rv;
+}
+
+BOOL docmdRunService(LPAPXCMDLINE lpCmdline)
+{
+    BOOL rv = FALSE;
+    _service_mode = TRUE;
+
+    apxLogWrite(APXLOG_MARK_INFO "Running Service...");
+    _service_name = lpCmdline->szApplication;
+    _service_table[0].lpServiceName = lpCmdline->szApplication;
+    _service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONW)serviceMain;
+    rv = (StartServiceCtrlDispatcherW(_service_table) == FALSE); 
+    apxLogWrite(APXLOG_MARK_INFO "Run service finished.");
+    return rv;
+}
+
+void __cdecl main(int argc, char **argv)
+{
+    UINT rv = 0;
+
+    LPAPXCMDLINE lpCmdline;
+
+    apxHandleManagerInitialize();
+    /* Create the main Pool */
+    gPool = apxPoolCreate(NULL, 0);
+
+    /* Parse the command line */
+    if ((lpCmdline = apxCmdlineParse(gPool, _options, _commands)) == NULL) {
+        apxLogWrite(APXLOG_MARK_ERROR "Invalid command line arguments");
+        rv = 1;
+        goto cleanup;
+    }
+    apxCmdlineLoadEnvVars(lpCmdline);
+    if (lpCmdline->dwCmdIndex < 5 &&
+        !loadConfiguration(lpCmdline)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Load configuration failed");
+        rv = 2;
+        goto cleanup;
+    }
+
+    apxLogOpen(gPool, SO_LOGPATH, SO_LOGPREFIX);
+    apxLogLevelSetW(NULL, SO_LOGLEVEL);
+    apxLogWrite(APXLOG_MARK_DEBUG "Procrun log initialized");
+
+    AplZeroMemory(&gStdwrap, sizeof(APX_STDWRAP));
+    
+    gStdwrap.szLogPath = SO_LOGPATH;
+    /* In debug mode allways use console */
+    if (lpCmdline->dwCmdIndex != 1) {
+        gStdwrap.szStdOutFilename = SO_STDOUTPUT;
+        gStdwrap.szStdErrFilename = SO_STDERROR;
+    }
+    redirectStdStreams(&gStdwrap);
+    switch (lpCmdline->dwCmdIndex) {
+        case 1: /* Run Service as console application */
+            if (!docmdDebugService(lpCmdline))
+                rv = 3;
+        break;
+        case 2: /* Run Service */
+            if (!docmdRunService(lpCmdline))
+                rv = 4;
+        break;
+        case 3: /* Stop Service */
+            if (!docmdStopService(lpCmdline))
+                rv = 5;
+        break;
+        case 4: /* Update Service parameters */
+            if (!docmdUpdateService(lpCmdline))
+                rv = 6;
+        break;
+        case 5: /* Install Service */
+            if (!docmdInstallService(lpCmdline))
+                rv = 7;
+        break;
+        case 6: /* Delete Service */
+            if (!docmdDeleteService(lpCmdline))
+                rv = 8;
+        break;
+        default:
+            /* Unknow command option */
+            apxLogWrite(APXLOG_MARK_ERROR "Unknown command line option");
+            printUsage(lpCmdline);
+            rv = 99;
+        break;
+    }
+
+cleanup:
+    apxLogWrite(APXLOG_MARK_INFO "Procrun finished.");
+    if (lpCmdline)
+        apxCmdlineFree(lpCmdline);
+    if (_service_status_handle)
+        CloseHandle(_service_status_handle);
+    _service_status_handle = NULL;
+    apxLogClose(NULL);
+    apxHandleManagerDestroy();
+    cleanupStdStreams(&gStdwrap);
+    ExitProcess(rv);
+}
diff --git a/src/native/nt/procrun/apps/prunsrv/prunsrv.h b/src/native/nt/procrun/apps/prunsrv/prunsrv.h
new file mode 100644
index 0000000..8632594
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunsrv/prunsrv.h
@@ -0,0 +1,31 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* ====================================================================
+ * jar2exe -- convert .jar file to WIN32 executable.
+ * Contributed by Mladen Turk <mturk at apache.org>
+ * 05 Aug 2003
+ * ==================================================================== 
+ */
+
+#ifndef _PRUNSRV_H
+#define _PRUNSRV_H
+
+#undef  PRG_VERSION
+#define PRG_VERSION    "1.0.0.0" 
+#define PRG_REGROOT   L"Apache Software Foundation\\Procrun 2.0"
+
+#endif /* _PRUNSRV_H */
+
diff --git a/src/native/nt/procrun/apps/prunsrv/prunsrv.rc b/src/native/nt/procrun/apps/prunsrv/prunsrv.rc
new file mode 100644
index 0000000..708d976
--- /dev/null
+++ b/src/native/nt/procrun/apps/prunsrv/prunsrv.rc
@@ -0,0 +1,55 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "prunsrv.h"
+
+#define RSTR_PRUNSRV "Service Runner"
+
+IDI_MAINICON         ICON                   "../../resources/procrunw.ico" 
+
+1 VERSIONINFO
+ FILEVERSION 2,0,0,0
+ PRODUCTVERSION 2,0,0,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "040904b0"
+    BEGIN
+      VALUE "Comments", "\0"
+      VALUE "CompanyName", "Apache Software Foundation\0"
+      VALUE "FileDescription", RSTR_PRUNSRV "\0"
+      VALUE "FileVersion", PRG_VERSION
+      VALUE "InternalName", RSTR_PRUNSRV "\0"
+      VALUE "LegalCopyright", "Copyright � 2000-2003 The Apache Software Foundation.\0"
+      VALUE "OriginalFilename", "prunsrv.exe\0"
+      VALUE "ProductName", RSTR_PRUNSRV "\0"
+      VALUE "ProductVersion", PRG_VERSION
+    END
+  END
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x409, 1200
+  END
+END 
diff --git a/src/native/nt/procrun/testchild/testchild.vcproj b/src/native/nt/procrun/apps/prunsrv/prunsrv.vcproj
similarity index 51%
copy from src/native/nt/procrun/testchild/testchild.vcproj
copy to src/native/nt/procrun/apps/prunsrv/prunsrv.vcproj
index e3cacb1..d667326 100644
--- a/src/native/nt/procrun/testchild/testchild.vcproj
+++ b/src/native/nt/procrun/apps/prunsrv/prunsrv.vcproj
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding = "windows-1250"?>
+<?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="7.00"
-	Name="testchild"
-	ProjectGUID="{C815B005-1292-47F7-9052-F46676CE2879}"
+	Version="7.10"
+	Name="prunsrv"
+	ProjectGUID="{DC1701B5-D480-461A-A16F-67E383AF376D}"
 	Keyword="Win32Proj">
 	<Platforms>
 		<Platform
@@ -12,13 +12,14 @@
 	<Configurations>
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="Debug"
-			IntermediateDirectory="Debug"
+			OutputDirectory="..\..\obj\Debug"
+			IntermediateDirectory="..\..\obj\Debug"
 			ConfigurationType="1"
 			CharacterSet="2">
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
+				AdditionalIncludeDirectories=".\;..\..\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -31,11 +32,13 @@
 				Name="VCCustomBuildTool"/>
 			<Tool
 				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
+				AdditionalDependencies="shlwapi.lib"
+				OutputFile="../../bin/prunsrvd.exe"
 				LinkIncremental="2"
 				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/testchild.pdb"
+				ProgramDatabaseFile="$(OutDir)/prunsrv.pdb"
 				SubSystem="1"
+				StackReserveSize="262144"
 				TargetMachine="1"/>
 			<Tool
 				Name="VCMIDLTool"/>
@@ -46,39 +49,44 @@
 			<Tool
 				Name="VCPreLinkEventTool"/>
 			<Tool
-				Name="VCResourceCompilerTool"/>
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
 			<Tool
 				Name="VCWebServiceProxyGeneratorTool"/>
 			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
 				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="Release"
-			IntermediateDirectory="Release"
+			OutputDirectory="..\..\obj\Release"
+			IntermediateDirectory="..\..\obj\Release"
 			ConfigurationType="1"
 			CharacterSet="2">
 			<Tool
 				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
+				AdditionalIncludeDirectories=".\;..\..\include"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-				StringPooling="TRUE"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="TRUE"
+				RuntimeLibrary="0"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
 				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
+				DebugInformationFormat="0"/>
 			<Tool
 				Name="VCCustomBuildTool"/>
 			<Tool
 				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
+				AdditionalDependencies="shlwapi.lib"
+				OutputFile="../../bin/prunsrv.exe"
 				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
+				GenerateDebugInformation="FALSE"
 				SubSystem="1"
+				StackReserveSize="262144"
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
 				TargetMachine="1"/>
@@ -91,28 +99,46 @@
 			<Tool
 				Name="VCPreLinkEventTool"/>
 			<Tool
-				Name="VCResourceCompilerTool"/>
+				Name="VCResourceCompilerTool"
+				AdditionalIncludeDirectories="..\..\include"/>
 			<Tool
 				Name="VCWebServiceProxyGeneratorTool"/>
 			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
 				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
 	</Configurations>
+	<References>
+	</References>
 	<Files>
 		<Filter
 			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
 			<File
-				RelativePath="testchild.c">
+				RelativePath=".\prunsrv.c">
 			</File>
 		</Filter>
 		<Filter
 			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc">
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\prunsrv.h">
+			</File>
 		</Filter>
 		<Filter
 			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+			<File
+				RelativePath=".\prunsrv.rc">
+			</File>
 		</Filter>
 	</Files>
 	<Globals>
diff --git a/src/native/nt/procrun/apps/srvbatch/MSG00001.bin b/src/native/nt/procrun/apps/srvbatch/MSG00001.bin
new file mode 100644
index 0000000..1c30b04
Binary files /dev/null and b/src/native/nt/procrun/apps/srvbatch/MSG00001.bin differ
diff --git a/src/native/nt/procrun/apps/srvbatch/example/example.c b/src/native/nt/procrun/apps/srvbatch/example/example.c
new file mode 100644
index 0000000..f1a1bb1
--- /dev/null
+++ b/src/native/nt/procrun/apps/srvbatch/example/example.c
@@ -0,0 +1,59 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <process.h>
+
+HANDLE hGlobalEvent; 
+#define EVENT_NAME "ServBatchExampleEvent"
+
+
+int main(int argc, char **argv)
+{
+    int mode = 0;
+    int i;
+
+    for (i = 0; i < argc; i++)
+        fprintf(stdout, "Command line param [%d] = %s\n", i, argv[i]);
+
+    if (argc > 1 && stricmp(argv[1], "stop") == 0)
+        mode = 1;
+    
+    if (mode) {
+        fprintf(stdout, "Stopping service\n");
+        hGlobalEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, EVENT_NAME);
+        if (!hGlobalEvent)
+            fprintf(stderr, "Unable to upen the Global Event\n");
+        else {
+            fprintf(stdout, "Signaling service event\n");
+            SetEvent(hGlobalEvent);
+        }
+
+    }
+    else {
+        fprintf(stdout, "Starting service\n");
+        hGlobalEvent = CreateEvent(NULL, FALSE, FALSE, EVENT_NAME);
+        WaitForSingleObject(hGlobalEvent, INFINITE);
+        fprintf(stdout, "Event Signaled\n");
+    }
+ 
+    fprintf(stdout, "Service mode %d finished\n", mode);
+    return 0;
+}
diff --git a/src/native/nt/procrun/testchild/testchild.vcproj b/src/native/nt/procrun/apps/srvbatch/example/example.vcproj
similarity index 68%
copy from src/native/nt/procrun/testchild/testchild.vcproj
copy to src/native/nt/procrun/apps/srvbatch/example/example.vcproj
index e3cacb1..5393cf6 100644
--- a/src/native/nt/procrun/testchild/testchild.vcproj
+++ b/src/native/nt/procrun/apps/srvbatch/example/example.vcproj
@@ -1,120 +1,132 @@
-<?xml version="1.0" encoding = "windows-1250"?>
-<VisualStudioProject
-	ProjectType="Visual C++"
-	Version="7.00"
-	Name="testchild"
-	ProjectGUID="{C815B005-1292-47F7-9052-F46676CE2879}"
-	Keyword="Win32Proj">
-	<Platforms>
-		<Platform
-			Name="Win32"/>
-	</Platforms>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory="Debug"
-			IntermediateDirectory="Debug"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="3"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/testchild.pdb"
-				SubSystem="1"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			OutputDirectory="Release"
-			IntermediateDirectory="Release"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-				StringPooling="TRUE"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="1"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-	</Configurations>
-	<Files>
-		<Filter
-			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
-			<File
-				RelativePath="testchild.c">
-			</File>
-		</Filter>
-		<Filter
-			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc">
-		</Filter>
-		<Filter
-			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
-		</Filter>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="example"
+	ProjectGUID="{1C38835C-714F-49F3-85FC-9E6372149DF3}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="example.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/example.pdb"
+				SubSystem="1"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="0"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/example.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\example.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/apps/srvbatch/example/exservice.bat b/src/native/nt/procrun/apps/srvbatch/example/exservice.bat
new file mode 100644
index 0000000..33d0fa4
--- /dev/null
+++ b/src/native/nt/procrun/apps/srvbatch/example/exservice.bat
@@ -0,0 +1,53 @@
+ at echo off
+REM Copyright 2000-2004 The Apache Software Foundation
+REM
+REM Licensed under the Apache License, Version 2.0 (the "License");
+REM you may not use this file except in compliance with the License.
+REM You may obtain a copy of the License at
+REM
+REM     http://www.apache.org/licenses/LICENSE-2.0
+REM
+REM Unless required by applicable law or agreed to in writing, software
+REM distributed under the License is distributed on an "AS IS" BASIS,
+REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+REM See the License for the specific language governing permissions and
+REM limitations under the License.
+REM
+
+ at if not "%ECHO%" == ""  echo %ECHO%
+ at if "%OS%" == "Windows_NT"  setlocal
+
+set SERVICE_EXECUTABLE=example.exe
+
+REM Figure out the running mode
+
+ at if "%1" == "install"   goto cmdInstall
+ at if "%1" == "uninstall" goto cmdUninstall
+ at if "%1" == "start"     goto cmdStart
+ at if "%1" == "stop"      goto cmdStop
+ at if "%1" == "restart"   goto cmdRestart
+echo Usage
+goto cmdEnd
+
+:cmdInstall
+..\Debug\srvbatch.exe -iwdcl SrvbatchExample "%CD%" "Srvbatch Example Service" "This is an Example service" exservice.bat 
+goto cmdEnd
+
+:cmdUninstall
+..\Debug\srvbatch.exe -u SrvbatchExample
+goto cmdEnd
+
+:cmdStart
+%SERVICE_EXECUTABLE% start
+goto cmdEnd
+
+:cmdStop
+%SERVICE_EXECUTABLE% stop
+goto cmdEnd
+
+:cmdRestart
+%SERVICE_EXECUTABLE% stop
+%SERVICE_EXECUTABLE% start
+goto cmdEnd
+
+:cmdEnd
diff --git a/src/native/nt/procrun/apps/srvbatch/srvbatch.c b/src/native/nt/procrun/apps/srvbatch/srvbatch.c
new file mode 100644
index 0000000..bad77b1
--- /dev/null
+++ b/src/native/nt/procrun/apps/srvbatch/srvbatch.c
@@ -0,0 +1,827 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <process.h>
+
+/* Custom return error values */
+#define ERR_RET_USAGE           1
+#define ERR_RET_VERSION         2
+#define ERR_RET_INSTALL         3
+#define ERR_RET_REMOVE          4
+#define ERR_RET_PARAMS          5
+#define ERR_RET_MODE            6
+
+#define MSG_ERROR               0xC0000001L
+#define MSG_INFO                0x40000002L
+
+
+
+#define MAX_CMDLINE   8192
+/* Extensions On, Old quote style */
+static LPCSTR CMD_DEFAULT     = "/E:ON /S /C \"SET SERVICE_PPID=%d && SET SERVICE_NAME=%s && CALL %s %s";
+static LPCSTR REGSERVICE_ROOT = "SYSTEM\\CurrentControlSet\\Services\\"; 
+static LPCSTR REGSERVICE_LOG  = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\";
+
+static LPCSTR REGPARAMS       = "\\Parameters";
+static LPCSTR REGDESCRIPTION  = "Description"; 
+static LPCSTR REG_SERVFILE    = "ServiceFile";
+static LPCSTR REG_LOGFILE     = "LogFile";
+static LPCSTR REG_WPATH       = "WorkingPath";
+
+
+/* Main servic table entry
+ * filled at run-time
+ */
+static SERVICE_TABLE_ENTRY  _service_table[] = {
+        {NULL, NULL},
+        {NULL, NULL}
+};
+ 
+static SERVICE_STATUS        _service_status; 
+static SERVICE_STATUS_HANDLE _service_status_handle = NULL; 
+static char                  _service_name[MAX_PATH + 1];
+static char                  _service_disp[MAX_PATH + 1];
+static char                  _service_desc[MAX_PATH * 2 + 1];
+static char                  _working_path[MAX_PATH + 1];
+static char                  _service_image[MAX_PATH + 1];
+static char                  _service_bat[MAX_PATH + 1];
+static char                  _cmd_exe[MAX_PATH + 1];
+static BOOL                  _service_log = FALSE;
+
+enum _service_mode_e {
+    mode_none,
+    mode_install,
+    mode_uninstall,
+    mode_debug,
+    mode_run
+};
+
+static enum _service_mode_e   _service_mode = mode_none;
+
+static BOOL IsWindowsNT()
+{
+    BOOL rv = FALSE;
+    OSVERSIONINFO osvi;
+
+    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+    if (!GetVersionEx(&osvi))
+        return FALSE;
+
+    switch (osvi.dwPlatformId) {
+        case VER_PLATFORM_WIN32_NT:
+            rv = TRUE;
+        break;
+        default:
+            rv = FALSE;
+        break;
+    }
+    return rv;
+}
+
+
+static BOOL IsServiceRunning(LPCSTR szServiceName)
+{
+    DWORD rc = 0;
+    SC_HANDLE schService;
+    SC_HANDLE schSCManager;
+    SERVICE_STATUS schSStatus;
+
+    schSCManager = OpenSCManager(NULL, NULL,
+                                 SC_MANAGER_CONNECT);
+    if (!schSCManager)
+        return FALSE;
+
+    schService = OpenService(schSCManager, szServiceName, 
+                             SERVICE_QUERY_STATUS);
+    if (schService != NULL) {
+        if (QueryServiceStatus(schService, &schSStatus))
+            rc = schSStatus.dwCurrentState;
+        CloseServiceHandle(schService);
+        CloseServiceHandle(schSCManager);
+        return rc == SERVICE_RUNNING ? TRUE : FALSE;
+    }
+    CloseServiceHandle(schSCManager);
+    return FALSE;
+
+}
+
+static void AddToMessageLog(BOOL isError, LPSTR szFormat, ...)
+{
+    char szMsg [MAX_PATH];
+    LPSTR   lpszStrings[2];
+    LPVOID  lpMsgBuf = NULL;
+    HANDLE  hEventSource;
+    DWORD dwErr = GetLastError();
+    WORD  wErrType;
+    DWORD dwErrId;
+    WORD  nStr;
+    va_list args;
+
+    if (!_service_log && !isError) {
+        /* Nothing to log */
+        return;
+    }
+
+    va_start(args, szFormat);
+    vsprintf(szMsg, szFormat, args);
+    va_end(args); 
+
+    if (isError) {
+        nStr = 2;
+        wErrType = EVENTLOG_ERROR_TYPE;
+        dwErrId = MSG_ERROR;
+        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                        FORMAT_MESSAGE_FROM_SYSTEM |
+                        FORMAT_MESSAGE_IGNORE_INSERTS,
+                        NULL, GetLastError(),
+                        MAKELANGID(LANG_NEUTRAL, LANG_NEUTRAL),
+                        (LPSTR) &lpMsgBuf, 0, NULL);
+        lpszStrings[0] = lpMsgBuf;
+        lpszStrings[1] = szMsg;
+    }
+    else {
+        wErrType = EVENTLOG_INFORMATION_TYPE;
+        dwErrId = MSG_INFO;
+        nStr = 1;
+        lpszStrings[0] = szMsg;
+    }
+    /* Use event logging to log the error.
+    */
+    hEventSource = RegisterEventSource(NULL, _service_name);
+
+    if (hEventSource != NULL) {
+        ReportEvent(hEventSource, // handle of event source
+            wErrType,             // event type
+            0,                    // event category
+            dwErrId,              // event ID
+            NULL,                 // current user's SID
+            nStr,                 // strings in lpszStrings
+            0,                    // no bytes of raw data
+            lpszStrings,          // array of error strings
+            NULL);                // no raw data
+        DeregisterEventSource(hEventSource);
+    }
+    if (lpMsgBuf)
+        LocalFree(lpMsgBuf);
+}
+
+static void ErrorUsage()
+{
+    if (_service_mode == mode_run)
+        return;
+
+    fprintf(stderr, "srvbatch -- program for running batch files as services.\n\n");
+    fprintf(stderr, "Usage: srvbatch -i        service service.bat\n");
+    fprintf(stderr, "                -i[wdcl]  service workingpath description comment\n"
+                    "                          service.bat\n");
+    fprintf(stderr, "                -u        service\n");
+    fprintf(stderr, "                -t        service\n");
+    fprintf(stderr, "Options:\n");
+    fprintf(stderr, "   -d   Service display name\n");
+    fprintf(stderr, "   -c   Service description\n");
+    fprintf(stderr, "   -w   Service working path\n");
+    fprintf(stderr, "   -l   Turn info logging On\n");
+
+    ExitProcess(ERR_RET_USAGE);
+}
+
+static void DumpParams()
+{
+    if (_service_mode == mode_run)
+        return;
+
+    fprintf(stdout, "Name           %s\n", _service_name);
+    fprintf(stdout, "Display        %s\n", _service_disp);
+    fprintf(stdout, "Description    %s\n", _service_desc);
+    fprintf(stdout, "ImagePath      %s\n", _service_image);
+    fprintf(stdout, "Shell          %s\n", _cmd_exe);
+    fprintf(stdout, "WorkingPath    %s\n", _working_path);
+    fprintf(stdout, "Service Script %s\n", _service_bat);
+
+}
+
+static void BuildCommandLine(char *buf, const char *action)
+{
+
+    ZeroMemory(buf, MAX_CMDLINE);
+    lstrcpy(buf, _cmd_exe);
+    lstrcat(buf, " ");
+    buf += lstrlen(buf);
+
+    sprintf(buf, CMD_DEFAULT, getpid(), _service_name, _service_bat, action);
+    lstrcat(buf, "\"");
+    fprintf(stdout, "Service Cmd    %s\n", buf);
+}
+
+/* We could use the ChangeServiceConfig2 on WIN2K+ 
+ * For now use the registry.
+ */
+static BOOL SetServiceDescription(LPCSTR szServiceName,
+                                  LPCSTR szDescription)
+{
+    HKEY  hKey;
+    CHAR  szName[MAX_PATH + 1];
+    DWORD rc;
+
+    if (lstrlen(szServiceName) > MAX_PATH)
+        return FALSE;
+    lstrcpy(szName, REGSERVICE_ROOT);
+    lstrcat(szName, szServiceName);
+
+    rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szName, 0, KEY_WRITE, &hKey);
+    if (rc != ERROR_SUCCESS) {
+        return FALSE;
+    }
+
+    rc = RegSetValueEx(hKey, REGDESCRIPTION, 0, REG_SZ,
+                       (CONST BYTE *)szDescription,
+                       lstrlen(szDescription) + 1);
+    CloseHandle(hKey);
+
+    return rc == ERROR_SUCCESS;
+}
+
+/* We could use the ChangeServiceConfig2 on WIN2K+ 
+ * For now use the registry.
+ */
+static BOOL SetServiceEventLog(LPCSTR szServiceName)
+{
+    HKEY  hKey;
+    CHAR  szName[MAX_PATH + 1];
+    DWORD dwData;
+
+    if (lstrlen(szServiceName) > MAX_PATH)
+        return FALSE;
+    lstrcpy(szName, REGSERVICE_LOG);
+    lstrcat(szName, szServiceName);
+
+    RegCreateKey(HKEY_LOCAL_MACHINE, szName, &hKey);
+
+    if (!GetModuleFileName(NULL, szName, MAX_PATH)) {
+        RegCloseKey(hKey);
+        return FALSE;
+    }
+
+    RegSetValueEx(hKey, "EventMessageFile", 0, REG_SZ, (LPBYTE)szName,
+                  lstrlen(szName) + 1);
+    dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+             EVENTLOG_INFORMATION_TYPE;
+
+    RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (LPBYTE)&dwData,
+                  sizeof(DWORD));
+ 
+    RegFlushKey(hKey);
+    RegCloseKey(hKey);
+
+    return TRUE;
+}
+
+BOOL SetServiceParameters(LPCSTR szServiceName)
+{
+    HKEY  hKey;
+    CHAR  szName[MAX_PATH + 1];
+    DWORD rc;
+    BOOL  rv = TRUE;
+
+    if (lstrlen(szServiceName) > MAX_PATH)
+        return FALSE;
+
+    lstrcpy(szName, REGSERVICE_ROOT);
+    lstrcat(szName, szServiceName);
+    lstrcat(szName, REGPARAMS);
+
+    rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
+                        szName,
+                        0,
+                        NULL,
+                        0,
+                        KEY_WRITE,
+                        NULL,
+                        &hKey,
+                        NULL);
+    if (rc != ERROR_SUCCESS) {
+        rv = FALSE;
+        goto cleanup;
+    }
+    rc = RegSetValueEx(hKey, REG_SERVFILE, 0, REG_SZ,
+                       (CONST BYTE *)_service_bat,
+                       lstrlen(_service_bat) + 1);
+    if (rc != ERROR_SUCCESS) {
+        rv = FALSE;
+        goto cleanup;
+    }
+    if (_service_log) {
+        rc = RegSetValueEx(hKey, REG_LOGFILE, 0, REG_DWORD,
+            (CONST BYTE *)&_service_log,
+            sizeof(DWORD));
+        if (rc != ERROR_SUCCESS) {
+            rv = FALSE;
+            goto cleanup;
+        }
+    }
+    if (lstrlen(_working_path)) {
+        rc = RegSetValueEx(hKey, REG_WPATH, 0, REG_SZ,
+            (CONST BYTE *)_working_path,
+            lstrlen(_working_path) + 1);
+        if (rc != ERROR_SUCCESS) {
+            rv = FALSE;
+            goto cleanup;
+        }
+    }
+
+cleanup:
+    CloseHandle(hKey);
+    return rv;
+}
+
+BOOL GetServiceParameters(LPCSTR szServiceName)
+{
+    HKEY  hKey;
+    CHAR  szName[MAX_PATH + 1];
+    DWORD rc;
+    BOOL  rv = TRUE;
+    DWORD dwType;
+    DWORD dwSize;
+
+    if (lstrlen(szServiceName) > MAX_PATH)
+        return FALSE;
+    lstrcpy(szName, REGSERVICE_ROOT);
+    lstrcat(szName, szServiceName);
+    lstrcat(szName, REGPARAMS);
+    rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szName, 0, KEY_READ, &hKey);
+    if (rc != ERROR_SUCCESS) {
+        return FALSE;
+    }
+    dwSize = MAX_PATH + 1;
+    rc = RegQueryValueEx(hKey, REG_SERVFILE, NULL, &dwType,
+                         (LPBYTE)_service_bat, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+        rv = FALSE;
+        goto cleanup;
+    }
+    dwSize = sizeof(DWORD);
+    rc = RegQueryValueEx(hKey, REG_LOGFILE, NULL, &dwType,
+                         (LPBYTE)&_service_log, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
+        _service_log = FALSE;
+    }
+    dwSize = MAX_PATH + 1;
+    rc = RegQueryValueEx(hKey, REG_WPATH, NULL, &dwType,
+                         (LPBYTE)_working_path, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+        _working_path[0] = '\0';
+    }
+
+    if (GetSystemDirectory(szName, MAX_PATH + 1)) {
+        lstrcat(szName, "\\cmd.exe");
+        if (strchr(_cmd_exe, ' ')) {
+            _cmd_exe[0] = '"';
+            lstrcpy(&_cmd_exe[1], szName);
+            lstrcat(_cmd_exe, "\"");
+        }
+        else
+            lstrcpy(_cmd_exe, szName);
+    }
+
+cleanup:
+    CloseHandle(hKey);
+    return rv;
+}
+
+BOOL InstallService(LPCSTR szServiceName)
+{
+    char szImage[MAX_PATH + 1];
+    char szPath[MAX_PATH + 1];
+    char *p;
+    BOOL rv = TRUE;
+    SC_HANDLE hManager; 
+    SC_HANDLE hService;
+
+    if (!(hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE))) {
+        return FALSE;
+    }
+
+    p = &szImage[1];
+    if (!GetModuleFileName(NULL, p, MAX_PATH)) {
+        rv = FALSE;
+        goto cleanup;
+    }
+    lstrcpy(szPath, p);
+    
+    if ((p = strrchr(szPath, '\\'))) {
+        *p = '\0';
+    }
+    szImage[0] = '"';
+    lstrcat(szImage, "\" -r ");
+    lstrcat(szImage, szServiceName);
+    if (!_working_path[0])
+        lstrcpy(_working_path, szPath);
+
+    hService = CreateService(hManager,                  // SCManager database
+                             _service_name,             // name of service
+                             _service_disp,             // name to display
+                             SERVICE_ALL_ACCESS,        // access required
+                             SERVICE_WIN32_OWN_PROCESS, // service type
+                             SERVICE_AUTO_START,        // start type
+                             SERVICE_ERROR_NORMAL,      // error control type
+                             szImage,                   // service's binary
+                             NULL,                      // no load svc group
+                             NULL,                      // no tag identifier
+                             "Tcpip\0Afd\0",            // dependencies
+                             NULL,                      // use SYSTEM account
+                             NULL);                     // no password
+    if (!hService) {
+        rv = FALSE;
+        goto cleanup;
+    }
+cleanup:
+    if (hService)
+        CloseServiceHandle(hService);
+    CloseServiceHandle(hManager);
+
+    return rv;
+}
+
+BOOL RemoveService(LPCSTR szServiceName)
+{
+    BOOL rv = TRUE;
+    SC_HANDLE hManager; 
+    SC_HANDLE hService;
+
+    if (!(hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT))) {
+        return FALSE;
+    }
+    hService = OpenService(hManager, _service_name, DELETE);
+    if (!hService) {
+        rv = FALSE;
+        goto cleanup;
+    }
+
+    rv = DeleteService(hService);
+
+cleanup:
+    if (hService)
+        CloseServiceHandle(hService);
+    CloseServiceHandle(hManager);
+    return rv;
+
+}
+
+/* Report the service status to the SCM
+ */
+BOOL ReportServiceStatus(DWORD dwCurrentState,
+                         DWORD dwWin32ExitCode,
+                         DWORD dwWaitHint)
+{
+   static DWORD dwCheckPoint = 1;
+   BOOL fResult = TRUE;
+
+   if (_service_mode == mode_run && _service_status_handle) {      
+       if (dwCurrentState == SERVICE_START_PENDING)
+            _service_status.dwControlsAccepted = 0;
+        else
+            _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+
+       _service_status.dwCurrentState  = dwCurrentState;
+       _service_status.dwWin32ExitCode = dwWin32ExitCode;
+       _service_status.dwWaitHint      = dwWaitHint;
+
+       if ((dwCurrentState == SERVICE_RUNNING) ||
+           (dwCurrentState == SERVICE_STOPPED))
+           _service_status.dwCheckPoint = 0;
+       else
+           _service_status.dwCheckPoint = dwCheckPoint++;
+       fResult = SetServiceStatus(_service_status_handle, &_service_status);
+       if (!fResult) {
+           /* TODO: Deal with error */
+       }
+   }
+   return fResult;
+}
+
+static BOOL RunChildProcess(LPCSTR szApplication, LPSTR szCmdLine,
+                            LPPROCESS_INFORMATION lpprInfo)
+{
+    STARTUPINFO stInfo;
+    BOOL bResult;
+
+    ZeroMemory(&stInfo, sizeof(stInfo));
+    stInfo.cb = sizeof(stInfo);
+    stInfo.dwFlags = STARTF_USESHOWWINDOW;
+    stInfo.wShowWindow = SW_HIDE;
+
+    bResult = CreateProcess(szApplication,
+                            szCmdLine,
+                            NULL,
+                            NULL,
+                            TRUE,
+                            CREATE_NEW_PROCESS_GROUP,
+                            NULL,
+                            _working_path,
+                            &stInfo,
+                            lpprInfo);
+
+    return bResult;
+}
+
+
+/* Executed when the service receives stop event */
+static DWORD ServiceStop()
+{ 
+    DWORD rv;
+    PROCESS_INFORMATION prInfo;
+    char cmd[MAX_CMDLINE + 1];
+    
+    if (!IsServiceRunning(_service_name)) {
+        AddToMessageLog(FALSE, "Service %s is already stopped", _service_name);
+        return 0;
+    }
+    BuildCommandLine(cmd, "stop");
+    AddToMessageLog(FALSE, "Stopping service %s", _service_name);
+    if (RunChildProcess(_cmd_exe, cmd, &prInfo)) {
+        ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+        rv = WaitForSingleObject(prInfo.hProcess, INFINITE);
+        AddToMessageLog(FALSE, "Stopped service %s", _service_name);
+        CloseHandle(prInfo.hProcess);
+        CloseHandle(prInfo.hThread);
+        return 0;
+    }
+    else {
+        AddToMessageLog(TRUE, "Stopping service %s", _service_name);
+        return 1;
+    }
+}
+
+/* Executed when the service receives restart event */
+static DWORD ServiceRestart()
+{ 
+    DWORD rv;
+    PROCESS_INFORMATION prInfo;
+    char cmd[MAX_CMDLINE + 1];    
+
+    BuildCommandLine(cmd, "restart");
+    ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+    if (RunChildProcess(_cmd_exe, cmd, &prInfo)) {
+        ReportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
+        rv = WaitForSingleObject(prInfo.hProcess, INFINITE);
+        printf("Restart Wait %d %d\n", rv, WAIT_OBJECT_0);
+        CloseHandle(prInfo.hProcess);
+        CloseHandle(prInfo.hThread);
+        rv = 0;
+    }
+    else {
+        AddToMessageLog(TRUE, "Restarting service %s", _service_name);
+        rv = 1;
+    }
+    ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+    ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+
+    return rv;
+}
+
+/* Service controll handler
+ */
+void WINAPI ServiceCtrlHandler(DWORD dwCtrlCode)
+{
+
+    switch (dwCtrlCode) {
+        case SERVICE_CONTROL_STOP:
+            ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+            /* Call the stop handler that will actualy stop the service */
+            ServiceStop();
+            return;
+        case SERVICE_CONTROL_INTERROGATE:
+        break;
+        default:
+        break;
+   }
+   ReportServiceStatus(_service_status.dwCurrentState, NO_ERROR, 0);
+}
+
+/* Console control handler
+ * 
+ */
+BOOL WINAPI ConsoleHandler(DWORD dwCtrlType)
+{
+
+    switch (dwCtrlType) {
+        case CTRL_BREAK_EVENT:
+            if (_service_mode == mode_run) {
+                ServiceStop();
+                return TRUE;
+            }
+            else
+                return FALSE;
+        case CTRL_C_EVENT:
+        case CTRL_CLOSE_EVENT:
+        case CTRL_SHUTDOWN_EVENT:
+            ServiceStop();
+            return TRUE;
+        break;
+    }
+
+    return FALSE;
+} 
+
+/* Executed when the service receives start event */
+static DWORD ServiceStart()
+{ 
+    DWORD rv;
+    PROCESS_INFORMATION prInfo;
+    char cmd[MAX_CMDLINE + 1];    
+
+    BuildCommandLine(cmd, "start");
+
+    DumpParams();
+
+    AddToMessageLog(FALSE, "Starting service %s", _service_name);
+    if (RunChildProcess(_cmd_exe, cmd, &prInfo)) {
+        AddToMessageLog(FALSE, "Started service %s", _service_name);
+        ReportServiceStatus(SERVICE_RUNNING, NO_ERROR, 0);
+        SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
+
+        rv = WaitForSingleObject(prInfo.hProcess, INFINITE);
+        AddToMessageLog(FALSE, "Finished service %s", _service_name);
+        ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+        ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+ 
+        CloseHandle(prInfo.hProcess);
+        CloseHandle(prInfo.hThread);
+        return 0;
+    }
+    else {
+        AddToMessageLog(TRUE, "Starting service %s", _service_name);
+        return 1;
+    }
+}
+
+/* Main service execution loop */
+void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
+{
+    DWORD rc;
+    _service_status.dwServiceType      = SERVICE_WIN32_OWN_PROCESS;
+    _service_status.dwCurrentState     = SERVICE_START_PENDING; 
+    _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
+                                         SERVICE_ACCEPT_PAUSE_CONTINUE; 
+    _service_status.dwWin32ExitCode    = 0; 
+    _service_status.dwCheckPoint       = 0; 
+    _service_status.dwWaitHint         = 0; 
+    _service_status.dwServiceSpecificExitCode = 0; 
+ 
+    if (_service_mode == mode_run) {
+        /* Register Service Control handler */
+        _service_status_handle = RegisterServiceCtrlHandler(_service_name,
+                                                            ServiceCtrlHandler); 
+        if (!_service_status_handle) {
+            AddToMessageLog(TRUE, "RegisterServiceCtrlHandler failed for %s",
+                            _service_name);
+            goto cleanup;
+        }
+    } 
+    ReportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+    if ((rc = ServiceStart()) == 0) {
+        AddToMessageLog(FALSE, "Service %s Main finished", _service_name);
+    } 
+
+    return;
+cleanup:
+    /* Cleanup */
+    ReportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, 0);
+    return; 
+}
+
+
+void __cdecl main(int argc, char **argv)
+{
+    UINT rv = 0;
+    char *arg;
+    int i;
+    int args_left = 1;
+    int need_desc = 0;
+    int need_disp = 0;
+    int need_path = 0;
+
+    if (argc < 3) {
+        ErrorUsage();
+    }
+
+    if (!IsWindowsNT()) {
+        fprintf(stderr, "This program will run only on Windows NT or higher\n");
+        ExitProcess(ERR_RET_VERSION);
+    }
+
+    for (i = 1; i < argc; i++) {
+        arg = argv[i];
+        if (*arg != '-')
+            break;
+
+        while (*++arg != '\0') {
+            switch (*arg) {
+                case 'i':
+                    _service_mode = mode_install;
+                    args_left++;
+                break;
+                case 'u':
+                    _service_mode = mode_uninstall;
+                break;
+                case 't':
+                    _service_mode = mode_debug;
+                break;
+                case 'r':
+                    _service_mode = mode_run;
+                break;
+                case 'd':
+                    need_disp = 1;
+                    args_left++;
+                break;
+                case 'c':
+                    need_desc = 1;
+                    args_left++;
+                break;
+                case 'w':
+                    need_path = 1;
+                    args_left++;
+                break;
+                case 'l':
+                    _service_log = TRUE;
+                break;
+                default:
+                    ErrorUsage();
+                break;
+            }
+        }
+    }
+    if ((argc - i) < args_left)
+        ErrorUsage();
+    lstrcpy(_service_name, argv[i++]);
+    if (need_path)
+        lstrcpy(_working_path, argv[i++]);
+    if (need_disp)
+        lstrcpy(_service_disp, argv[i++]);
+    if (need_desc)
+        lstrcpy(_service_desc, argv[i++]);
+
+    SetServiceEventLog(_service_name);
+    if (_service_mode == mode_install) {
+        lstrcpy(_service_bat, argv[i++]);
+        if (!InstallService(_service_name)) {
+            rv = ERR_RET_INSTALL;
+            AddToMessageLog(TRUE, "Failed installing %s", _service_name);
+            goto cleanup;
+        }
+        SetServiceParameters(_service_name);
+        if (need_desc)
+            SetServiceDescription(_service_name, _service_desc);
+        AddToMessageLog(FALSE, "Installed %s", _service_name);
+    }
+    else if (_service_mode == mode_uninstall) {
+        GetServiceParameters(_service_name);
+        AddToMessageLog(FALSE, "Uninstalling %s", _service_name);
+        ServiceStop();
+        if (!RemoveService(_service_name)) {
+            AddToMessageLog(TRUE, "Failed removing %s", _service_name);
+            rv = ERR_RET_REMOVE;
+        }
+    }
+    else if (_service_mode == mode_run) {
+        GetServiceParameters(_service_name);
+        AddToMessageLog(FALSE, "Initialized %s", _service_name);
+        _service_table[0].lpServiceName = _service_name;
+        _service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain; 
+        StartServiceCtrlDispatcher(_service_table);
+    }
+    else if (_service_mode == mode_debug) {
+        GetServiceParameters(_service_name);
+        AddToMessageLog(FALSE, "Debugging %s", _service_name);
+        ServiceMain(argc, argv);
+    }
+    else {
+        AddToMessageLog(TRUE, "Unknown service mode for %s", _service_name);
+        rv = ERR_RET_MODE;
+    }
+
+
+cleanup:
+    AddToMessageLog(FALSE, "SrvBatch finished");
+    ExitProcess(rv);
+}
diff --git a/src/native/nt/procrun/apps/srvbatch/srvbatch.rc b/src/native/nt/procrun/apps/srvbatch/srvbatch.rc
new file mode 100644
index 0000000..e54d78d
--- /dev/null
+++ b/src/native/nt/procrun/apps/srvbatch/srvbatch.rc
@@ -0,0 +1,58 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+ #include <windows.h>
+ 
+ #define PRODUCT_VER_STRING "1.0.0.0\0"
+ #define PRODUCT_VER_NAME   "ServBatch\0"
+ 
+ IDI_MAINICON         ICON                   "../../resources/procrunw.ico"
+
+LANGUAGE 0x9,0x1
+1 11 MSG00001.bin
+ 
+ 1 VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x3fL
+#if defined(_DEBUG)
+ FILEFLAGS 0x03L
+#else
+ FILEFLAGS 0x02L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+  BLOCK "StringFileInfo"
+  BEGIN
+    BLOCK "040904b0"
+    BEGIN
+      VALUE "Comments", "\0"
+      VALUE "CompanyName", "Apache Software Foundation\0"
+      VALUE "FileDescription", "Application for running batch files as services\0"
+      VALUE "FileVersion", PRODUCT_VER_STRING
+      VALUE "InternalName", PRODUCT_VER_NAME
+      VALUE "LegalCopyright", "Copyright � 2000-2004 The Apache Software Foundation.\0"
+      VALUE "OriginalFilename", "srvbatch.exe\0"
+      VALUE "ProductVersion", PRODUCT_VER_STRING
+      VALUE "ProductName", PRODUCT_VER_NAME
+    END
+  END
+  BLOCK "VarFileInfo"
+  BEGIN
+    VALUE "Translation", 0x409, 1200
+  END
+END
diff --git a/src/native/nt/procrun/apps/srvbatch/srvbatch.sln b/src/native/nt/procrun/apps/srvbatch/srvbatch.sln
new file mode 100644
index 0000000..f22d73a
--- /dev/null
+++ b/src/native/nt/procrun/apps/srvbatch/srvbatch.sln
@@ -0,0 +1,30 @@
+Microsoft Visual Studio Solution File, Format Version 8.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "srvbatch", "srvbatch.vcproj", "{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}"
+	ProjectSection(ProjectDependencies) = postProject
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example\example.vcproj", "{1C38835C-714F-49F3-85FC-9E6372149DF3}"
+	ProjectSection(ProjectDependencies) = postProject
+		{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB} = {6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}
+	EndProjectSection
+EndProject
+Global
+	GlobalSection(SolutionConfiguration) = preSolution
+		Debug = Debug
+		Release = Release
+	EndGlobalSection
+	GlobalSection(ProjectConfiguration) = postSolution
+		{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}.Debug.ActiveCfg = Debug|Win32
+		{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}.Debug.Build.0 = Debug|Win32
+		{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}.Release.ActiveCfg = Release|Win32
+		{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}.Release.Build.0 = Release|Win32
+		{1C38835C-714F-49F3-85FC-9E6372149DF3}.Debug.ActiveCfg = Debug|Win32
+		{1C38835C-714F-49F3-85FC-9E6372149DF3}.Debug.Build.0 = Debug|Win32
+		{1C38835C-714F-49F3-85FC-9E6372149DF3}.Release.ActiveCfg = Release|Win32
+		{1C38835C-714F-49F3-85FC-9E6372149DF3}.Release.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+	EndGlobalSection
+	GlobalSection(ExtensibilityAddIns) = postSolution
+	EndGlobalSection
+EndGlobal
diff --git a/src/native/nt/procrun/testchild/testchild.vcproj b/src/native/nt/procrun/apps/srvbatch/srvbatch.vcproj
similarity index 67%
copy from src/native/nt/procrun/testchild/testchild.vcproj
copy to src/native/nt/procrun/apps/srvbatch/srvbatch.vcproj
index e3cacb1..4f3a350 100644
--- a/src/native/nt/procrun/testchild/testchild.vcproj
+++ b/src/native/nt/procrun/apps/srvbatch/srvbatch.vcproj
@@ -1,120 +1,135 @@
-<?xml version="1.0" encoding = "windows-1250"?>
-<VisualStudioProject
-	ProjectType="Visual C++"
-	Version="7.00"
-	Name="testchild"
-	ProjectGUID="{C815B005-1292-47F7-9052-F46676CE2879}"
-	Keyword="Win32Proj">
-	<Platforms>
-		<Platform
-			Name="Win32"/>
-	</Platforms>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory="Debug"
-			IntermediateDirectory="Debug"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="3"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/testchild.pdb"
-				SubSystem="1"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			OutputDirectory="Release"
-			IntermediateDirectory="Release"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-				StringPooling="TRUE"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="1"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-	</Configurations>
-	<Files>
-		<Filter
-			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
-			<File
-				RelativePath="testchild.c">
-			</File>
-		</Filter>
-		<Filter
-			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc">
-		</Filter>
-		<Filter
-			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
-		</Filter>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="srvbatch"
+	ProjectGUID="{6AD26261-F2A9-4E6A-9CE6-92B4F2AA37AB}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/srvbatch.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/srvbatch.pdb"
+				SubSystem="1"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="0"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/srvbatch.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\srvbatch.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+			<File
+				RelativePath=".\srvbatch.rc">
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/extend.h b/src/native/nt/procrun/extend.h
deleted file mode 100644
index 8101612..0000000
--- a/src/native/nt/procrun/extend.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/*
- * procrun GUI extension includes.
- */
diff --git a/src/native/nt/procrun/icoi.ico b/src/native/nt/procrun/icoi.ico
deleted file mode 100644
index 1f04870..0000000
Binary files a/src/native/nt/procrun/icoi.ico and /dev/null differ
diff --git a/src/native/nt/procrun/icos.ico b/src/native/nt/procrun/icos.ico
deleted file mode 100644
index b6f6f1e..0000000
Binary files a/src/native/nt/procrun/icos.ico and /dev/null differ
diff --git a/src/native/nt/procrun/icow.ico b/src/native/nt/procrun/icow.ico
deleted file mode 100644
index 3b310c6..0000000
Binary files a/src/native/nt/procrun/icow.ico and /dev/null differ
diff --git a/src/native/nt/procrun/include/apxwin.h b/src/native/nt/procrun/include/apxwin.h
new file mode 100644
index 0000000..54f1d6f
--- /dev/null
+++ b/src/native/nt/procrun/include/apxwin.h
@@ -0,0 +1,196 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _APXWIN_H_INCLUDED_
+#define _APXWIN_H_INCLUDED_
+
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 
+#endif
+#ifndef WIN32_CE
+#define _WIN32_WINNT 0x0400
+#endif
+
+#include <windows.h>
+#include <windowsx.h>
+#include <commdlg.h>
+#include <commctrl.h>
+#include <objbase.h>
+#include <shlobj.h>
+#include <shlwapi.h>
+#include <shellapi.h>
+#include <zmouse.h>
+#include <richedit.h>
+
+#include <lm.h>
+
+
+#define APXMACRO_BEGIN                  do {
+#define APXMACRO_END                    } while(0)
+
+#ifdef  __cplusplus
+#define __APXBEGIN_DECLS    extern "C" {
+#define __APXEND_DECLS  }
+#else
+#define __APXBEGIN_DECLS
+#define __APXEND_DECLS
+#endif
+
+#define SET_BIT_FLAG(x, b) ((x) |= (1 << b))
+#define CLR_BIT_FLAG(x, b) ((x) &= ~(1 << b))
+#define TST_BIT_FLAG(x, b) ((x) & (1 << b))
+
+#define IS_INVALID_HANDLE(h) (((h) == NULL || (h) == INVALID_HANDLE_VALUE))
+
+#define DYNOLAD_TYPE_DECLARE(fnName, callconv, retType)             \
+    typedef retType (callconv *PFN_##fnName)                        \
+
+#define DYNLOAD_FPTR_DECLARE(fnName)                                \
+    PFN_##fnName FP_##fnName
+
+#define DYNLOAD_FPTR(fnName)  FP_##fnName
+
+#define DYNLOAD_FPTR_ADDRESS(fnName, dllName)                       \
+    FP_##fnName = (PFN_##fnName)GetProcAddress(                     \
+                                GetModuleHandle(TEXT(#dllName)),    \
+                                #fnName)    
+
+#define DYNLOAD_FPTR_LOAD(fnName, dllHandle)                        \
+    FP_##fnName = (PFN_##fnName)GetProcAddress(                     \
+                                dllHandle,                          \
+                                #fnName)    
+
+#define DYNLOAD_CALL(fnName)    (*FP_##fnName)
+
+#ifndef ABS
+#define ABS(x)       (((x) > 0) ? (x) : (x) * (-1))
+#endif
+
+#define SIZ_RESLEN         256
+#define SIZ_RESMAX         (SIZ_RESLEN -1)
+#define SIZ_BUFLEN         512
+#define SIZ_BUFMAX         (SIZ_BUFLEN -1)
+#define SIZ_DESLEN         1024
+#define SIZ_DESMAX         (SIZ_DESLEN -1)
+#define SIZ_HUGLEN         8192
+#define SIZ_HUGMAX         (SIZ_HUGLEN -1)
+
+#include "handles.h"
+#include "log.h"
+#include "cmdline.h"
+#include "console.h"
+#include "rprocess.h"
+#include "registry.h"
+#include "service.h"
+#include "javajni.h"
+#include "gui.h"
+
+__APXBEGIN_DECLS
+
+typedef enum {
+        APX_WINVER_UNK =       0,
+        APX_WINVER_UNSUP =     1,
+        APX_WINVER_95 =       10,
+        APX_WINVER_95_B =     11,
+        APX_WINVER_95_OSR2 =  12,
+        APX_WINVER_98 =       14,
+        APX_WINVER_98_SE =    16,
+        APX_WINVER_ME =       18,
+
+        APX_WINVER_UNICODE =  20, /* Prior versions support only narrow chars */
+
+        APX_WINVER_CE_3 =     23, /* CE is an odd beast, not supporting */
+                               /* some pre-NT features, such as the    */
+        APX_WINVER_NT =       30, /* narrow charset APIs (fooA fns), while  */
+        APX_WINVER_NT_3_5 =   35, /* not supporting some NT-family features.  */
+        APX_WINVER_NT_3_51 =  36,
+
+        APX_WINVER_NT_4 =     40,
+        APX_WINVER_NT_4_SP2 = 42,
+        APX_WINVER_NT_4_SP3 = 43,
+        APX_WINVER_NT_4_SP4 = 44,
+        APX_WINVER_NT_4_SP5 = 45,
+        APX_WINVER_NT_4_SP6 = 46,
+
+        APX_WINVER_2000 =     50,
+        APX_WINVER_2000_SP1 = 51,
+        APX_WINVER_2000_SP2 = 52,
+        APX_WINVER_XP =       60
+} APX_OSLEVEL;
+
+APX_OSLEVEL apxGetOsLevel();
+LPWSTR      AsciiToWide(LPCSTR s, LPWSTR ws);
+LPSTR       WideToAscii(LPCWSTR ws, LPSTR s);
+LPSTR       MzWideToAscii(LPCWSTR ws, LPSTR s);
+
+typedef struct APXMULTISZ APXMULTISZ;
+typedef APXMULTISZ*       LPAPXMULTISZ;
+
+DWORD   apxMultiSzToArrayA(APXHANDLE hPool, LPCSTR lpString, LPSTR **lppArray);
+DWORD   apxMultiSzToArrayW(APXHANDLE hPool, LPCWSTR lpString, LPWSTR **lppArray);
+LPWSTR  apxMultiSzCombine(APXHANDLE hPool, LPCWSTR lpStrA, LPCWSTR lpStrB,
+                          LPDWORD lpdwLength);
+
+LPAPXMULTISZ    apxMultiSzStrdup(LPCTSTR szSrc);
+LPTSTR          apxMultiSzStrcat(LPAPXMULTISZ lpmSz, LPCTSTR szSrc);
+LPCTSTR         apxMultiSzGet(LPAPXMULTISZ lpmSz);
+/** Remove the specified character from the string
+ * Replacement is done in-place.
+ */
+LPTSTR          apxStrCharRemove(LPTSTR szString, TCHAR chSkip);
+DWORD           apxStrUnQuoteInplaceA(LPSTR szString);
+DWORD           apxStrUnQuoteInplaceW(LPWSTR szString);
+
+BOOL            apxUltohex(ULONG n, LPTSTR lpBuff, DWORD dwBuffLength);
+BOOL            apxUptohex(ULONG_PTR n, LPTSTR lpBuff, DWORD dwBuffLength);
+ULONG           apxStrToul(LPCTSTR szNum);
+ULONG           apxStrToulW(LPCWSTR szNum);
+ULONG           apxAtoulW(LPCWSTR szNum);
+
+BOOL            apxMakeResourceName(LPCTSTR szPrefix, LPTSTR lpBuff,
+                                    DWORD dwBuffLength);
+
+INT             apxStrMatchA(LPCSTR szString, LPCSTR szPattern, BOOL bIgnoreCase);
+INT             apxStrMatchW(LPCWSTR szString, LPCWSTR szPattern, BOOL bIgnoreCase);
+INT             apxMultiStrMatchW(LPCWSTR szString, LPCWSTR szPattern,
+                                  WCHAR chSeparator, BOOL bIgnoreCase);
+LPSTR           apxArrayToMultiSzA(APXHANDLE hPool, DWORD nArgs, LPCSTR *lpArgs);
+void            apxStrQuoteInplaceW(LPWSTR szString);
+LPWSTR          apxMszToCRLFW(APXHANDLE hPool, LPCWSTR szStr);
+LPWSTR          apxCRLFToMszW(APXHANDLE hPool, LPCWSTR szStr, LPDWORD lpdwBytes);
+LPSTR           apxExpandStrA(APXHANDLE hPool, LPCSTR szString);
+LPWSTR          apxExpandStrW(APXHANDLE hPool, LPCWSTR szString);
+void            apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith);
+void            apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith);
+
+
+LPVOID  AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill);
+void    AplZeroMemory(PVOID Destination, SIZE_T Length);
+LPVOID  AplCopyMemory(PVOID Destination, const VOID* Source, SIZE_T Length);
+/*
+ * Find the first occurrence of lpFind in lpMem.
+ * dwLen:   The length of lpFind
+ * dwSize:  The length of lpMem
+ */
+LPBYTE  ApcMemSearch(LPCVOID lpMem, LPCVOID lpFind, SIZE_T dwLen, SIZE_T dwSize);
+LPSTR   AplRindexA(LPCSTR lpStr, int ch);
+
+#define AplMoveMemory   AplCopyMemory
+
+__APXEND_DECLS
+
+#endif /* _APXWIN_H_INCLUDED_ */
+
diff --git a/src/native/nt/procrun/include/cmdline.h b/src/native/nt/procrun/include/cmdline.h
new file mode 100644
index 0000000..fd22a0c
--- /dev/null
+++ b/src/native/nt/procrun/include/cmdline.h
@@ -0,0 +1,76 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _CMDLINE_H_INCLUDED_
+#define _CMDLINE_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define APXCMDOPT_NIL   0x00000000  /* Argopt value not needed */
+#define APXCMDOPT_INT   0x00000001  /* Argopt value is unsigned integer */
+#define APXCMDOPT_STR   0x00000002  /* Argopt value is string */
+#define APXCMDOPT_STE   0x00000006  /* Argopt value is expandable string */
+#define APXCMDOPT_MSZ   0x00000010  /* Multiline string '#' separated */
+#define APXCMDOPT_BIN   0x00000020  /* Encrypted binary */
+
+#define APXCMDOPT_REG   0x00000100  /* Save to registry */
+#define APXCMDOPT_SRV   0x00000200  /* Save to service registry */
+#define APXCMDOPT_USR   0x00000400  /* Save to user registry */
+
+#define APXCMDOPT_FOUND 0x00001000  /* The option is present in cmdline */
+#define APXCMDOPT_ADD   0x00002000  /* The option is present in cmdline as ++*/
+
+
+typedef struct APXCMDLINEOPT APXCMDLINEOPT;
+
+struct APXCMDLINEOPT {
+    LPWSTR          szName;         /* Long Argument Name */
+    LPWSTR          szRegistry;     /* Registry Association */
+    LPWSTR          szSubkey;       /* Registry Association */
+    DWORD           dwType;         /* Argument type (string, number, multistring */
+    LPWSTR          szValue;        /* Return string value  */
+    DWORD           dwValue;        /* Return numeric value or present if NIL */
+};
+
+typedef struct APXCMDLINE {
+    APXCMDLINEOPT       *lpOptions;
+    LPWSTR              szExecutable;   /* Parsed argv0 */
+    LPWSTR              szExePath;      /* Parsed argv0 */
+    LPWSTR              szApplication;  /* Fist string after //CMD// */
+    DWORD               dwCmdIndex;     /* Command index */
+    LPWSTR              *lpArgvw;
+    DWORD               dwArgc;
+    APXHANDLE           hPool;
+    
+} APXCMDLINE, *LPAPXCMDLINE;
+
+LPAPXCMDLINE apxCmdlineParse(
+    APXHANDLE hPool,
+    APXCMDLINEOPT   *lpOptions,
+    LPCWSTR         *lpszCommands
+);
+
+void apxCmdlineLoadEnvVars(
+    LPAPXCMDLINE lpCmdline
+);
+
+void apxCmdlineFree(
+    LPAPXCMDLINE lpCmdline
+);
+
+
+__APXEND_DECLS
+
+#endif /* _CMDLINE_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/console.h b/src/native/nt/procrun/include/console.h
new file mode 100644
index 0000000..1af2c53
--- /dev/null
+++ b/src/native/nt/procrun/include/console.h
@@ -0,0 +1,25 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _CONSOLE_H_INCLUDED_
+#define _CONSOLE_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+
+
+__APXEND_DECLS
+
+#endif /* _CONSOLE_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/gui.h b/src/native/nt/procrun/include/gui.h
new file mode 100644
index 0000000..10e1b14
--- /dev/null
+++ b/src/native/nt/procrun/include/gui.h
@@ -0,0 +1,185 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _GUI_H_INCLUDED_
+#define _GUI_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+
+#define IDC_STATIC              -1
+#define IDC_APPLICATION         100
+#define IDI_MAINICON            101
+#define IDC_STATBAR             102
+#define IDB_SUSERS              103
+
+#define IDS_APPLICATION         150
+#define IDS_APPDESCRIPTION      151
+#define IDS_APPVERSION          152
+#define IDS_APPCOPYRIGHT        153
+#define IDS_APPFULLNAME         154
+
+#define IDD_ABOUTBOX            250
+#define IDC_LICENSE             251
+#define IDR_LICENSE             252
+#define IAB_SYSINF              253
+#define IDC_ABOUTAPP            254
+
+#define IDD_PROGRESS            260
+#define IDDP_HEAD               261
+#define IDDP_TEXT               262
+#define IDDP_PROGRESS           263
+
+#define IDD_SELUSER             270
+#define IDSU_SELNAME            271
+#define IDSU_SELECTED           272
+#define IDSU_LIST               273
+#define IDSU_COMBO              274
+
+
+#define WM_TRAYMESSAGE          (WM_APP+1) 
+
+#define SNDMSGW SendMessageW
+#define SNDMSGA SendMessageA
+#define ComboBox_AddStringW(hwndCtl, lpsz)       ((int)(DWORD)SNDMSGW((hwndCtl), CB_ADDSTRING, 0L, (LPARAM)(LPCWSTR)(lpsz)))
+
+#define ListView_SetItemTextW(hwndLV, i, iSubItem_, pszText_) \
+{ LV_ITEMW _ms_lvi;\
+  _ms_lvi.iSubItem = iSubItem_;\
+  _ms_lvi.pszText = pszText_;\
+  SNDMSG((hwndLV), LVM_SETITEMTEXTW, (WPARAM)(i), (LPARAM)(LV_ITEMW *)&_ms_lvi);\
+} ((void)0)
+
+#define ListView_GetItemTextA(hwndLV, i, iSubItem_, pszText_, cchTextMax_) \
+{ LV_ITEMA _ms_lvi;\
+  _ms_lvi.iSubItem = iSubItem_;\
+  _ms_lvi.cchTextMax = cchTextMax_;\
+  _ms_lvi.pszText = pszText_;\
+  SNDMSGA((hwndLV), LVM_GETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&_ms_lvi);\
+}  ((void)0)
+
+#define ListView_GetItemTextW(hwndLV, i, iSubItem_, pszText_, cchTextMax_) \
+{ LV_ITEMW _ms_lvi;\
+  _ms_lvi.iSubItem = iSubItem_;\
+  _ms_lvi.cchTextMax = cchTextMax_;\
+  _ms_lvi.pszText = pszText_;\
+  SNDMSG((hwndLV), LVM_GETITEMTEXTW, (WPARAM)(i), (LPARAM)(LV_ITEMW *)&_ms_lvi);\
+}  ((void)0)
+
+#define ListView_InsertItemW(hwnd, pitem)   \
+    (int)SNDMSGW((hwnd), LVM_INSERTITEMW, 0, (LPARAM)(const LV_ITEMW *)(pitem))
+
+typedef struct APXLVITEM {
+    INT         iPosition;
+    BOOL        bSortable;
+    INT         iWidth;
+    INT         iDefault;
+    INT         iFmt;
+    LPTSTR      szLabel;
+} APXLVITEM, *LPAPXLVITEM; 
+
+typedef struct APXGUISTATE {
+    DWORD       dwShow;
+    RECT        rcPosition;
+    COLORREF    bgColor;
+    COLORREF    fgColor;
+    COLORREF    txColor;
+    INT         nColumnWidth[32];
+    INT         nUser[8];
+} APXGUISTATE, *LPAPXGUISTATE;
+
+typedef struct APXGUISTORE {
+    HANDLE  hInstance;
+    HICON   hIcon;
+    HICON   hIconSm;
+    HICON   hIconHg;
+    HWND    hMainWnd;
+    HACCEL  hAccel;
+    TCHAR   szWndClass[256];
+    TCHAR   szWndMutex[256];
+    APXGUISTATE stState;
+    STARTUPINFO stStartupInfo;
+    UINT        nWhellScroll;
+
+} APXGUISTORE, *LPAPXGUISTORE;
+
+LPAPXGUISTORE apxGuiInitialize(WNDPROC lpfnWndProc, LPCTSTR szAppName);
+
+BOOL        apxCenterWindow(HWND hwndChild, HWND hwndParent);
+
+LPSTR       apxLoadResourceA(UINT wID, UINT nBuf);
+LPWSTR      apxLoadResourceW(UINT wID, UINT nBuf);
+
+
+void        apxAppendMenuItem(HMENU hMenu, UINT idMenu, LPCTSTR szName,
+                              BOOL bDefault, BOOL bEnabled);
+void        apxAppendMenuItemBmp(HMENU hMenu, UINT idMenu, LPCTSTR szName);
+
+void        apxManageTryIconA(HWND hWnd, DWORD dwMessage, LPCSTR szInfoTitle,
+                              LPCSTR szInfo, HICON hIcon);
+void        apxManageTryIconW(HWND hWnd, DWORD dwMessage, LPCWSTR szInfoTitle,
+                              LPCWSTR szInfo, HICON hIcon);
+#ifdef _UNICODE
+#define apxLoadResource apxLoadResourceW
+#else
+#define apxLoadResource apxLoadResourceA
+#endif
+
+void        apxAboutBox(HWND hWnd);
+int         apxProgressBox(HWND hWnd, LPCTSTR szHeader,
+                           LPCWSTR szText,
+                           LPAPXFNCALLBACK fnProgressCallback,
+                           LPVOID cbData);
+BOOL        apxYesNoMessage(LPCTSTR szTitle, LPCTSTR szMessage, BOOL bStop);
+
+BOOL        apxCalcStringEllipsis(HDC hDC, LPTSTR  szString, 
+                                  int cchMax, UINT uColWidth);
+LPWSTR      apxGetDlgTextW(APXHANDLE hPool, HWND hDlg, int nIDDlgItem);
+LPSTR       apxGetDlgTextA(APXHANDLE hPool, HWND hDlg, int nIDDlgItem);
+
+#ifdef _UNICODE
+#define apxGetDlgText  apxGetDlgTextW
+#else
+#define apxGetDlgText  apxGetDlgTextA
+#endif
+
+LPSTR       apxBrowseForFolderA(HWND hWnd, LPCSTR szTitle, LPCSTR szName);
+LPWSTR      apxBrowseForFolderW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szName);
+
+#ifdef _UNICODE
+#define apxBrowseForFolder  apxBrowseForFolderW
+#else
+#define apxBrowseForFolder  apxBrowseForFolderA
+#endif
+
+LPSTR       apxGetFileNameA(HWND hWnd, LPCSTR szTitle, LPCSTR szFilter,
+                            LPCSTR szDefExt, LPCSTR szDefPath, BOOL bOpenOrSave,
+                            LPDWORD lpdwFindex);
+
+LPWSTR      apxGetFileNameW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szFilter,
+                            LPCWSTR szDefExt, LPCWSTR szDefPath, BOOL bOpenOrSave,
+                            LPDWORD lpdwFindex);
+
+#ifdef _UNICODE
+#define apxGetFileName  apxGetFileNameW
+#else
+#define apxGetFileName  apxGetFileNameA
+#endif
+
+LPCWSTR     apxDlgSelectUser(HWND hWnd, LPWSTR szUser);
+
+__APXEND_DECLS
+
+#endif /* _GUI_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/handles.h b/src/native/nt/procrun/include/handles.h
new file mode 100644
index 0000000..bd05931
--- /dev/null
+++ b/src/native/nt/procrun/include/handles.h
@@ -0,0 +1,191 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _HANDLES_H_INCLUDED_
+#define _HANDLES_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define SAFE_CLOSE_HANDLE(h)                            \
+    if ((h) != NULL && (h) != INVALID_HANDLE_VALUE) {   \
+        CloseHandle((h));                               \
+        (h) = NULL;                                     \
+    }
+
+typedef struct stAPXHANDLE  stAPXHANDLE;
+typedef stAPXHANDLE*        APXHANDLE;
+
+/**
+ * Alignment macros
+ */
+
+/* APR_ALIGN() is only to be used to align on a power of 2 boundary */
+#define APX_ALIGN(size, boundary) \
+    (((size) + ((boundary) - 1)) & ~((boundary) - 1))
+
+/** Default alignment */
+#define APX_ALIGN_DEFAULT(size) APX_ALIGN(size, 16)
+
+ 
+/** Handle callback function prototype */
+typedef BOOL (*LPAPXFNCALLBACK)(APXHANDLE hObject, UINT uMsg,
+                                WPARAM wParam, LPARAM lParam);
+
+#if _MSC_VER >= 1300
+#define APXHANDLE_INVALID               ((void *)0xdeadbeefLL)
+#else
+#define APXHANDLE_INVALID               ((void *)0xdeadbeefL)
+#endif
+
+#define APXHANDLE_HOOK_FIRST            0
+#define APXHANDLE_HOOK_LAST             1
+
+/** Flags */
+/** handle has its own heap */
+#define APXHANDLE_HAS_HEAP              0x00000001
+/** handle has CriticalSection */
+#define APXHANDLE_HAS_LOCK              0x00000002
+/** handle owns the CriticalSection */
+#define APXHANDLE_OWNS_LOCK             0x00000006
+/** handle has EventThread */
+#define APXHANDLE_HAS_EVENT             0x00000010
+/** handle has UserData */
+#define APXHANDLE_HAS_USERDATA          0x00000020
+
+/** Types */
+#define APXHANDLE_TYPE_INVALID          0xdeadbeef
+#define APXHANDLE_TYPE_POOL             0x01000000
+#define APXHANDLE_TYPE_WINHANDLE        0x02000000
+#define APXHANDLE_TYPE_SERVICE          0x03000000
+#define APXHANDLE_TYPE_LPTR             0x04000000
+#define APXHANDLE_TYPE_CONSOLE          0x05000000
+#define APXHANDLE_TYPE_PROCESS          0x06000000
+#define APXHANDLE_TYPE_JVM              0x07000000
+#define APXHANDLE_TYPE_REGISTRY         0x08000000
+
+/** Initialize the Handle manager
+ *  reference counted
+ */
+BOOL        apxHandleManagerInitialize();
+/** Destroys the Handle manager
+ *  reference counted
+ */
+BOOL        apxHandleManagerDestroy();
+/** Create the memory pool
+ * param: hParent   parent pool or NULL to use the system pool
+ *        dwOptions OR'd flags: APXHANDLE_HAS_HEAP,
+ *                              APXHANDLE_HAS_LOCK
+ *                              APXHANDLE_OWNS_LOCK
+ */                 
+APXHANDLE   apxPoolCreate(APXHANDLE hParent, DWORD dwOptions);
+/** Create the memory pool
+ * param: hPpool    pool to allocate from or NULL for system pool
+ *        dwOptions OR'd flags: see APXHANDLE_TYPE_ and APXHANDLE_HAS_
+ *                              values
+ *        lpData     user supplied Data
+ *        dwDataSize extra pool user data size, combined with options
+ *                   the lpData is copied to the internal storage;   
+ *        fnCallback Optional handle callback function
+ */                 
+APXHANDLE   apxHandleCreate(APXHANDLE hPool, DWORD dwOptions,
+                            LPVOID lpData, DWORD  dwDataSize,
+                            LPAPXFNCALLBACK fnCallback);
+/** Close the handle
+ *  Calls the callback function and frees the memory
+ */
+BOOL        apxCloseHandle(APXHANDLE hObject);
+/** Get The internal user data
+ */
+LPVOID      apxHandleGetUserData(APXHANDLE hObject);
+/** Set The internal user data
+ *  params:
+ *        lpData     user supplied Data
+ *        dwDataSize user data size, combined with create options
+ *                   the lpData is either copied to the internal storage
+ *                   or assigned.
+ */
+LPVOID      apxHandleSetUserData(APXHANDLE hObject, LPVOID lpData,
+                                 DWORD dwDataSize);
+/** Send the message to the handle 
+ *  Callback function is executed with WM_COMMAND uMsg
+ */
+BOOL        apxHandleSendMessage(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam);
+
+/** Post the message to the handle 
+ *  function returns imediately.
+ */
+BOOL        apxHandlePostMessage(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam);
+/** Lock or unlock the handle
+ * If bLock is true lock the handle, otherwise unlock.
+ */
+BOOL        apxHandleLock(APXHANDLE hObject, BOOL bLock);
+
+/** Add the callback to the handles hook chain
+ * 
+ */
+BOOL        apxHandleAddHook(APXHANDLE hObject, DWORD dwWhere,
+                             LPAPXFNCALLBACK fnCallback);
+
+DWORD       apxHandleWait(APXHANDLE hHandle, DWORD dwMilliseconds,
+                          BOOL bKill);
+
+/** General pool memory allocation functions
+ */
+LPVOID      apxPoolAlloc(APXHANDLE hPool, DWORD dwSize);
+LPVOID      apxPoolCalloc(APXHANDLE hPool, DWORD dwSize);
+LPVOID      apxPoolRealloc(APXHANDLE hPool, LPVOID lpMem, DWORD dwNewSize);
+LPTSTR      apxPoolStrdup(APXHANDLE hPool, LPCTSTR szSource);
+
+/** General system pool memory allocation functions
+ */
+
+LPVOID      apxAlloc(DWORD dwSize);
+LPVOID      apxCalloc(DWORD dwSize);
+LPVOID      apxRealloc(LPVOID lpMem, DWORD dwNewSize);
+
+LPSTR       apxStrdupA(LPCSTR szSource);
+LPWSTR      apxStrdupW(LPCWSTR szSource);
+LPSTR       apxPoolStrdupA(APXHANDLE hPool, LPCSTR szSource);
+LPWSTR      apxPoolStrdupW(APXHANDLE hPool, LPCWSTR szSource);
+
+LPWSTR      apxPoolWStrdupA(APXHANDLE hPool, LPCSTR szSource);
+
+#define     apxPoolWStrdupW apxPoolStrdupW
+
+#ifdef _UNICODE
+#define apxStrdup       apxStrdupW
+#define apxPoolStrdup   apxPoolStrdupW
+#else
+#define apxStrdup       apxStrdupA
+#define apxPoolStrdup   apxPoolStrdupW
+#endif
+
+#ifndef _UNICODE
+#define     apxPoolWStrdup  apxPoolWStrdupA
+#define     apxWStrdup      apxWStrdupA
+#else
+#define     apxPoolWStrdup  apxPoolStrdupW
+#define     apxWStrdup      apxStrdupW
+#endif
+/** Free the allocated memory
+ * It will call te correct pool if the address is valid
+ */
+VOID        apxFree(LPVOID lpMem);
+
+__APXEND_DECLS
+
+#endif /* _HANDLES_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/javajni.h b/src/native/nt/procrun/include/javajni.h
new file mode 100644
index 0000000..44ae6a6
--- /dev/null
+++ b/src/native/nt/procrun/include/javajni.h
@@ -0,0 +1,41 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _JAVAJNI_H_INCLUDED_
+#define _JAVAJNI_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+APXHANDLE   apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath);
+
+BOOL        apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
+                              LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
+                              DWORD dwSs, BOOL bReduceSignals);
+
+BOOL        apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
+                                 LPCSTR szMethodName,
+                                 LPCVOID lpArguments);
+
+BOOL        apxJavaStart(APXHANDLE hJava);
+
+DWORD       apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill);
+
+BOOL        apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut,
+                          LPCWSTR szFilename);
+
+
+__APXEND_DECLS
+
+#endif /* _JAVAJNI_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/log.h b/src/native/nt/procrun/include/log.h
new file mode 100644
index 0000000..3f20249
--- /dev/null
+++ b/src/native/nt/procrun/include/log.h
@@ -0,0 +1,101 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* Logfile handling 
+ * Use Systemdir/Logfiles/Apache as a default path
+ */
+
+#ifndef _LOG_H_INCLUDED_
+#define _LOG_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define APX_LOGLOCK(file)                           \
+    APXMACRO_BEGIN                                  \
+        DWORD _lmax = 0;                            \
+        while(!LockFile(file, 0, 0, 512, 0)) {      \
+            Sleep(10);                              \
+            if (_lmax++ > 1000) break;              \
+        }                                           \
+        SetFilePointer(file, 0, NULL, FILE_END);    \
+    APXMACRO_END
+
+#define APX_LOGUNLOCK(file)                         \
+    APXMACRO_BEGIN                                  \
+        UnlockFile(file, 0, 0, 512, 0);             \
+    APXMACRO_END
+
+#define APXLOG_LEVEL_DEBUG  0
+#define APXLOG_LEVEL_INFO   1
+#define APXLOG_LEVEL_WARN   2
+#define APXLOG_LEVEL_ERROR  3
+
+#define APXLOG_MARK_INFO    NULL, APXLOG_LEVEL_INFO,  TRUE,  NULL, 0, ""
+#define APXLOG_MARK_WARN    NULL, APXLOG_LEVEL_WARN,  TRUE,  NULL, 0, ""
+#define APXLOG_MARK_ERROR   NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, __LINE__, ""
+#define APXLOG_MARK_DEBUG   NULL, APXLOG_LEVEL_DEBUG, TRUE,  __FILE__, __LINE__, ""
+#define APXLOG_MARK_RAW     NULL, APXLOG_LEVEL_INFO,  FALSE, NULL, 0,
+#define APXLOG_MARK_SYSERR  NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, __LINE__, NULL
+
+LPWSTR apxLogFile(
+    APXHANDLE hPool,
+    LPCWSTR szPath,
+    LPCWSTR szPrefix,
+    LPCWSTR szName
+);
+
+HANDLE apxLogOpen(
+    APXHANDLE hPool,
+    LPCWSTR szPath,
+    LPCWSTR szPrefix
+);
+
+void apxLogClose(
+    HANDLE hFile
+);
+
+void apxLogLevelSet(
+    HANDLE  hFile,
+    DWORD dwLevel
+);
+
+void apxLogLevelSetW(
+    HANDLE  hFile,
+    LPCWSTR szLevel
+);
+
+int
+apxLogWrite(
+    HANDLE  hFile,
+    DWORD   dwLevel,
+    BOOL    bTimeStamp,
+    LPCSTR  szFile,
+    DWORD   dwLine,
+    LPCSTR  szFormat,
+    ...
+);
+
+int
+apxDisplayError(
+    BOOL    bDisplay,
+    LPCSTR  szFile,
+    DWORD   dwLine,
+    LPCSTR  szFormat,
+    ...
+);
+
+__APXEND_DECLS
+
+#endif /* _LOG_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/registry.h b/src/native/nt/procrun/include/registry.h
new file mode 100644
index 0000000..10f42c0
--- /dev/null
+++ b/src/native/nt/procrun/include/registry.h
@@ -0,0 +1,145 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _REGISTRY_H_INCLUDED_
+#define _REGISTRY_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+#define APXREG_SOFTWARE         0x0001
+#define APXREG_SERVICE          0x0002
+#define APXREG_USER             0x0004
+
+#define APXREG_PARAMSOFTWARE    0x0010
+#define APXREG_PARAMSERVICE     0x0020
+#define APXREG_PARAMUSER        0x0040
+
+/** Create or open the process registry keys
+ */
+APXHANDLE apxCreateRegistryA(APXHANDLE hPool, REGSAM samDesired,
+                             LPCSTR szRoot, LPCSTR szKeyName,
+                             DWORD dwOptions);
+APXHANDLE apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired,
+                             LPCWSTR szRoot, LPCWSTR szKeyName,
+                             DWORD dwOptions);
+
+#ifdef _UNICODE
+#define apxCreateRegistry   apxCreateRegistryW
+#else
+#define apxCreateRegistry   apxCreateRegistryA
+#endif
+
+/** Delete the process registry keys
+ */
+BOOL      apxDeleteRegistryA(LPCSTR szRoot, LPCSTR szKeyName,
+                            BOOL bDeleteEmpty);
+
+BOOL      apxDeleteRegistryW(LPCWSTR szRoot, LPCWSTR szKeyName,
+                            BOOL bDeleteEmpty);
+
+#ifdef _UNICODE
+#define apxDeleteRegistry   apxDeleteRegistryW
+#else
+#define apxDeleteRegistry   apxDeleteRegistryA
+#endif
+
+/** Get the JavaHome path from registry
+ * and set the JAVA_HOME environment variable if not found
+ * If bPreferJre is set use the JRE's path as JAVA_HOME
+ */
+LPWSTR    apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre);
+
+/** Get the Java RuntimeLib from registry (jvm.dll)
+ */
+LPWSTR    apxGetJavaSoftRuntimeLib(APXHANDLE hPool);
+
+LPSTR     apxRegistryGetStringA(APXHANDLE hRegistry, DWORD dwFrom,
+                                LPCSTR szSubkey, LPCSTR szValueName);
+
+LPWSTR    apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom,
+                                LPCWSTR szSubkey, LPCWSTR szValueName);
+
+#ifdef _UNICODE
+#define apxRegistryGetString    apxRegistryGetStringW
+#else
+#define apxRegistryGetString    apxRegistryGetStringA
+#endif
+
+LPBYTE    apxRegistryGetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+                                LPCSTR szSubkey, LPCSTR szValueName,
+                                LPBYTE lpData, LPDWORD lpdwLength);
+
+LPBYTE    apxRegistryGetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+                                LPCWSTR szSubkey, LPCWSTR szValueName,
+                                LPBYTE lpData, LPDWORD lpdwLength);
+
+#ifdef _UNICODE
+#define apxRegistryGetBinary    apxRegistryGetBinaryW
+#else
+#define apxRegistryGetBinary    apxRegistryGetBinaryA
+#endif
+
+BOOL    apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+                              LPCSTR szSubkey, LPCSTR szValueName,
+                              const LPBYTE lpData, DWORD dwLength);
+
+BOOL    apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+                              LPCWSTR szSubkey, LPCWSTR szValueName,
+                              const LPBYTE lpData, DWORD dwLength);
+
+LPWSTR  apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+                             LPCWSTR szSubkey, LPCWSTR szValueName,
+                             LPWSTR lpData, LPDWORD lpdwLength);
+
+BOOL    apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+                             LPCWSTR szSubkey, LPCWSTR szValueName,
+                             LPCWSTR lpData, DWORD dwLength);
+
+BOOL    apxRegistrySetStrA(APXHANDLE hRegistry, DWORD dwFrom,
+                           LPCSTR szSubkey, LPCSTR szValueName,
+                           LPCSTR szValue);
+
+BOOL    apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom,
+                           LPCWSTR szSubkey, LPCWSTR szValueName,
+                           LPCWSTR szValue);
+
+
+#ifdef _UNICODE
+#define apxRegistrySetStr    apxRegistrySetStrW
+#else
+#define apxRegistrySetStr    apxRegistrySetStrA
+#endif
+
+BOOL    apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom,
+                           LPCWSTR szSubkey, LPCWSTR szValueName,
+                           DWORD dwValue);
+
+DWORD   apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom,
+                              LPCWSTR szSubkey, LPCWSTR szValueName);
+
+
+BOOL    apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom,
+                           LPCWSTR szSubkey, LPCWSTR szValueName);
+
+
+#ifdef _UNICODE
+#define apxRegistryDelete    apxRegistryDeleteW
+#else
+#define apxRegistryDelete    apxRegistryDeleteA
+#endif
+
+__APXEND_DECLS
+
+#endif /* _REGISTRY_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/rprocess.h b/src/native/nt/procrun/include/rprocess.h
new file mode 100644
index 0000000..db20821
--- /dev/null
+++ b/src/native/nt/procrun/include/rprocess.h
@@ -0,0 +1,75 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _RPROCESS_H_INCLUDED_
+#define _RPROCESS_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+BOOL        apxProcessExecute(APXHANDLE hProcess);
+
+APXHANDLE   apxCreateProcessA(APXHANDLE hPool, DWORD dwOptions,
+                              LPAPXFNCALLBACK fnCallback,
+                              LPCSTR szUsername, LPCSTR szPassword,
+                              BOOL bLogonAsService);
+APXHANDLE   apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+                              LPAPXFNCALLBACK fnCallback,
+                              LPCWSTR szUsername, LPCWSTR szPassword,
+                              BOOL bLogonAsService);
+
+#ifdef _UNICODE
+#define apxCreateProcess    apxCreateProcessW
+#else
+#define apxCreateProcess    apxCreateProcessA
+#endif
+
+BOOL        apxProcessSetExecutableA(APXHANDLE hProcess, LPCSTR szName);
+BOOL        apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName);
+
+BOOL        apxProcessSetCommandLineA(APXHANDLE hProcess, LPCSTR szCmdline);
+BOOL        apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline);
+BOOL        apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle,
+                                      DWORD dwArgc, LPCWSTR *lpArgs);
+
+BOOL        apxProcessSetWorkingPathA(APXHANDLE hProcess, LPCSTR szPath);
+BOOL        apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath);
+
+DWORD       apxProcessPutcA(APXHANDLE hProcess, INT ch);
+DWORD       apxProcessPutcW(APXHANDLE hProcess, INT ch);
+DWORD       apxProcessPutsA(APXHANDLE hProcess, LPCSTR szString);
+DWORD       apxProcessPutsW(APXHANDLE hProcess, LPCWSTR szString);
+
+#ifndef _UNICODE
+#define     apxProcessPutc  apxProcessPutcA
+#define     apxProcessPuts  apxProcessPutsA
+#else
+#define     apxProcessPutc  apxProcessPutcW
+#define     apxProcessPuts  apxProcessPutsW
+#endif
+
+DWORD       apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen);
+
+VOID        apxProcessCloseInputStream(APXHANDLE hProcess);
+BOOL        apxProcessFlushStdin(APXHANDLE hProcess);
+
+DWORD       apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds,
+                           BOOL bKill);
+
+BOOL        apxProcessRunning(APXHANDLE hProcess);
+
+
+__APXEND_DECLS
+
+#endif /* _RPROCESS_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/include/service.h b/src/native/nt/procrun/include/service.h
new file mode 100644
index 0000000..30d03fa
--- /dev/null
+++ b/src/native/nt/procrun/include/service.h
@@ -0,0 +1,72 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _SERVICE_H_INCLUDED_
+#define _SERVICE_H_INCLUDED_
+
+__APXBEGIN_DECLS
+
+typedef struct APXSERVENTRY {
+    WCHAR   szServiceName[SIZ_RESLEN];
+    WCHAR   szObjectName[SIZ_RESLEN];
+    WCHAR   szServiceDescription[SIZ_DESLEN];
+    DWORD   dwStart;
+    LPQUERY_SERVICE_CONFIGW lpConfig;
+    SERVICE_STATUS          stServiceStatus;
+    SERVICE_STATUS_PROCESS  stStatusProcess;
+
+} APXSERVENTRY, *LPAPXSERVENTRY;
+
+
+APXHANDLE   apxCreateService(APXHANDLE hPool, DWORD dwOptions,
+                             BOOL bManagerMode);
+
+BOOL        apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions);
+
+
+BOOL        apxServiceSetNames(APXHANDLE hService, LPCWSTR szImagePath,
+                               LPCWSTR szDisplayName, LPCWSTR szDescription,
+                               LPCWSTR szUsername, LPCWSTR szPassword);
+
+BOOL        apxServiceSetOptions(APXHANDLE hService, DWORD dwServiceType,
+                                 DWORD dwStartType, DWORD dwErrorControl);
+
+BOOL        apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
+                              LPAPXFNCALLBACK fnControlCallback,
+                              LPVOID lpCbData);
+BOOL        apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
+                              LPCWSTR szDisplayName, LPCWSTR szImagePath,
+                              LPCWSTR lpDependencies, DWORD dwServiceType,
+                              DWORD dwStartType);
+
+LPAPXSERVENTRY  apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus);
+
+/** Delete te service
+ * Stops the service if running
+ */
+BOOL        apxServiceDelete(APXHANDLE hService);
+
+DWORD       apxServiceBrowse(APXHANDLE hService,
+                             LPCWSTR szIncludeNamePattern,
+                             LPCWSTR szIncludeImagePattern,
+                             LPCWSTR szExcludeNamePattern,
+                             LPCWSTR szExcludeImagePattern,
+                             UINT uMsg,
+                             LPAPXFNCALLBACK fnDisplayCallback,
+                             LPVOID lpCbData);
+
+__APXEND_DECLS
+
+#endif /* _SERVICE_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/java/Test.java b/src/native/nt/procrun/java/Test.java
index 12f92f1..c1f0db3 100644
--- a/src/native/nt/procrun/java/Test.java
+++ b/src/native/nt/procrun/java/Test.java
@@ -1,3 +1,19 @@
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
 import java.io.*;
 import java.lang.*;
 
@@ -15,4 +31,4 @@ public class Test implements Runnable {
             t.printStackTrace(System.err);
         }         
     }
-} 
\ No newline at end of file
+}
diff --git a/src/native/nt/procrun/libprocrun.vcproj b/src/native/nt/procrun/libprocrun.vcproj
new file mode 100644
index 0000000..21789b2
--- /dev/null
+++ b/src/native/nt/procrun/libprocrun.vcproj
@@ -0,0 +1,270 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="libprocrun"
+	ProjectGUID="{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="obj\libD"
+			IntermediateDirectory="obj\libD"
+			ConfigurationType="4"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\;.\include;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32"
+				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="bin/libprocrund.lib"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="obj\libR"
+			IntermediateDirectory="obj\libR"
+			ConfigurationType="4"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\;.\include;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32"
+				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+				RuntimeLibrary="0"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="bin/libprocrun.lib"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug Unicode|Win32"
+			OutputDirectory="obj\libDU"
+			IntermediateDirectory="obj\libDU"
+			ConfigurationType="4"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\;.\include;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32"
+				PreprocessorDefinitions="WIN32;_DEBUG;_UNICODE;_LIB"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="bin/libprocrunud.lib"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release Unicode|Win32"
+			OutputDirectory="obj\libRU"
+			IntermediateDirectory="obj\libRU"
+			ConfigurationType="4"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\;.\include;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32"
+				PreprocessorDefinitions="WIN32;NDEBUG;_UNICODE;_LIB"
+				RuntimeLibrary="0"
+				BufferSecurityCheck="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="bin/libprocrunu.lib"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\src\cmdline.c">
+			</File>
+			<File
+				RelativePath=".\src\console.c">
+			</File>
+			<File
+				RelativePath=".\src\gui.c">
+			</File>
+			<File
+				RelativePath=".\src\handles.c">
+			</File>
+			<File
+				RelativePath=".\src\javajni.c">
+			</File>
+			<File
+				RelativePath=".\src\log.c">
+			</File>
+			<File
+				RelativePath=".\src\mclib.c">
+			</File>
+			<File
+				RelativePath=".\src\registry.c">
+			</File>
+			<File
+				RelativePath=".\src\rprocess.c">
+			</File>
+			<File
+				RelativePath=".\src\service.c">
+			</File>
+			<File
+				RelativePath=".\src\utils.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath=".\include\apxwin.h">
+			</File>
+			<File
+				RelativePath=".\include\cmdline.h">
+			</File>
+			<File
+				RelativePath=".\include\console.h">
+			</File>
+			<File
+				RelativePath=".\include\gui.h">
+			</File>
+			<File
+				RelativePath=".\include\handles.h">
+			</File>
+			<File
+				RelativePath=".\include\javajni.h">
+			</File>
+			<File
+				RelativePath=".\include\log.h">
+			</File>
+			<File
+				RelativePath=".\src\mclib.h">
+			</File>
+			<File
+				RelativePath=".\src\private.h">
+			</File>
+			<File
+				RelativePath=".\include\registry.h">
+			</File>
+			<File
+				RelativePath=".\include\rprocess.h">
+			</File>
+			<File
+				RelativePath=".\include\service.h">
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/procgui.c b/src/native/nt/procrun/procgui.c
deleted file mode 100644
index 4cbf5ab..0000000
--- a/src/native/nt/procrun/procgui.c
+++ /dev/null
@@ -1,1300 +0,0 @@
-/* ====================================================================
-     Copyright 2002-2004 The Apache Software Foundation.
-   
-     Licensed 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.
-*/
-/* ====================================================================
- * procrun
- *
- * Contributed by Mladen Turk <mturk at apache.org>
- *
- * 05 Aug 2002
- * ==================================================================== 
- */
-#if defined(PROCRUN_WINAPP)
-
-#ifndef STRICT
-#define STRICT
-#endif
-#ifndef OEMRESOURCE
-#define OEMRESOURCE
-#endif
-
-#include <windows.h>
-#include <windowsx.h>
-#include <commctrl.h>
-#include <objbase.h>
-#include <shlobj.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <Shlwapi.h>
-#include <io.h>
-#include <fcntl.h>
-#include <process.h>
-#include <time.h>
-#include <stdarg.h>
-#include <jni.h>
- 
-#include "procrun.h"
-
-#define WM_TRAYMESSAGE         (WM_APP+1)
-#define WM_TIMER_TIMEOUT       10
-#define MAX_LOADSTRING         200
-#define MAX_LISTCOUNT          8192
-#define CONWRAP_SUCCESS        0
-#define CONWRAP_ENOARGS        1
-#define CONWRAP_EARG           2
-#define CONWRAP_EFATAL         3
-
-#ifndef PSH_NOCONTEXTHELP
-#define PSH_NOCONTEXTHELP       0x02000000
-#endif
-
-#define MAX_LIST_ITEMS         4000     /* maximum items in ListView */
- 
-extern int g_proc_mode;
-/* The main envronment for services */
-extern procrun_t *g_env;
-
-int                    ac_use_try = 0;
-int                    ac_use_dlg = 0;
-int                    ac_use_show = 0;
-int                    ac_use_props = 0;
-int                    ac_use_lview = 1;
-/* default splash timeout 5 seconds */
-int                    ac_splash_timeout = 5000;
-int                    ac_lview_current = 0;
-HINSTANCE              ac_instance;
-HWND                   ac_main_hwnd;
-HWND                   ac_list_hwnd;
-char                   *ac_cmdline;
-char                   *ac_cmdname;
-char                   *ac_splash_msg = NULL;
-
-RECT                   ac_winpos = {-1, 0, 640, 480};
-
-static procrun_t       *ac_env = NULL;
-static HICON           ac_main_icon;
-static HICON           ac_try_icon;
-static HICON           ac_try_stop;
-static UINT            ac_taskbar_created;
-static HWND            ac_console_hwnd = NULL;
-static char            *ac_stdout_lines[MAX_LISTCOUNT + 1];
-static HWND            ac_splash_hwnd = NULL;
-static HWND            ac_splist_hwnd;
-static int             ac_lv_iicon = 0;
-
-
-static prcrun_lview_t lv_columns[] = {
-    {   "Type",     80      },
-    {   "Message",  532     },
-    {   NULL,       0       },
-};
-
-static char *lv_infos[] = {
-    "Info",
-    "Warning",
-    "Error"
-};
-
-prcrun_lview_t *ac_columns = &lv_columns[0];
-
-INT_PTR ac_show_properties(HWND owner);
-
-/* Create the list view using ac_columns struct.
- * You may change the ac_columns to a different layout
- * (see the tomcat.c for example)
- */
-static void lv_create_view(HWND hdlg, LPRECT pr, LPRECT pw)
-{
-    LV_COLUMN lvc;
-    int i = 0;
-    HIMAGELIST  imlist;
-    HICON hicon;
-    prcrun_lview_t *col = ac_columns;
-
-    imlist = ImageList_Create(16, 16, ILC_COLORDDB | ILC_MASK, 4, 0);
-    hicon = LoadImage(ac_instance, MAKEINTRESOURCE(IDI_ICOI),
-                      IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-    ImageList_AddIcon(imlist, hicon);
-    hicon = LoadImage(ac_instance, MAKEINTRESOURCE(IDI_ICOW),
-                      IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-    ImageList_AddIcon(imlist, hicon);
-    hicon = LoadImage(ac_instance, MAKEINTRESOURCE(IDI_ICOS),
-                      IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-    ImageList_AddIcon(imlist, hicon);
-    ImageList_AddIcon(imlist, hicon);
-    
-    ac_list_hwnd = CreateWindowEx(0L, WC_LISTVIEW, "", 
-                                  WS_VISIBLE | WS_CHILD |
-                                  LVS_REPORT | WS_EX_CLIENTEDGE,
-                                  0, 0, pr->right - pr->left,
-                                  pr->bottom - abs((pw->top - pw->bottom)),
-                                  hdlg, NULL, ac_instance, NULL);
-    lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
-    lvc.fmt  = LVCFMT_LEFT;
-    
-    ListView_SetImageList(ac_list_hwnd,imlist, LVSIL_SMALL);
-    
-    while (col->label)  {
-        lvc.iSubItem    = i;
-        lvc.cx          = col->width;
-        lvc.pszText     = col->label;
-        ListView_InsertColumn(ac_list_hwnd, i, &lvc );
-        ++col;
-        ++i;
-    }
-#ifdef LVS_EX_FULLROWSELECT
-    ListView_SetExtendedListViewStyleEx(ac_list_hwnd, 0,
-        LVS_EX_FULLROWSELECT |
-        LVS_EX_INFOTIP);
-#endif
-    
-}
-
-/*
- * Find the first occurrence of find in s.
- * This is the case insesitive version of strstr
- * that the MSVCRT is missing
- */
-static char *
-stristr(register const char *s, register const char *find)
-{
-    register char c, sc;
-    register size_t len;
-
-    if ((c = *find++) != 0) {
-        len = strlen(find);
-        do {
-            do {
-                if ((sc = *s++) == 0)
-                    return (NULL);
-            } while (sc != toupper(c));
-        } while (strnicmp(s, find, len) != 0);
-        s--;
-    }
-    return ((char *)s);
-} 
-
-/* Parse the stdout messages and try to figure out what it is about.
- * Display the icon in the list view acording to that message.
- * If param from is nonzero (from stderr), display the error icon.
- */ 
-void parse_list_string(const char *str, int from)
-{
-    int row = 0x7FFFFFFF;
-    LV_ITEM lvi;
-
-    if (!from) {
-        /* some general messages 
-         * chnage to suit the particular app.
-         */
-        if (stristr(str, "INFO"))
-            ac_lv_iicon = 0;
-        else if (stristr(str, "WARNING"))
-            ac_lv_iicon = 1;
-        else if (stristr(str, "WARN "))
-            ac_lv_iicon = 1;
-        else if (stristr(str, "ERROR"))
-            ac_lv_iicon = 2;
-        else if (stristr(str, "SEVERE"))
-            ac_lv_iicon = 2;       
-    }
-    else /* if this is from stderr set the error icon */
-        ac_lv_iicon = 2;
-
-    memset(&lvi, 0, sizeof(LV_ITEM));
-    lvi.mask        = LVIF_IMAGE | LVIF_TEXT;
-    lvi.iItem       = ac_lview_current;
-    lvi.iImage      = ac_lv_iicon;
-    lvi.pszText     = lv_infos[ac_lv_iicon];
-    lvi.cchTextMax  = 8;
-    row = ListView_InsertItem(ac_list_hwnd, &lvi);
-    if (row == -1)
-        return;
-    ListView_SetItemText(ac_list_hwnd, row, 1, (char *)str);
-    ListView_EnsureVisible(ac_list_hwnd,
-                               ListView_GetItemCount(ac_list_hwnd) - 1,
-                               FALSE); 
-
-    ac_lview_current++;
-}
-
-lv_parse_cb_t  lv_parser = parse_list_string;
-
-/* Try icon helper
- * Add/Change/Delete icon from the windows try.
- */
-void ac_show_try_icon(HWND hwnd, DWORD message, const char *tip, int stop)
-{
-    
-    NOTIFYICONDATA nid;
-    if (!ac_use_try)
-        return;
-
-    ZeroMemory(&nid,sizeof(nid));
-    nid.cbSize = sizeof(NOTIFYICONDATA);
-    nid.hWnd = hwnd;
-    nid.uID = 0xFF;
-    nid.uFlags = NIF_ICON | NIF_MESSAGE;
-    if (tip)
-        nid.uFlags |= NIF_TIP;
-
-    nid.uCallbackMessage = WM_TRAYMESSAGE;
-    
-    if (message != NIM_DELETE)
-        nid.hIcon = stop ? ac_try_stop : ac_try_icon;
-    else
-        nid.hIcon = NULL;
-    if (tip)
-        strcpy(nid.szTip, tip);
-
-    Shell_NotifyIcon(message, &nid);
-}
-
-/* Main console dialog print function
- * The str comes either from redirected child's stdout
- * or stderr pipe.
- */
-void ac_add_list_string(const char *str, int len, int from)
-{
-    static int nqueue = 0;
-    static int nlen = 0, olen = 0;
-    static int litems = 0;
-    int i;
-
-    if (str) {
-        if (ac_splash_hwnd) {
-            if (ac_splash_msg && 
-                !strnicmp(str, ac_splash_msg, strlen(ac_splash_msg))) {
-                ac_show_try_icon(ac_main_hwnd, NIM_MODIFY, ac_cmdname, 0);
-                EndDialog(ac_splash_hwnd, TRUE);
-                ac_splash_hwnd = NULL;
-            }
-            else
-                SendMessage(ac_splist_hwnd, LB_INSERTSTRING, 0, (LPARAM)str);
-        }
-        /* Ensure that we dont have more the MAX_LISTCOUNT
-         * in the queue
-         */
-        if (nqueue > MAX_LISTCOUNT - 1) {
-            free(ac_stdout_lines[0]);
-            /* TODO: improve performance */
-            for (i = 1; i < MAX_LISTCOUNT; i++)
-                ac_stdout_lines[i - 1] = ac_stdout_lines[i];
-            --nqueue;
-        }
-        /* add the string to the queue */
-        ac_stdout_lines[nqueue++] = strdup(str);
-        nlen = max(nlen, len);
-    }
-    /* If there is no window or the queue is empty return */
-    if (!ac_list_hwnd || !nqueue)
-        return;
-    /* Ok. We have the window open and something in the queue.
-     * Flush that to the screen.
-     */
-    if (ac_use_lview) {
-        for (i = 0; i < nqueue; i++) {
-            /* Call the list view callback parser */
-            (*lv_parser)(ac_stdout_lines[i], from);
-            if (litems++ > MAX_LIST_ITEMS)
-                ListView_DeleteItem(ac_list_hwnd, 0);
-        }
-    }
-    else 
-    {
-        /* Flush all the lines from the queue */
-        for (i = 0; i < nqueue; i++) {
-            ListBox_AddString(ac_list_hwnd, ac_stdout_lines[i]);
-            /* Ensure no more then MAX_LIST_ITEMS are maintained.
-             * This ensures that we dont waste to much system resources.
-             */
-            if (litems++ > MAX_LIST_ITEMS)
-                ListBox_DeleteString(ac_list_hwnd, 0);
-        
-        }
-        if (olen < nlen) {
-            olen = nlen;
-            SendMessage(ac_list_hwnd, LB_SETHORIZONTALEXTENT,
-                        (WPARAM) 10 * olen, (LPARAM) 0);
-        }
-    }
-    /* Remove all the lines from the queue */
-    for (i = 0; i < nqueue; i++) {
-        free(ac_stdout_lines[i]);
-        ac_stdout_lines[i] = NULL;
-    }
-    nqueue = 0;
-}
-
-/* Add the item to the Try popup menu
- */
-static void ac_append_menu_item(HMENU menu, UINT menu_id, char *name, int isdef, int enabled)
-{
-    MENUITEMINFO mii;
-    
-    ZeroMemory(&mii, sizeof(MENUITEMINFO));
-    mii.cbSize = sizeof(MENUITEMINFO);
-    mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
-    if (strlen(name)) {
-        mii.fType = MFT_STRING;
-        mii.wID = menu_id;
-        if (isdef)
-            mii.fState = MFS_DEFAULT;
-        if (!enabled)
-            mii.fState |= MFS_DISABLED;
-        mii.dwTypeData = name;
-    }
-    else
-        mii.fType = MFT_SEPARATOR;
-    InsertMenuItem(menu, menu_id, FALSE, &mii);
-}
-
-/* Show the Try popup menu
- */
-static void ac_show_try_menu(HWND hwnd)
-{
-    HMENU menu;
-    POINT pt;
-    char tmp[MAX_LOADSTRING];
-
-    if (!ac_use_try)
-        return;
-    menu = CreatePopupMenu();
-    if (menu) {
-        if (ac_use_dlg) {
-            ac_append_menu_item(menu, IDM_CONSOLE, "Open Console Monitor", 1, 1);
-            ac_append_menu_item(menu, 0, "", 0, 1);
-        }
-        ac_append_menu_item(menu, IDM_ABOUT, "About", 0, 1);
-        ac_append_menu_item(menu, IDM_OPTIONS, "Properties", 0, 1);
-        strcpy(tmp, "Shutdown: ");
-        strcat(tmp, g_env->m->service.name);
-        ac_append_menu_item(menu, IDM_EXIT,  tmp, 0, 1);
-
-        if (!SetForegroundWindow(hwnd))
-            SetForegroundWindow(NULL);
-        GetCursorPos(&pt);
-        TrackPopupMenu(menu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, 
-                       pt.x, pt.y, 0, hwnd, NULL);
-        DestroyMenu(menu);
-    }
-}
-
-/* Sopy selected items from the console dialog
- * to the windows clipboard
- */
-static int ac_copy_to_clipboard()
-{
-    HGLOBAL hglbcopy = NULL; 
-    DWORD sel, i;
-    char buf[MAX_PATH + 2], *str; 
-    int *si = NULL;
-    
-    if (!OpenClipboard(NULL)) 
-        return -1; 
-    EmptyClipboard(); 
-
-    if (ac_use_lview) {
-        sel = ListView_GetSelectedCount(ac_list_hwnd);
-        if (sel != LB_ERR && sel > 0) {
-            int curr;
-            str = malloc((MAX_PATH+4)*sel);
-            str[0] = '\0';
-            curr = ListView_GetNextItem(ac_list_hwnd, -1, LVNI_SELECTED);
-            for (i = 0; i < sel && curr >= 0; i++) {
-                int j;
-                for(j=0; j < 3; j++) {
-                    ListView_GetItemText(ac_list_hwnd, curr, j, buf, MAX_PATH);
-                    strcat(buf, j < 2 ? "\t" : "\r\n");
-                    strcat(str, buf);
-                }
-                curr = ListView_GetNextItem(ac_list_hwnd, curr, LVNI_SELECTED);
-            }
-            sel = strlen(str);
-            if(sel > 0) {
-                hglbcopy = GlobalAlloc(GMEM_MOVEABLE, sel+1);
-                strcpy(GlobalLock(hglbcopy), str);
-            }
-            free(str);
-
-        }
-    }
-    else {
-        sel = SendMessage(ac_list_hwnd, LB_GETSELCOUNT, (WPARAM)0, (LPARAM)0);
-        if (sel != LB_ERR && sel > 0) {
-            si = (int *)malloc(sel * sizeof(int));
-            str = malloc((MAX_PATH + 2) * sel); 
-            str[0] = '\0';
-            SendMessage(ac_list_hwnd, LB_GETSELITEMS, (WPARAM)sel, (LPARAM)si);
-            for (i = 0; i < sel; i++) {
-                SendMessage(ac_list_hwnd, LB_GETTEXT, (WPARAM)si[i], (LPARAM)buf);
-                strcat(buf, "\r\n");
-                strcat(str, buf);
-            }
-            sel = strlen(str);
-            if(sel > 0) {
-                hglbcopy = GlobalAlloc(GMEM_MOVEABLE, sel+1);
-                strcpy(GlobalLock(hglbcopy), str);
-            }
-            free(str);
-            free(si);
-        }
-    }
-
-    if(hglbcopy != NULL) {
-        GlobalUnlock(hglbcopy);  
-        SetClipboardData(CF_TEXT, hglbcopy); 
-    }
-    CloseClipboard();
-    return 0;
-}
-
-/* Center the hwnd on the user desktop */
-void ac_center_window(HWND hwnd)
-{
-   RECT    rc, rw;
-   int     cw, ch;
-   int     x, y;
-   if (!ac_use_try)
-       return;
-
-   /* Get the Height and Width of the child window */
-   GetWindowRect(hwnd, &rc);
-   cw = rc.right - rc.left;
-   ch = rc.bottom - rc.top;
-
-   /* Get the limits of the 'workarea' */
-   if (!SystemParametersInfo(
-            SPI_GETWORKAREA,
-            sizeof(RECT),
-            &rw, 0)) {
-      rw.left = rw.top = 0;
-      rw.right = GetSystemMetrics(SM_CXSCREEN);
-      rw.bottom = GetSystemMetrics(SM_CYSCREEN);
-   }
-
-   /* Calculate new X and Y position*/
-   x = (rw.right - cw)/2;
-   y = (rw.bottom - ch)/2;
-   SetWindowPos(hwnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
-}
-
-static void ac_calc_center()
-{
-   RECT    rWorkArea;
-   BOOL    bResult;
-
-
-   /* Get the limits of the 'workarea' */
-   bResult = SystemParametersInfo(
-      SPI_GETWORKAREA,
-      sizeof(RECT),
-      &rWorkArea,
-      0);
-   if (!bResult) {
-      rWorkArea.left = rWorkArea.top = 0;
-      rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
-      rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
-   }
-
-   /* Calculate new X and Y position*/
-   ac_winpos.left = (rWorkArea.right - ac_winpos.right) / 2;
-   ac_winpos.top  = (rWorkArea.bottom - ac_winpos.bottom) / 2;
-}
-
-LRESULT CALLBACK ac_about_dlg_proc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
-    HWND hrich;
-    HRSRC rsrc;
-    HGLOBAL glob;
-    char *txt;
-
-    switch (message) {
-    case WM_INITDIALOG:
-        ac_center_window(hDlg);
-        hrich = GetDlgItem(hDlg, IDC_RICHEDIT21);
-        rsrc = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_RTFLIC), "RTF");
-        glob = LoadResource(GetModuleHandle(NULL), rsrc);
-        txt = (char *)LockResource(glob);
-        SendMessage(hrich, WM_SETTEXT, 0, (LPARAM)txt);
-        return TRUE;
-
-    case WM_COMMAND:
-        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
-            EndDialog(hDlg, LOWORD(wParam));
-            return TRUE;
-        }
-        break;
-    }
-    return FALSE;
-}
-
-LRESULT CALLBACK ac_console_dlg_proc(HWND hdlg, UINT message, WPARAM wparam, LPARAM lparam)
-{
-
-    RECT r, m;
-    static      HWND  status_bar; 
-
-    switch (message) {
-        case WM_INITDIALOG:
-           ac_console_hwnd = hdlg;
-           SetWindowText(hdlg, ac_cmdname);
-           ac_list_hwnd = GetDlgItem(hdlg, IDL_STDOUT);
-           if (ac_use_lview)
-               ShowWindow(ac_list_hwnd, SW_HIDE);
-           status_bar = CreateStatusWindow(0x0800 /* SBT_TOOLTIPS */
-                                          | WS_CHILD | WS_VISIBLE,
-                                            ac_cmdline, hdlg, IDC_STATBAR);
-  
-           if (!ac_use_try) { 
-               LONG w = GetWindowLong(hdlg, GWL_STYLE);
-               w &= ~WS_MINIMIZEBOX;
-               SetWindowLong(hdlg, GWL_STYLE, w);
-           }
-           
-           if (ac_winpos.left < 0)
-               ac_calc_center();
-
-           SetWindowPos(hdlg, HWND_TOP, ac_winpos.left, ac_winpos.top,
-                        ac_winpos.right, ac_winpos.bottom, SWP_SHOWWINDOW);
-                        
-           GetWindowRect(status_bar, &r);
-           GetClientRect(hdlg, &m);
-           if (!ac_use_lview)
-               MoveWindow(ac_list_hwnd, 0, 0, m.right - m.left, m.bottom - abs((r.top - r.bottom)), TRUE);
-           else
-               lv_create_view(hdlg, &m, &r);
-
-           ac_add_list_string(NULL, 0, 0);
-           SetForegroundWindow(ac_console_hwnd);
-           SetActiveWindow(ac_console_hwnd);
-
-           break;
-        case WM_SIZE:
-            switch (LOWORD(wparam)) { 
-                case SIZE_MINIMIZED:
-                    GetWindowRect(hdlg, &ac_winpos);
-                    if (!ac_use_try) {
-                        ShowWindow(hdlg, SW_RESTORE);
-                        return FALSE;
-                    }
-                    ShowWindow(hdlg, SW_HIDE);
-                    return TRUE; 
-                break;
-                default:
-                    GetWindowRect(status_bar, &r);
-                    MoveWindow(status_bar, 0, HIWORD(lparam) - (r.top - r.bottom),
-                                              LOWORD(lparam), (r.top - r.bottom), TRUE);
-                    GetClientRect(hdlg, &m);
-                    MoveWindow(ac_list_hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam) - abs((r.top - r.bottom)), TRUE);
-                    break;
-            }
-        break;
-        case WM_COMMAND:
-            switch (LOWORD(wparam)) {
-                case IDM_MENU_EXIT:
-                    EndDialog(hdlg, TRUE);
-                    ac_list_hwnd = NULL;
-                    ac_console_hwnd = NULL;
-                    ac_show_try_icon(ac_main_hwnd, NIM_MODIFY, ac_cmdname, 1);
-                    SetEvent(g_env->m->events[0]);
-                break;
-                case IDM_MENU_EDIT:
-                    ac_copy_to_clipboard();
-                break;
-                case IDM_MENU_ABOUT:
-                    DialogBox(ac_instance, MAKEINTRESOURCE(IDD_ABOUTBOX),
-                              hdlg, (DLGPROC)ac_about_dlg_proc);
-                break;
-            }
-            break;
-        case WM_QUIT:
-        case WM_CLOSE:
-            GetWindowRect(hdlg, &ac_winpos);
-            if (!ac_use_try) {
-                EndDialog(hdlg, TRUE);
-                ac_list_hwnd = NULL;
-                ac_console_hwnd = NULL;
-                SetEvent(g_env->m->events[0]);
-                PostQuitMessage(CONWRAP_SUCCESS);
-            }
-            else
-                ShowWindow(ac_console_hwnd, SW_HIDE);
-            return TRUE;
-        default:
-            return FALSE;
-    }
-
-    return FALSE;
-}
-
-/* Browse dialog.
- * Brose either for file or folder.
- * TODO: add some file filters.
- */
-int ac_browse_for_dialog(HWND hwnd, char *str, size_t len, int files)
-{
-    int rv = 0;
-
-    BROWSEINFO bi;
-    ITEMIDLIST *il , *ir;
-    LPMALLOC pMalloc;
-    
-    memset(&bi, 0, sizeof(BROWSEINFO));
-    SHGetSpecialFolderLocation(hwnd, CSIDL_DRIVES, &il);
-    if (files)
-        bi.lpszTitle  = PROCRUN_GUI_DISPLAY " :\nSelect Folder!";
-    else
-        bi.lpszTitle  = PROCRUN_GUI_DISPLAY " :\nSelect File!";
-    bi.pszDisplayName = str;
-    bi.hwndOwner =      hwnd;
-    bi.ulFlags =        BIF_EDITBOX;
-    if (files)
-        bi.ulFlags |=   BIF_BROWSEINCLUDEFILES;
-
-    bi.lpfn =           NULL;
-    bi.lParam =         0;
-    bi.iImage =         0;
-    bi.pidlRoot =       il;
-    
-    if ((ir = SHBrowseForFolder(&bi)) != NULL) {
-        SHGetPathFromIDList(ir, str);
-
-        rv = 1;
-    }
-    if (SHGetMalloc(&pMalloc)) {
-        pMalloc->lpVtbl->Free(pMalloc, il);
-        pMalloc->lpVtbl->Release(pMalloc);
-    }
-    return rv;
-    
-}
-
-/* Service option dialogs
- */
-void CALLBACK PropSheetCallback(HWND hwndPropSheet, UINT uMsg, LPARAM lParam)
-{
-    switch(uMsg) {
-        case PSCB_PRECREATE:       
-           {
-                LPDLGTEMPLATE  lpTemplate = (LPDLGTEMPLATE)lParam;
-                if (!(lpTemplate->style & WS_SYSMENU))
-                    lpTemplate->style |= WS_SYSMENU;
-
-            }
-        break;
-        case PSCB_INITIALIZED:
-        break;
-
-    }
-}
-
-LRESULT CALLBACK dlg_service_proc(HWND hdlg,
-                                  UINT uMessage,
-                                  WPARAM wParam,
-                                  LPARAM lParam)
-{
-
-    LPNMHDR     lpnmhdr;
-    int argc = 2;
-    char *argv[10];
-    char txt[4096];
-    process_t p;
-
-    switch (uMessage) {
-        case WM_COMMAND:
-            PropSheet_Changed(GetParent(hdlg), hdlg);
-            switch (LOWORD(wParam))  {
-                case RC_BTN_BIP:
-                    if (ac_browse_for_dialog(hdlg, txt, 1024, 1))
-                        SetDlgItemText(hdlg, RC_TXT_IP,
-                                       txt);
-                    return TRUE;
-                break;
-                case RC_BTN_BWP:
-                    if (ac_browse_for_dialog(hdlg, txt, 1024, 0))
-                        SetDlgItemText(hdlg, RC_TXT_WP,
-                                       txt);
-                    return TRUE;
-                break;
-            }
-        break;
-        case WM_INITDIALOG:
-            ac_center_window(GetParent(hdlg));
-            SetDlgItemText(hdlg, RC_TXT_SN, g_env->m->service.display ? 
-                           g_env->m->service.display : g_env->m->service.name);
-            SetDlgItemText(hdlg, RC_TXT_SD, g_env->m->service.description);
-            SetDlgItemText(hdlg, RC_TXT_IP, g_env->m->service.image);
-            SetDlgItemText(hdlg, RC_TXT_WP, g_env->m->service.path);
-            SetDlgItemText(hdlg, RC_TXT_UN, g_env->m->service.account);
-            SetDlgItemText(hdlg, RC_TXT_UP, g_env->m->service.password);
-            if (g_env->m->service.startup == SERVICE_AUTO_START)
-                CheckDlgButton(hdlg, RC_CHK_AUTO, BST_CHECKED);
-
-        break;
-
-        case WM_NOTIFY:
-            lpnmhdr = (NMHDR FAR *)lParam;
-
-            switch (lpnmhdr->code) {
-                case PSN_APPLY:   /* sent when OK or Apply button pressed */
-                memcpy(&p, g_env->m, sizeof(process_t));
-                p.pool = pool_create();
-                p.service.name = g_env->m->service.name;
-                argc = 2;
-                if (GetDlgItemText(hdlg, RC_TXT_SD, txt, 4095) > 0) {
-                    argv[argc++] = "--" PROCRUN_PARAMS_DESCRIPTION;
-                    argv[argc++] = &txt[0];
-                    argv[argc] = NULL;
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_IP, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_IMAGE;
-                    argv[argc++] = &txt[0];
-                    argv[argc] = NULL;
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_WP, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_WORKPATH;
-                    argv[argc++] = &txt[0];
-                    argv[argc] = NULL;
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_UN, txt, 64) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_ACCOUNT;
-                    argv[argc++] = &txt[0];
-                    argv[argc] = NULL;
-                    if (GetDlgItemText(hdlg, RC_TXT_UP, &txt[128], 64) > 0) {
-                        argv[argc++] = "--" PROCRUN_PARAMS_PASSWORD;
-                        argv[argc++] = &txt[128];
-                        procrun_update_service(&p, argc, argv);
-                    }
-                }
-                else if (g_env->m->service.account) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_ACCOUNT;
-                    argv[argc++] = "-";
-                    argv[argc++] = "--" PROCRUN_PARAMS_PASSWORD;
-                    argv[argc++] = "-";
-                    argv[argc] = NULL;
-                    procrun_update_service(&p, argc, argv);
-                }
-                /* TODO: check if the param is changed */
-                argc = 2;
-                argv[argc++] = "--" PROCRUN_PARAMS_STARTUP;
-                if (IsDlgButtonChecked(hdlg, RC_CHK_AUTO))
-                    argv[argc++] = "auto";
-                else
-                    argv[argc++] = "manual";
-
-                argv[argc] = NULL;
-                procrun_update_service(&p, argc, argv);
-                pool_destroy(p.pool);
-                break;
-                case PSN_RESET:   /* sent when Cancel button pressed */
-                break;         
-                default:
-                break;
-            }
-        break;
-        default:
-        break;
-    }
-
-    return FALSE;
-}
-
-LRESULT CALLBACK dlg_java_proc(HWND hdlg,
-                               UINT uMessage,
-                               WPARAM wParam,
-                               LPARAM lParam)
-{
-
-    LPNMHDR     lpnmhdr;
-    int argc = 2;
-    char *argv[10];
-    char txt[4096];
-    process_t p;
-    char *s, *d;
-
-    switch (uMessage) {
-        case WM_COMMAND:
-            PropSheet_Changed(GetParent(hdlg), hdlg);
-            switch (LOWORD(wParam))  {
-                case RC_BTN_JVM:
-                    if (ac_browse_for_dialog(hdlg, txt, 1024, 1))
-                        SetDlgItemText(hdlg, RC_TXT_JVM,
-                                       txt);
-                    return TRUE;
-                break;
-            }
-
-        break;
-        case WM_INITDIALOG:
-            SetDlgItemText(hdlg, RC_TXT_JVM, g_env->m->java.display);
-            sprintf(txt, "%s;%s;%s", g_env->m->java.start_class,
-                                     g_env->m->java.start_method,
-                                     g_env->m->java.start_param);
-            SetDlgItemText(hdlg, RC_TXT_SC, txt);
-            sprintf(txt, "%s;%s;%s", g_env->m->java.stop_class,
-                                     g_env->m->java.stop_method,
-                                     g_env->m->java.stop_param);
-            SetDlgItemText(hdlg, RC_TXT_EC, txt);
-            if (g_env->m->java.display &&
-                !strcmp(g_env->m->java.display, "auto"))
-                CheckDlgButton(hdlg, RC_CHK_JVM, BST_CHECKED);
-            
-            memset(txt, 0, 4096);
-            d = &txt[0];
-            for (s = g_env->m->java.opts; s && *s; s++) {
-                sprintf(d, "%s\r\n", s);
-                d += strlen(d);
-                while (*s)
-                    s++;
-            }
-            SetDlgItemText(hdlg, RC_TXT_JO, txt);
-        break;
-        case WM_NOTIFY:
-            lpnmhdr = (NMHDR FAR *)lParam;
-
-            switch (lpnmhdr->code) {
-                case PSN_APPLY:   /* sent when OK or Apply button pressed */
-                memcpy(&p, g_env->m, sizeof(process_t));
-                argc = 2;
-                p.pool = pool_create();
-                if (IsDlgButtonChecked(hdlg, RC_CHK_JVM)) {
-                    argv[argc++] = "--" PROCRUN_PARAMS_JVM;
-                    argv[argc++] = "auto";
-                }
-                else if (GetDlgItemText(hdlg, RC_TXT_JVM, txt, 4095) > 0) {
-                    argv[argc++] = "--" PROCRUN_PARAMS_JVM;
-                    argv[argc++] = &txt[0];
-                }
-                if (argc > 2)
-                    procrun_update_service(&p, argc, argv);
-
-                if (GetDlgItemText(hdlg, RC_TXT_SC, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_STARTCLASS;
-                    argv[argc++] = &txt[0];
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_EC, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_STOPCLASS;
-                    argv[argc++] = &txt[0];
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_JO, txt, 4095) > 0) {
-                    char *c = &txt[0];
-                    char b[4096] = {0};
-                    int i = 0;
-                    argc = 2;
-                    while (*c) {
-                        if (*c == '\n')
-                            b[i++] = '#';
-                        else if (*c != '\r')
-                            b[i++] = *c;
-                        ++c;
-                    }
-                    b[i] = '\0';
-                    argv[argc++] = "--" PROCRUN_PARAMS_JVM_OPTS;
-                    argv[argc++] = &b[0];
-                    procrun_update_service(&p, argc, argv);
-                }
-                pool_destroy(p.pool);
-                break;
-                case PSN_RESET:   /* sent when Cancel button pressed */
-                break;         
-                default:
-                break;
-            }
-        break;
-        default:
-        break;
-    }
-
-    return FALSE;
-}
-
-LRESULT CALLBACK dlg_stream_proc(HWND hdlg,
-                                 UINT uMessage,
-                                 WPARAM wParam,
-                                 LPARAM lParam)
-{
-
-    LPNMHDR     lpnmhdr;
-    int argc = 2;
-    char *argv[10];
-    char txt[4096];
-    process_t p;
-
-    switch (uMessage) {
-        case WM_COMMAND:
-            PropSheet_Changed(GetParent(hdlg), hdlg);
-            switch (LOWORD(wParam))  {
-                case RC_BTN_STDI:
-                    if (ac_browse_for_dialog(hdlg, txt, 1024, 1))
-                        SetDlgItemText(hdlg, RC_TXT_STDI,
-                                       txt);
-                    return TRUE;
-                break;
-                case RC_BTN_STDO:
-                    if (ac_browse_for_dialog(hdlg, txt, 1024, 1))
-                        SetDlgItemText(hdlg, RC_TXT_STDO,
-                                       txt);
-                    return TRUE;
-                break;
-                case RC_BTN_STDE:
-                    if (ac_browse_for_dialog(hdlg, txt, 1024, 1))
-                        SetDlgItemText(hdlg, RC_TXT_STDE,
-                                       txt);
-                    return TRUE;
-                break;
-            }
-
-        break;
-        case WM_INITDIALOG:
-            SetDlgItemText(hdlg, RC_TXT_STDI, g_env->m->service.inname);
-            SetDlgItemText(hdlg, RC_TXT_STDO, g_env->m->service.outname);
-            SetDlgItemText(hdlg, RC_TXT_STDE, g_env->m->service.errname);
-
-        break;
-
-        case WM_NOTIFY:
-            lpnmhdr = (NMHDR FAR *)lParam;
-
-            switch (lpnmhdr->code) {
-                case PSN_APPLY:   /* sent when OK or Apply button pressed */
-                memcpy(&p, g_env->m, sizeof(process_t));
-                p.pool = pool_create();
-                if (GetDlgItemText(hdlg, RC_TXT_STDI, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_STDINFILE;
-                    argv[argc++] = &txt[0];
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_STDO, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_STDOUTFILE;
-                    argv[argc++] = &txt[0];
-                    procrun_update_service(&p, argc, argv);
-                }
-                if (GetDlgItemText(hdlg, RC_TXT_STDE, txt, 4095) > 0) {
-                    argc = 2;
-                    argv[argc++] = "--" PROCRUN_PARAMS_STDERRFILE;
-                    argv[argc++] = &txt[0];
-                    procrun_update_service(&p, argc, argv);
-                }
-                pool_destroy(p.pool);
-
-                break;
-                case PSN_RESET:   /* sent when Cancel button pressed */
-                break;         
-                default:
-                break;
-            }
-        break;
-        default:
-        break;
-    }
-
-    return FALSE;
-}
-
-
-INT_PTR ac_show_properties(HWND owner)
-{
-    PROPSHEETPAGE psp[3];
-    PROPSHEETHEADER psh;
-    char title[256];
-
-    strcpy(title, ac_cmdline);
-    strcat(title, " Service properties");
-    psp[0].dwSize        = sizeof(PROPSHEETPAGE);
-    psp[0].dwFlags       = PSP_USETITLE;
-    psp[0].hInstance     = ac_instance;
-    psp[0].pszTemplate   = MAKEINTRESOURCE(RC_DLG_SRVOPT);
-    psp[0].pszIcon       = NULL;
-    psp[0].pfnDlgProc    = (DLGPROC)dlg_service_proc;
-    psp[0].pszTitle      = TEXT("Service");
-    psp[0].lParam        = 0;
-
-    psp[1].dwSize        = sizeof(PROPSHEETPAGE);
-    psp[1].dwFlags       = PSP_USETITLE;
-    psp[1].hInstance     = ac_instance;
-    psp[1].pszTemplate   = MAKEINTRESOURCE(RC_DLG_JVMOPT);
-    psp[1].pszIcon       = NULL;
-    psp[1].pfnDlgProc    = (DLGPROC)dlg_java_proc;
-    psp[1].pszTitle      = TEXT("Java VM");
-    psp[1].lParam        = 0;
-
-    psp[2].dwSize        = sizeof(PROPSHEETPAGE);
-    psp[2].dwFlags       = PSP_USETITLE;
-    psp[2].hInstance     = ac_instance;
-    psp[2].pszTemplate   = MAKEINTRESOURCE(RC_DLG_STDOPT);
-    psp[2].pszIcon       = NULL;
-    psp[2].pfnDlgProc    = (DLGPROC)dlg_stream_proc;
-    psp[2].pszTitle      = TEXT("Standard Streams");
-    psp[2].lParam        = 0;
-
-    psh.dwSize           = sizeof(PROPSHEETHEADER);
-    psh.dwFlags          = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
-    psh.hwndParent       = owner;
-    psh.hInstance        = ac_instance;
-    psh.pszIcon          = MAKEINTRESOURCE(IDI_ICOCONWRAP);
-#if (_WIN32_IE >= 0x0500)
-    psh.pszbmHeader      = MAKEINTRESOURCE(IDB_BMPJAKARTA);
-#endif
-    psh.pszCaption       = title;
-    psh.nPages           = sizeof(psp) / sizeof(PROPSHEETPAGE);
-    psh.ppsp             = (LPCPROPSHEETPAGE) &psp;
-    psh.pfnCallback      = (PFNPROPSHEETCALLBACK)PropSheetCallback;
-    psh.nStartPage       = 0;
-    return PropertySheet(&psh);
-}
-
-
-LRESULT CALLBACK ac_splash_dlg_proc(HWND hdlg, UINT message, WPARAM wparam, LPARAM lparam)
-{
-
-    switch (message) {
-        case WM_INITDIALOG:
-           ac_splash_hwnd = hdlg;
-           ac_center_window(hdlg);
-           ac_splist_hwnd = GetDlgItem(hdlg, IDL_INFO); 
-           break;
-    }
-
-    return FALSE;
-}
-
-/* main (invisible) window procedure
- *
- */
-LRESULT CALLBACK ac_main_wnd_proc(HWND hwnd, UINT message,
-                          WPARAM wparam, LPARAM lparam)
-{
-    if (message == ac_taskbar_created) {
-        /* restore the tray icon on shell restart */
-        ac_show_try_icon(hwnd, NIM_ADD, ac_cmdname, 0);
-        return DefWindowProc(hwnd, message, wparam, lparam);
-    }
-    switch (message) {
-        case WM_CREATE:
-            ac_main_hwnd = hwnd;
-            if (ac_use_props) {
-                PostMessage(hwnd, WM_COMMAND, IDM_OPTIONS, 0);
-                return FALSE;
-            }
-
-            if (ac_use_try)
-                ac_show_try_icon(hwnd, NIM_ADD, ac_cmdname, 1);
-            /* add the 20 s timer for startup to avoid zombie spash 
-             * if something goes wrong.
-             */
-            SetTimer(hwnd, WM_TIMER_TIMEOUT, ac_splash_timeout, NULL);
-            if (ac_use_try) {
-                DialogBox(ac_instance, MAKEINTRESOURCE(IDD_DLGSPLASH),
-                    hwnd, (DLGPROC)ac_splash_dlg_proc);
-            }
-            if (ac_use_show) {
-                DialogBox(ac_instance, MAKEINTRESOURCE(IDD_DLGCONSOLE),
-                          hwnd, (DLGPROC)ac_console_dlg_proc);
-            }
-            break;
-        case WM_TIMER:
-            switch (wparam) {
-                case WM_TIMER_TIMEOUT:
-                    if (ac_use_try)
-                        ac_show_try_icon(hwnd, NIM_MODIFY, ac_cmdname, 0);
-                    if (ac_use_try && ac_splash_hwnd)
-                        EndDialog(ac_splash_hwnd, TRUE);
-                break;
-            }
-            break;
-        case WM_DESTROY:
-        case WM_QUIT:
-            if (ac_use_try);
-                ac_show_try_icon(hwnd, NIM_DELETE, NULL, 0);
-            SetEvent(g_env->m->events[0]);
-            break;
-        case WM_TRAYMESSAGE:
-            switch(lparam) {
-                case WM_LBUTTONDBLCLK:
-                   if (ac_console_hwnd) {
-                        ShowWindow(ac_console_hwnd, SW_SHOW);
-                        ShowWindow(ac_console_hwnd, SW_RESTORE);
-                   }
-                   else
-                       DialogBox(ac_instance, MAKEINTRESOURCE(IDD_DLGCONSOLE),
-                                 hwnd, (DLGPROC)ac_console_dlg_proc); 
-                   SetForegroundWindow(ac_console_hwnd);
-                   SetActiveWindow(ac_console_hwnd);
-                break;
-                case WM_RBUTTONUP:
-                    ac_show_try_menu(hwnd);
-                break;    
-            }
-            break;
-        case WM_COMMAND:
-            switch (LOWORD(wparam)) {
-               case IDM_EXIT:
-                   ac_show_try_icon(hwnd, NIM_MODIFY, ac_cmdname, 1);
-                   SetEvent(g_env->m->events[0]);
-                   return TRUE;
-                   break;
-               case IDM_CONSOLE:
-                   if (ac_console_hwnd) {
-                        ShowWindow(ac_console_hwnd, SW_SHOW);
-                        ShowWindow(ac_console_hwnd, SW_RESTORE);
-                   }
-                   else
-                       DialogBox(ac_instance, MAKEINTRESOURCE(IDD_DLGCONSOLE),
-                                 hwnd, (DLGPROC)ac_console_dlg_proc);                   
-                   break;
-               case IDM_ABOUT:
-                       DialogBox(ac_instance, MAKEINTRESOURCE(IDD_ABOUTBOX),
-                                 hwnd, (DLGPROC)ac_about_dlg_proc);                   
-                   break;
-               case IDM_OPTIONS:
-                    ac_show_properties(NULL);
-                    if (ac_use_props)                               
-                        PostMessage(hwnd, WM_QUIT, 0, 0);
-
-                   break;
-            }
-        default:
-            return DefWindowProc(hwnd, message, wparam, lparam);
-    }
-
-    return FALSE;
-}
-
-/* Create main invisible window */
-static HWND ac_create_main_window(HINSTANCE instance, const char *wclass, const char *title)
-{
-    HWND       hwnd = NULL;
-    WNDCLASSEX wcex;
-
-    wcex.cbSize = sizeof(WNDCLASSEX); 
-
-    wcex.style          = CS_HREDRAW | CS_VREDRAW;
-    wcex.lpfnWndProc    = ac_main_wnd_proc;
-    wcex.cbClsExtra     = 0;
-    wcex.cbWndExtra     = 0;
-    wcex.hInstance      = instance;
-    wcex.hIcon          = ac_main_icon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_ICOCONWRAP),
-                                                IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
-    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
-    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
-    wcex.lpszMenuName   = 0;
-    wcex.lpszClassName  = wclass;
-    wcex.hIconSm        = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_ICOCONWRAP),
-                                           IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-    ac_try_icon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_ICOCONTRY),
-                                           IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-    ac_try_stop = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_ICOCONTRYSTOP),
-                                           IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-    if (RegisterClassEx(&wcex))
-        hwnd = CreateWindow(wclass, title,
-                            0, 0, 0, 0, 0,
-                            NULL, NULL, instance, NULL);
-
- 
-    return hwnd;
-
-}
-
-/* Main GUI application thread
- * launched from procrun_main.
- */
-DWORD WINAPI gui_thread(LPVOID param)
-{
-    DWORD rv = 0;
-    MSG   msg;
-    /* single instance mutex */
-    HANDLE mutex;
-
-    procrun_t *env = ac_env = (procrun_t *)param;
-    char cname[MAX_LOADSTRING];
-    char cmutex[MAX_PATH];
-
-    if (!param || !env->m->service.name)
-        return -1;
-    strcpy(cname, env->m->service.name);
-    strcat(cname, "_CLASS");
-    strcpy(cmutex, env->m->service.name);
-    strcat(cmutex, "_MUTEX");
-    if (env->m->service.description)
-        ac_cmdline = env->m->service.description;
-    else
-        ac_cmdline = env->m->service.name;
-    if (env->m->service.display)
-        ac_cmdname = env->m->service.display;
-    else
-        ac_cmdname = env->m->service.name;
-    
-    /* Ensure that only one instance of a service is running 
-     * TODO: Allow the //ES// and //MS// to run withouth that
-     *       restriction, but reather use that mutex to signal
-     *       the //GT// of a params change.
-     */
-    mutex = CreateMutex(NULL, FALSE, cmutex);
-    if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
-        char msg[2048];
-        sprintf(msg, "Starting: %s\nApplication is already running",
-                env->m->service.name);
-        MessageBox(NULL, msg, "Second instance", 
-                   MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
-        if (mutex)
-            CloseHandle(mutex);
-        SetEvent(env->m->events[0]);
-        return 0;
-    }
-
-#if defined(PROCRUN_EXTENDED)
-    /* Init all the extended properties
-     * like splash, listview, etc..
-     *
-     */
-    acx_init_extended();
-#endif
-    ac_main_hwnd = ac_create_main_window(ac_instance, cname, 
-                                         env->m->service.name);
-
-    InitCommonControls();
-    if (ac_main_hwnd) {
-        if (ac_use_try)
-            ac_taskbar_created = RegisterWindowMessage("TaskbarCreated");
-        /* Main message loop */
-        while (GetMessage(&msg, NULL, 0, 0)) {
-            TranslateMessage(&msg);
-            DispatchMessage(&msg);
-        }    
-    }
-    if (mutex)
-        CloseHandle(mutex);
-    ac_main_hwnd = NULL;
-    /* Signal to procrun_main we are done */
-    SetEvent(env->m->events[0]);
-    return rv;
-}
-
-#endif /* PROCRUN_WINAPP */
diff --git a/src/native/nt/procrun/procrun.c b/src/native/nt/procrun/procrun.c
deleted file mode 100644
index 0f5de34..0000000
--- a/src/native/nt/procrun/procrun.c
+++ /dev/null
@@ -1,3306 +0,0 @@
-/* ====================================================================
-     Copyright 2002-2004 The Apache Software Foundation.
-   
-     Licensed 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.
-*/
-
-/* ====================================================================
- * procrun
- *
- * Contributed by Mladen Turk <mturk at apache.org>
- *
- * 05 Aug 2002
- * ==================================================================== 
- */
-
-#ifndef STRICT
-#define STRICT
-#endif
-#ifndef OEMRESOURCE
-#define OEMRESOURCE
-#endif
-
-#include <windows.h>
-#include <windowsx.h>
-#include <commctrl.h>
-#include <objbase.h>
-#include <shlobj.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <Shlwapi.h>
-#include <io.h>
-#include <fcntl.h>
-#include <process.h>
-#include <time.h>
-#include <stdarg.h>
-#include <jni.h>
- 
-#include "procrun.h"
-
-typedef HANDLE (__stdcall * PFNCREATERTHRD)(HANDLE, LPSECURITY_ATTRIBUTES, 
-                                            DWORD, LPTHREAD_START_ROUTINE,
-                                            LPVOID, DWORD, LPDWORD); 
-typedef jint (JNICALL *JNI_GETDEFAULTJAVAVMINITARGS)(void *);
-typedef jint (JNICALL *JNI_CREATEJAVAVM)(JavaVM **, JNIEnv **, void *);
-typedef jint (JNICALL *JNI_GETCREATEDJAVAVMS)(JavaVM **, int, int *);
-
-JNI_GETDEFAULTJAVAVMINITARGS jni_JNI_GetDefaultJavaVMInitArgs = NULL;
-JNI_CREATEJAVAVM jni_JNI_CreateJavaVM = NULL;
-JNI_GETCREATEDJAVAVMS jni_JNI_GetCreatedJavaVMs = NULL;
-
-int report_service_status(DWORD, DWORD, DWORD, process_t *); 
-int procrun_redirect(char *program, char **envp, procrun_t *env, int starting);
-
-static int g_proc_stderr_file = 0;
-int g_proc_mode = 0;
-/* The main envronment for services */
-procrun_t *g_env = NULL;
-static int g_is_windows_nt = 0;
-
-#ifdef PROCRUN_WINAPP
-
-
-#endif
-
-#ifdef _DEBUG
-void log_write(char *string)
-{
-    FILE *fd;
-    fd = fopen("c:\\jakarta-service.txt","a");
-    if (fd == NULL)
-    return;
-    fprintf(fd,string);
-    if (string[strlen(string)-1]!='\n')
-        fprintf(fd,"\n");
-    fclose(fd);
-}
-void dbprintf(char *format, ...)
-{
-    va_list args;
-    char tid[4096 + 128];
-    char buffer[4096];
-    int len;
-
-    if (!format) {
-        len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 
-                            FORMAT_MESSAGE_IGNORE_INSERTS,
-                            NULL,
-                            GetLastError(),
-                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                            buffer,
-                            4096,
-                            NULL);
-    }
-    else {
-        va_start(args, format);
-        len = _vsnprintf(buffer, 4096, format, args);
-        va_end(args);
-    }
-    if (len > 0) {
-        sprintf(tid, "[%04X:%08d] %s", GetCurrentThreadId(),time(NULL), buffer);
-        if (g_proc_stderr_file > 0)
-            write(g_proc_stderr_file, tid, strlen(tid));
-        else
-            fprintf(stderr,tid);
-    log_write(tid);
-#ifdef _DEBUG_TRACE
-        OutputDebugString(tid);
-#endif
-    }
-}
-#define DBPRINTF0(v1)               dbprintf(v1)
-#define DBPRINTF1(v1, v2)           dbprintf(v1, v2)
-#define DBPRINTF2(v1, v2, v3)       dbprintf(v1, v2, v3)
-#else
-#define DBPRINTF0(v1)
-#define DBPRINTF1(v1, v2)
-#define DBPRINTF2(v1, v2, v3)
-#endif
-
-/* Create the memory pool.
- * Memory pool is fixed size (PROC_POOL_SIZE -> 128 by default)
- * It ensures that all the memory and HANDELS gets freed
- * when the procrun exits
- */
-pool_t *pool_create()
-{
-    pool_t *pool = malloc(sizeof(pool_t));
-    if (pool) {
-        InitializeCriticalSection(&pool->lock);
-        pool->size = 0;
-        pool->mp[0].m = NULL;
-        pool->mp[0].h = NULL;
-    }
-    return pool;
-}
-
-/* Destroy the memory pool
- * each pool slot can have allocated memory block
- * and/or associated windows HANDLE that can be
- * release with CloseHandle.
- */
-int pool_destroy(pool_t *pool)
-{
-    int i = 0;
-    for (i = 0; i < pool->size; i++) {
-        if (pool->mp[i].m) {
-            free(pool->mp[i].m);
-        }
-        if (pool->mp[i].h != INVALID_HANDLE_VALUE && pool->mp[i].h != NULL) {
-            CloseHandle(pool->mp[i].h);
-        }
-    }
-    DeleteCriticalSection(&pool->lock);
-    free(pool);
-    return i;
-}
-
-/*  Allocation functions
- *  They doesn't check for overflow
- */
-static void *pool_alloc(pool_t *pool, size_t size)
-{
-    void *m = malloc(size);
-    EnterCriticalSection(&pool->lock);
-    pool->mp[pool->size].h = INVALID_HANDLE_VALUE;
-    pool->mp[pool->size++].m = m;
-    LeaveCriticalSection(&pool->lock);
-    return m;
-}
-
-static void *pool_calloc(pool_t *pool, size_t size)
-{
-    void *m = calloc(size, 1);
-    EnterCriticalSection(&pool->lock);
-    pool->mp[pool->size].h = INVALID_HANDLE_VALUE;
-    pool->mp[pool->size++].m = m;
-    LeaveCriticalSection(&pool->lock);
-    return m;
-}
-
-static char *pool_strdup(pool_t *pool, const char *src)
-{
-    char *s = strdup(src);
-    EnterCriticalSection(&pool->lock);
-    pool->mp[pool->size].h = INVALID_HANDLE_VALUE;
-    pool->mp[pool->size++].m = s;
-    LeaveCriticalSection(&pool->lock);
-    return s;
-}
-
-/* Attach the Handle to the pool
- * The handle will be released on pool_destroy
- * using CloseHandle API call
- */
-static void *pool_handle(pool_t *pool, HANDLE h)
-{
-    EnterCriticalSection(&pool->lock);
-    pool->mp[pool->size].h = h;
-    pool->mp[pool->size++].m = NULL;
-    LeaveCriticalSection(&pool->lock);
-    return h;
-}
-
-static BOOL pool_close_handle(pool_t *pool, HANDLE h)
-{
-    int i;
-    EnterCriticalSection(&pool->lock);
-    for(i=0; i < pool->size; i++) {
-        if(pool->mp[i].h == h) 
-            pool->mp[i].h = INVALID_HANDLE_VALUE;
-    }
-    LeaveCriticalSection(&pool->lock);
-    return CloseHandle(h);
-}
-
-/* Very simple encryption for hiding password
- * they can be easily decrypted cause the key
- * is hadcoded (100) in the code.
- * It can be easily cracked if someone finds that needed.
- * XXX: The solution is to either use the CryproAPI
- * or our own account management.
- */
-static void simple_encrypt(int seed, const char *str, unsigned char bytes[256])
-{
-    int i;
-    char sc[256];
-
-    srand(seed);
-    memset(sc, 0, 256);
-    strncpy(sc, str, 255);
-    for (i = 0; i < 256; i ++) {
-        bytes[i] = ((rand() % 256) ^ sc[i]);
-    }
-}
-
-static void simple_decrypt(int seed, char *str, unsigned char bytes[256])
-{
-    int i;
-    char sc[256];
-
-    srand(seed);
-    for (i = 0; i < 256; i ++) {
-        sc[i] = ((rand() % 256) ^ bytes[i]);
-    }
-    strcpy(str, sc);
-}
-
-/* Injects the 'ExitProcess' to the child
- * The function tries to kill the child process
- * without using 'hard' mathods like TerminateChild.
- * At first it sends the CTRL+C and CTRL+BREAK to the
- * child process. If that fails (the child doesn't exit)
- * it creates the remote thread in the address space of
- * the child process, and calls the ExitProcess function,
- * inside the child process.
- * Finaly it calls the TerminateProcess all of the above
- * fails.
- * Well designed console clients usually exits on closing
- * stdin stream, so this function not be called in most cases.
- */
-static void inject_exitprocess(PROCESS_INFORMATION *child) 
-{
-    PFNCREATERTHRD pfn_CreateRemoteThread;
-    UINT exit_code = 2303;
-    HANDLE rt = NULL, dup = NULL;
-    DWORD  rtid, stat;
-    BOOL isok;
-
-    if (!child || !child->hProcess) {
-        DBPRINTF0("No process\n");
-        return;
-    }
-    if (!GetExitCodeProcess(child->hProcess, &stat) || 
-        (stat != STILL_ACTIVE)) {
-            DBPRINTF1("The child process %d isn't active any more\n",
-                     child->dwProcessId);
-            child->hProcess = NULL;
-            child->dwProcessId = 0;
-            return;
-    } 
-    GenerateConsoleCtrlEvent(CTRL_C_EVENT, child->dwProcessId);
-    GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, child->dwProcessId);
-#if 1
-    /* Wait for a child to capture CTRL_ events. */
-    WaitForSingleObject(child->hThread, 2000);
-#endif
-    if (!GetExitCodeProcess(child->hProcess, &stat) || 
-        (stat != STILL_ACTIVE)) {
-            child->hProcess = NULL;
-            child->dwProcessId = 0;
-            DBPRINTF0("Breaked by CTRL+C event\n");
-            return;
-    } 
-    DBPRINTF1("Injecting ExitProcess to the child process %d\n",
-             child->dwProcessId);
-
-    pfn_CreateRemoteThread = (PFNCREATERTHRD)GetProcAddress(
-                                             GetModuleHandle("KERNEL32.DLL"),
-                                            "CreateRemoteThread");
-
-    isok = DuplicateHandle(GetCurrentProcess(), 
-                           child->hProcess, 
-                           GetCurrentProcess(), 
-                           &dup, 
-                           PROCESS_ALL_ACCESS, 
-                           FALSE, 0);
-    isok = GetExitCodeProcess((isok) ? dup : child->hProcess, &stat);
-    if (pfn_CreateRemoteThread) {        
-        FARPROC pfnExitProc;
-        if (isok && stat == STILL_ACTIVE) { 
-           
-            pfnExitProc = GetProcAddress(GetModuleHandle("KERNEL32.DLL"),
-                                         "ExitProcess");
-            rt = pfn_CreateRemoteThread(child->hProcess, 
-                                        NULL, 
-                                        0, 
-                                        (LPTHREAD_START_ROUTINE)pfnExitProc,
-                                        (PVOID)exit_code, 0, &rtid);
-       }
-    }
-    else {
-        if (isok && stat == STILL_ACTIVE) {
-            DBPRINTF0("Could not CreateRemoteThread... Forcing TerminateProcess\n");
-            TerminateProcess(child->hProcess, exit_code);
-        }
-    }
-
-    if (rt) {
-        if (WaitForSingleObject(child->hProcess, 2000) == WAIT_OBJECT_0) {
-            CloseHandle(rt);
-            DBPRINTF0("Exited cleanly\n");
-        }
-        else {
-            DBPRINTF0("Forcing TerminateProcess\n");
-            TerminateProcess(child->hProcess, exit_code);
-        }
-    }
-    if (dup)
-        CloseHandle(dup);
-} 
-
-int __cdecl compare(const void *arg1, const void *arg2)
-{
-    return _stricoll(*((char **)arg1),*((char **)arg2));
-}
-
-/* Merge two char arrays and make
- * zero separated, double-zero terminated
- * string
- */
-static char * merge_arrays(char **one, char **two, process_t *proc)
-{
-    int len = 0, n, cnt = 0;
-    char *envp, *p;
-
-    for (n = 0; one[n]; n++) {
-        len += (strlen(one[n]) + 1);
-        cnt++;
-    }
-    for (n = 0; two[n]; n++) {
-        len += (strlen(two[n]) + 1);        
-        cnt++;
-    }
-    p = envp = (char *)pool_calloc(proc->pool, len + 1);
-
-    for (n = 0; one[n]; n++) {
-        strcpy(p, one[n]);
-        p += strlen(one[n]) + 1;
-    }
-    for (n = 0; two[n]; n++) {
-        strcpy(p, two[n]);
-        p += strlen(two[n]) + 1;
-    }
-    return envp;
-}
-
-/* Make the environment string
- * for the child process.
- * The original environment of the calling process
- * is merged with the current environment.
- */
-static char * make_environment(char **envarr, char **envorg, process_t *proc)
-{
-    int len = 0, n, cnt = 0;
-    char *envp, *p, **tmp;
-
-    for (n = 0; envarr[n]; n++) {
-        len += strlen(envarr[n]) + 1;
-        cnt++;
-    }
-    for (n = 0; envorg[n]; n++) {
-        len += strlen(envorg[n]) + 1;        
-        cnt++;
-    }
-    if (proc->java.jpath) {
-        len += strlen(proc->java.jpath) + 2;
-        cnt++;
-    }
-    p = envp = (char *)pool_calloc(proc->pool, len + 1);
-    if (!p)
-        return NULL;
-    tmp = (char **)calloc(cnt + 1, sizeof(char *));
-    cnt = 0;
-    for (n = 0; envarr[n]; n++) {
-            tmp[cnt++] = envarr[n];
-    }
-    for (n = 0; envorg[n]; n++) {
-        if (STRN_COMPARE(envorg[n], PROCRUN_ENV_STDIN)) {}
-        else if (STRN_COMPARE(envorg[n], PROCRUN_ENV_STDOUT)) {}
-        else if (STRN_COMPARE(envorg[n], PROCRUN_ENV_STDERR)) {}
-        else if (STRN_COMPARE(envorg[n], PROCRUN_ENV_PPID)) {}
-        else if (STRNI_COMPARE(envorg[n], "PATH=") && 
-                 proc->java.jpath) {
-            tmp[cnt] = pool_calloc(proc->pool, strlen(envorg[n]) +
-                                     strlen(proc->java.jpath) + 2);
-            strcpy(tmp[cnt], envorg[n]);
-            strcat(tmp[cnt], ";");
-            strcat(tmp[cnt], proc->java.jpath);
-            DBPRINTF1("New PATH %s", tmp[cnt]);
-            ++cnt;
-        }
-        else
-            tmp[cnt++] = envorg[n];
-    }
-    qsort((void *)tmp, (size_t)n, sizeof(char *), compare);
-    for (n = 0; tmp[n]; n++) {
-        strcpy(p, tmp[n]);
-        p += strlen(tmp[n]) + 1;
-    }
-    free(tmp);
-    return envp;
-}
-
-/* Make the character string array form
- * zero separated, double-zero terminated
- * strings. Those strings comes from some
- * Windows api calls, like GetEnvironmentStrings
- * This string format is also used in Registry (REG_MULTI_SZ)
- */
-static int make_array(const char *str, char **arr, int size, process_t *proc)
-{
-    int i = 0;
-    char *p;
-    
-    if (!str)
-        return 0;
-    for (p = (char *)str; p && *p; p++) {
-        arr[i] = pool_strdup(proc->pool, p);
-        while (*p)
-            p++;
-        i++;
-        if (i + 1 > size)
-            break;
-    }
-    return i;
-}
-
-/* Simple string unqouting
- * TODO: Handle multiqoutes.
- */
-static char *remove_quotes(char * string) {
-  char *p = string, *q = string;
-  while (*p) {
-    if(*p != '\"' && *p != '\'')
-      *q++ = *p;
-    ++p;
-  }
-  *q = '\0';
-  return string;
-}
-
-/*  Parse command line argument.
- *  First command param starts with //name//value
- */
-static int parse_args(int argc, char **argv, process_t *proc)
-{
-    int mode = 0;
-    char *arg = argv[1];
-
-    if ((strlen(arg) > 5) && arg[0] == '/' && arg[1] == '/') {
-        if (STRN_COMPARE(arg, PROC_ARG_ENVPREFIX)) {
-            proc->env_prefix = arg + STRN_SIZE(PROC_ARG_ENVPREFIX);
-            mode = PROCRUN_CMD_ENVPREFIX;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_RUN_JAVA)) {
-            proc->java.path = pool_strdup(proc->pool, arg + 
-                                          STRN_SIZE(PROC_ARG_RUN_JAVA));
-            mode = PROCRUN_CMD_RUN_JAVA;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_INSTALL_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg + 
-                                          STRN_SIZE(PROC_ARG_INSTALL_SERVICE));
-            mode = PROCRUN_CMD_INSTALL_SERVICE;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_RUN_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg + 
-                                             STRN_SIZE(PROC_ARG_RUN_SERVICE));
-            mode = PROCRUN_CMD_RUN_SERVICE;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_TEST_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg + 
-                                             STRN_SIZE(PROC_ARG_TEST_SERVICE));
-            mode = PROCRUN_CMD_TEST_SERVICE;
-        }
-#ifdef PROCRUN_WINAPP
-        else if (STRN_COMPARE(arg, PROC_ARG_GUIT_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg + 
-                                             STRN_SIZE(PROC_ARG_GUIT_SERVICE));
-            mode = PROCRUN_CMD_GUIT_SERVICE;
-            ac_use_try = 1;
-            ac_use_dlg = 1;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_GUID_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg + 
-                                             STRN_SIZE(PROC_ARG_GUID_SERVICE));
-            mode = PROCRUN_CMD_GUID_SERVICE;
-            ac_use_dlg = 1;
-            ac_use_show = 1;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_GUID_PROCESS)) {
-            mode = PROCRUN_CMD_GUID_PROCESS;
-            ac_use_dlg = 1;
-            ac_use_show = 1;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_EDIT_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg + 
-                                             STRN_SIZE(PROC_ARG_EDIT_SERVICE));
-
-            mode = PROCRUN_CMD_EDIT_SERVICE;
-            ac_use_props = 1;
-        }
-#endif
-        else if (STRN_COMPARE(arg, PROC_ARG_STOP_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg +
-                                             STRN_SIZE(PROC_ARG_STOP_SERVICE));
-            mode = PROCRUN_CMD_STOP_SERVICE;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_DELETE_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg +
-                                           STRN_SIZE(PROC_ARG_DELETE_SERVICE));
-            mode = PROCRUN_CMD_DELETE_SERVICE;
-        }
-        else if (STRN_COMPARE(arg, PROC_ARG_UPDATE_SERVICE)) {
-            proc->service.name = pool_strdup(proc->pool, arg +
-                                           STRN_SIZE(PROC_ARG_UPDATE_SERVICE));
-            mode = PROCRUN_CMD_UPDATE_SERVICE;
-        }
-    }
-    return mode;
-}
-
-/* Print some statistics about the current process
- *
- */
-static void debug_process(int argc, char **argv, process_t *p)
-{
-    DBPRINTF1("DUMPING %s\n", argv[0]);
-    DBPRINTF0("  SERVICE:\n");
-    DBPRINTF1("    name        : %s\n", p->service.name);
-    DBPRINTF1("    description : %s\n", p->service.description);
-    DBPRINTF1("    path        : %s\n", p->service.path);
-    DBPRINTF1("    image       : %s\n", p->service.image);
-    DBPRINTF1("    infile      : %s\n", p->service.inname);
-    DBPRINTF1("    outfile     : %s\n", p->service.outname);
-    DBPRINTF1("    errfile     : %s\n", p->service.errname);
-    DBPRINTF1("    argvw       : %s\n", p->argw);
-    DBPRINTF0("  JAVAVM:\n");
-    DBPRINTF1("    name        : %s\n", p->java.path);
-    DBPRINTF1("    start       : %s\n", p->java.start_class);
-    DBPRINTF1("    stop        : %s\n", p->java.stop_class);
-    DBPRINTF1("    start method: %s\n", p->java.start_method);
-    DBPRINTF1("    stop method : %s\n", p->java.stop_method);
-    DBPRINTF1("    start param : %s\n", p->java.start_param);
-    DBPRINTF1("    stop param  : %s\n", p->java.stop_param);
-
-    DBPRINTF0("DONE...\n");
-}
-
-/* Add the environment variable 'name=value'
- * to the environment that will be passed to the child process.
- */
-static int procrun_addenv(char *name, char *value, int val, process_t *proc)
-{
-    int i;
-
-    for (i = 0; i < PROC_ENV_COUNT; i++)
-        if (proc->env[i] == NULL)
-            break;
-    if (i < PROC_ENV_COUNT) {
-        if (value) {
-            proc->env[i] = (char *)pool_alloc(proc->pool, strlen(name) + 
-                                              strlen(value) + 1);
-            strcpy(proc->env[i], name);
-            strupr(proc->env[i]);
-            strcat(proc->env[i], value);
-        }
-        else {
-            proc->env[i] = (char *)pool_alloc(proc->pool, strlen(name) + 34);
-            strcpy(proc->env[i], name);
-            strupr(proc->env[i]);
-            itoa(val, proc->env[i] + strlen(name), 10);
-        }
-        return i;
-    }
-    else
-        return -1;
-}
-
-/* Read the environment.
- * This function reads the procrun defined environment
- * variables passed from the calling process,
- * if the calling process is a procrun instance.
- */
-static int procrun_readenv(process_t *proc, char **envp)
-{
-    int i, rv = 0;
-    char *env;
-    HANDLE h;
-
-    for (i = 0; envp[i]; i++) {
-        env = envp[i];
-        if (STRN_COMPARE(env, PROCRUN_ENV_STDIN)) {
-            h = (HANDLE)atoi(env + STRN_SIZE(PROCRUN_ENV_STDIN));
-            if (!DuplicateHandle(proc->pinfo.hProcess, 
-                                 h,
-                                 proc->pinfo.hProcess,
-                                 &proc->h_stdin[0], 
-                                 0L, TRUE, DUPLICATE_SAME_ACCESS)) {
-                DBPRINTF1("%s\tDuplicateHandle for STDIN failed\n", env[i]);
-                proc->h_stdin[0] = INVALID_HANDLE_VALUE;
-                return 0;
-            }
-            CloseHandle(h);
-            ++rv;
-        }
-        else if (STRN_COMPARE(env, PROCRUN_ENV_STDOUT)) {
-            h = (HANDLE)atoi(env + STRN_SIZE(PROCRUN_ENV_STDOUT));
-            if (!DuplicateHandle(proc->pinfo.hProcess, 
-                                 h,
-                                 proc->pinfo.hProcess,
-                                 &proc->h_stdout[1], 
-                                 0L, TRUE, DUPLICATE_SAME_ACCESS)) {
-                DBPRINTF1("%s\tDuplicateHandle for STDOUT failed\n", env[i]);
-                proc->h_stdout[1] = INVALID_HANDLE_VALUE;
-                return 0;
-            }
-            CloseHandle(h);
-            ++rv;
-        }
-        else if (STRN_COMPARE(env, PROCRUN_ENV_STDERR)) {
-            h = (HANDLE)atoi(env + STRN_SIZE(PROCRUN_ENV_STDERR));
-            if (!DuplicateHandle(proc->pinfo.hProcess, 
-                                 h,
-                                 proc->pinfo.hProcess,
-                                 &proc->h_stderr[1], 
-                                 0L, TRUE, DUPLICATE_SAME_ACCESS)) {
-                DBPRINTF1("%s\tDuplicateHandle for STDERR failed\n", env[i]);
-                proc->h_stderr[1] = INVALID_HANDLE_VALUE;
-                return 0;
-            }
-            CloseHandle(h);
-            ++rv;
-        }
-        else if (STRN_COMPARE(env, PROCRUN_ENV_ERRFILE)) {
-            h = (HANDLE)atoi(env + STRN_SIZE(PROCRUN_ENV_ERRFILE));
-            g_proc_stderr_file = _open_osfhandle((long)h,
-                                                  _O_APPEND | _O_TEXT);
-        }
-        else if (STRN_COMPARE(env, PROCRUN_ENV_PPID)) {
-            proc->ppid = atoi(env + STRN_SIZE(PROCRUN_ENV_PPID));
-        }
-
-    }
-    return rv;
-}
-
-/* Find the default jvm.dll
- * The function scans through registry and finds
- * default JRE jvm.dll.
- */
-static char* procrun_guess_jvm(process_t *proc)
-{
-    HKEY hkjs;
-    char jvm[MAX_PATH+1];
-    char reg[MAX_PATH+1];
-    char *cver;
-    unsigned long err, klen = MAX_PATH;
-    
-    strcpy(reg, JAVASOFT_REGKEY);
-    cver = &reg[sizeof(JAVASOFT_REGKEY)-1];
-
-    if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg,
-                            0, KEY_READ, &hkjs)) != ERROR_SUCCESS) {
-       DBPRINTF0("procrun_guess_jvm() failed to open Registry key\n");
-       return NULL;
-    }
-    if ((err = RegQueryValueEx(hkjs, "CurrentVersion", NULL, NULL, 
-                               (unsigned char *)cver,
-                               &klen)) != ERROR_SUCCESS) {
-        DBPRINTF0("procrun_guess_jvm() failed obtaining Current Java Version\n");
-        RegCloseKey(hkjs);
-        return NULL;
-    }
-    RegCloseKey(hkjs);
-    
-    if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg,
-                            0, KEY_READ, &hkjs) ) != ERROR_SUCCESS) {
-        DBPRINTF1("procrun_guess_jvm() failed to open Registry key %s\n", reg);
-        return NULL;
-    }
-    klen = MAX_PATH;
-    if ((err = RegQueryValueEx(hkjs, "RuntimeLib", NULL, NULL, 
-                               (unsigned char *)jvm, 
-                               &klen)) != ERROR_SUCCESS) {
-        DBPRINTF0("procrun_guess_jvm() failed obtaining Runtime Library\n");
-        RegCloseKey(hkjs);
-        return NULL;
-    }
-    RegCloseKey(hkjs);
-
-    return pool_strdup(proc->pool, jvm);
-} 
-
-/* Find the java/javaw (depending on image)
- * The function locates the JavaHome Registry entry
- * and merges that path with the requested image
- */
-
-static char* procrun_guess_java(process_t *proc, const char *image)
-{
-    HKEY hkjs;
-    char jbin[MAX_PATH+1];
-    char reg[MAX_PATH+1];
-    char *cver;
-    unsigned long err, klen = MAX_PATH;
-    
-    if((cver = getenv("JAVA_HOME")) != NULL) {
-        strcpy(jbin,cver);
-    } else {
-        strcpy(reg, JAVASOFT_REGKEY);
-        cver = &reg[sizeof(JAVASOFT_REGKEY)-1];
-
-        if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg,
-                            0, KEY_READ, &hkjs)) != ERROR_SUCCESS) {
-           DBPRINTF0("procrun_guess_jvm() failed to open Registry key\n");
-           return NULL;
-        }
-        if ((err = RegQueryValueEx(hkjs, "CurrentVersion", NULL, NULL, 
-                               (unsigned char *)cver,
-                               &klen)) != ERROR_SUCCESS) {
-            DBPRINTF0("procrun_guess_jvm() failed obtaining Current Java Version\n");
-            RegCloseKey(hkjs);
-            return NULL;
-        }
-        RegCloseKey(hkjs);
-    
-        if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg,
-                            0, KEY_READ, &hkjs) ) != ERROR_SUCCESS) {
-            DBPRINTF1("procrun_guess_jvm() failed to open Registry key %s\n", reg);
-            return NULL;
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(hkjs, "JavaHome", NULL, NULL, 
-                               (unsigned char *)jbin, 
-                               &klen)) != ERROR_SUCCESS) {
-            DBPRINTF0("procrun_guess_jvm() failed obtaining Java path\n");
-            RegCloseKey(hkjs);
-            return NULL;
-        }
-        RegCloseKey(hkjs);
-    }
-    strcat(jbin, "\\bin\\");
-    strcat(jbin, image);
-    strcat(jbin, ".exe");
-    return pool_strdup(proc->pool, jbin);
-} 
-
-/* Find the system JavaHome path.
- * The "JAVA_HOME" environment variable
- * gets procedance over registry settings
- */
-static char* procrun_guess_java_home(process_t *proc)
-{
-    HKEY hkjs;
-    char jbin[MAX_PATH+1];
-    char reg[MAX_PATH+1];
-    char *cver;
-    unsigned long err, klen = MAX_PATH;
-    
-    if ((cver = getenv("JAVA_HOME")) != NULL) {
-        strcpy(jbin, cver);
-        strcat(jbin, "\\bin");
-        return pool_strdup(proc->pool, jbin);
-    }
-    strcpy(reg, JAVAHOME_REGKEY);
-    cver = &reg[sizeof(JAVAHOME_REGKEY)-1];
-
-    if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg,
-                            0, KEY_READ, &hkjs)) != ERROR_SUCCESS) {
-       DBPRINTF0("procrun_guess_jvm() failed to open Registry key\n");
-       return NULL;
-    }
-    if ((err = RegQueryValueEx(hkjs, "CurrentVersion", NULL, NULL, 
-                               (unsigned char *)cver,
-                               &klen)) != ERROR_SUCCESS) {
-        DBPRINTF0("procrun_guess_jvm() failed obtaining Current Java SDK Version\n");
-        RegCloseKey(hkjs);
-        return NULL;
-    }
-    RegCloseKey(hkjs);
-    
-    if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg,
-                            0, KEY_READ, &hkjs)) != ERROR_SUCCESS) {
-        DBPRINTF1("procrun_guess_jvm() failed to open Registry key %s\n", reg);
-        return NULL;
-    }
-    klen = MAX_PATH;
-    if ((err = RegQueryValueEx(hkjs, "JavaHome", NULL, NULL, 
-                               (unsigned char *)jbin, 
-                               &klen)) != ERROR_SUCCESS) {
-        DBPRINTF0("procrun_guess_jvm() failed obtaining Java Home\n");
-        RegCloseKey(hkjs);
-        return NULL;
-    }
-    RegCloseKey(hkjs);
-    procrun_addenv("JAVA_HOME", jbin, 0, proc);
-    strcat(jbin, "\\bin");
-    return pool_strdup(proc->pool, jbin);
-} 
-
-/* Read the service parameters from the registry
- *
- */
-static int procrun_service_params(process_t *proc)
-{
-    HKEY key;
-    char skey[256];
-    char kval[MAX_PATH];
-    unsigned long klen;
-    DWORD err;
-    
-    if (!proc->service.name)
-        return 0;
-
-    sprintf(skey, PROCRUN_REGKEY_RPARAMS, proc->service.name);
-    DBPRINTF1("getting key: %s\n", skey);
-    if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, skey,
-                            0, KEY_READ, &key)) == ERROR_SUCCESS) {
-
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_DESCRIPTION, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.description = pool_strdup(proc->pool, kval);
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_DISPLAY, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.display = pool_strdup(proc->pool, kval);
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_WORKPATH, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.path = pool_strdup(proc->pool, kval);
-        }
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_IMAGE, NULL, NULL, 
-                                   NULL,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.image = (char *)pool_alloc(proc->pool, klen);
-            if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_IMAGE, NULL, NULL, 
-                                   (unsigned char *)proc->service.image,
-                                   &klen)) != ERROR_SUCCESS) {
-                proc->service.image = NULL;
-            }
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_ACCOUNT, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.account = pool_strdup(proc->pool, kval);
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_PASSWORD, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.password = pool_calloc(proc->pool, 256);
-            simple_decrypt(100, proc->service.password,  kval);
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_STARTUP, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            if (!strcmp(kval, "auto"))
-                proc->service.startup = SERVICE_AUTO_START;
-            else
-                proc->service.startup = SERVICE_DEMAND_START;
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_STARTCLASS, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            char *p;
-            p = strchr(kval, ';');
-            if (p) *p = '\0';
-            proc->java.start_class = pool_strdup(proc->pool, kval);
-            if (p) {
-                ++p;
-                proc->java.start_method = pool_strdup(proc->pool, p);
-                p = strchr(proc->java.start_method, ';');
-                if (p) {
-                    *p = '\0';
-                    ++p;
-                    proc->java.start_param = pool_strdup(proc->pool, p);
-                }
-            }
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_STOPCLASS, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            char *p;
-            p = strchr(kval, ';');
-            if (p) *p = '\0';
-            proc->java.stop_class = pool_strdup(proc->pool, kval);
-            if (p) {
-                ++p;
-                proc->java.stop_method = pool_strdup(proc->pool, p);
-                p = strchr(proc->java.stop_method, ';');
-                if (p) {
-                    *p = '\0';
-                    ++p;
-                    proc->java.stop_param = pool_strdup(proc->pool, p);
-                }
-            }
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_STDINFILE, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.infile = CreateFile(kval,
-                                              GENERIC_READ,
-                                              0,
-                                              NULL,
-                                              OPEN_EXISTING,
-                                              FILE_ATTRIBUTE_NORMAL,
-                                              NULL);
-            if (proc->service.infile != INVALID_HANDLE_VALUE) {
-                if (proc->h_stdin[1] != INVALID_HANDLE_VALUE)
-                    pool_close_handle(proc->pool, proc->h_stdin[1]);
-                proc->h_stdin[1] = proc->service.infile;
-                proc->service.inname = pool_strdup(proc->pool, kval);
-            }
-            pool_handle(proc->pool, proc->service.infile);
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_STDOUTFILE, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.outfile = CreateFile(kval,
-                                               GENERIC_WRITE,
-                                               FILE_SHARE_READ,
-                                               NULL,
-                                               OPEN_ALWAYS,
-                                               FILE_ATTRIBUTE_NORMAL,
-                                               NULL);
-            if (proc->service.outfile != INVALID_HANDLE_VALUE) {
-                SetFilePointer(proc->service.outfile, 0L, NULL, FILE_END);
-                if (proc->h_stdout[1] != INVALID_HANDLE_VALUE)
-                    pool_close_handle(proc->pool, proc->h_stdout[1]);
-                proc->h_stdout[1] = proc->service.outfile;
-                proc->service.outname = pool_strdup(proc->pool, kval);
-            }
-            pool_handle(proc->pool, proc->service.outfile);
-        }
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_STDERRFILE, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.errfile = CreateFile(kval,
-                                               GENERIC_WRITE,
-                                               FILE_SHARE_READ,
-                                               NULL,
-                                               OPEN_ALWAYS,
-                                               FILE_ATTRIBUTE_NORMAL,
-                                               NULL);
-            if (proc->service.errfile != INVALID_HANDLE_VALUE) {
-                SetFilePointer(proc->service.errfile, 0L, NULL, FILE_END);
-                if (proc->h_stderr[1] != INVALID_HANDLE_VALUE)
-                    pool_close_handle(proc->pool, proc->h_stderr[1]);
-                proc->h_stderr[1] = proc->service.errfile;
-                proc->service.errname = pool_strdup(proc->pool, kval);
-            }
-            pool_handle(proc->pool, proc->service.errfile);
-        }
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_CMDARGS, NULL, NULL, 
-                                   NULL,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->argw = (char *)pool_alloc(proc->pool, klen);
-            if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_CMDARGS, NULL, NULL, 
-                                       (unsigned char *)proc->argw,
-                                       &klen)) != ERROR_SUCCESS) {
-                proc->argw = NULL;
-            }
-            
-        }
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_JVM_OPTS, NULL, NULL, 
-                                   NULL,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->java.opts = (char *)pool_alloc(proc->pool, klen);
-            if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_JVM_OPTS, NULL, NULL, 
-                                       (unsigned char *)proc->java.opts,
-                                       &klen)) != ERROR_SUCCESS) {
-                proc->java.opts = NULL;
-            }
-        }
-#ifdef PROCRUN_WINAPP
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_WINPOS, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            sscanf(kval, "%d %d %d %d", &ac_winpos.left, &ac_winpos.right,
-                                        &ac_winpos.top, &ac_winpos.bottom);
-        }
-
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_USELVIEW, NULL, NULL, 
-                                   (unsigned char *)kval,
-                                   &klen)) == ERROR_SUCCESS) {
-            ac_use_lview = atoi(kval);
-        }
-#endif
-        klen = MAX_PATH;
-        if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_ENVIRONMENT, NULL, NULL, 
-                                   NULL,
-                                   &klen)) == ERROR_SUCCESS) {
-            proc->service.environment = (char *)pool_alloc(proc->pool, klen);
-            if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_ENVIRONMENT, NULL, NULL, 
-                                   (unsigned char *)proc->service.environment,
-                                   &klen)) != ERROR_SUCCESS) {
-                proc->service.environment = NULL;
-            }
-        }
-
-        RegCloseKey(key); 
-        return 0;
-    }
-    else
-        return -1;
-}
-
-/* Decide if we need the java
- * Check the registry and decide how the java
- * is going to be loaded.
- * Using inprocess jvm.dll or as a child process running java.exe
- */
-static int procrun_load_jvm(process_t *proc, int mode)
-{
-    int has_java = 0;
-    char jvm_path[MAX_PATH + 1];
-    
-    if (!proc->java.start_class) {
-        return 0;
-    }
-    jvm_path[0] = '\0';
-    switch (mode) {
-        case PROCRUN_CMD_RUN_JAVA:
-            has_java = 1;
-            break;
-        case PROCRUN_CMD_RUN_SERVICE:
-        case PROCRUN_CMD_TEST_SERVICE:
-        case PROCRUN_CMD_GUIT_SERVICE:
-        case PROCRUN_CMD_GUID_SERVICE:
-        case PROCRUN_CMD_EDIT_SERVICE:
-            {
-                HKEY key;
-                char skey[256];
-                unsigned long klen = MAX_PATH;
-                DWORD err;
-                sprintf(skey, PROCRUN_REGKEY_RPARAMS, proc->service.name);
-                if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, skey,
-                                        0, KEY_READ, &key)) == ERROR_SUCCESS) {
-                    
-                    if ((err = RegQueryValueEx(key, PROCRUN_PARAMS_JVM,
-                                               NULL, NULL, 
-                                               (unsigned char *)jvm_path,
-                                               &klen)) == ERROR_SUCCESS) {
-                        has_java = 1;
-                    }
-                    RegCloseKey(key); 
-                }
-            }
-            break;
-    }
-    if (has_java) {
-        UINT em;
-        if (strlen(jvm_path)) {
-            proc->java.display = pool_strdup(proc->pool, jvm_path);
-            if (strlen(jvm_path) < 6)
-                proc->java.path = procrun_guess_jvm(proc);
-            else
-                proc->java.path = pool_strdup(proc->pool, jvm_path);
-            if (strnicmp(jvm_path, "java", 4) == 0) {
-                proc->java.jbin = procrun_guess_java(proc, jvm_path);
-                proc->java.jpath = procrun_guess_java_home(proc);
-            }
-        }
-        DBPRINTF1("jvm dll path %s\n", proc->java.path);
-        DBPRINTF1("java    path %s\n", proc->java.jpath);
-        DBPRINTF1("java    bin  %s\n", proc->java.jbin);
-        if (!proc->java.path || !proc->java.start_method) {
-            DBPRINTF0("java path or start method missing\n");
-            return -1;
-        } else if (proc->java.jbin != NULL) {
-            DBPRINTF0("forking no need to load java dll\n");
-        return 0; // If forking, don't bother with the load.
-        }
-        /* Try to load the jvm dll */ 
-        em = SetErrorMode(SEM_FAILCRITICALERRORS);
-        proc->java.dll = LoadLibraryEx(proc->java.path, NULL, 0); 
-        if (!proc->java.dll)
-            proc->java.dll = LoadLibraryEx(proc->java.path, NULL,
-                                           LOAD_WITH_ALTERED_SEARCH_PATH);
-        SetErrorMode(em);
-        if (!proc->java.dll) {
-            DBPRINTF0(NULL);
-            DBPRINTF0("Cannot load java dll\n");
-            return -1;
-        }
-        /* resolve symbols */
-        jni_JNI_GetDefaultJavaVMInitArgs = (JNI_GETDEFAULTJAVAVMINITARGS)
-                                            GetProcAddress(proc->java.dll,
-                                            "JNI_GetDefaultJavaVMInitArgs");
-        jni_JNI_CreateJavaVM = (JNI_CREATEJAVAVM)
-                               GetProcAddress(proc->java.dll,
-                               "JNI_CreateJavaVM");
-        jni_JNI_GetCreatedJavaVMs = (JNI_GETCREATEDJAVAVMS)
-                                    GetProcAddress(proc->java.dll,
-                                    "JNI_GetCreatedJavaVMs");
-        if (jni_JNI_GetDefaultJavaVMInitArgs == NULL ||
-            jni_JNI_CreateJavaVM == NULL ||
-            jni_JNI_GetCreatedJavaVMs == NULL) {
-            DBPRINTF0(NULL);
-            DBPRINTF0("Cannot find JNI routines in java dll\n");
-            FreeLibrary(proc->java.dll);
-            proc->java.dll = NULL;
-            return -1;
-        }
-        DBPRINTF1("JVM %s Loaded\n", proc->java.path);
-    }
-    return 0;
-}
-
-/* JVM hooks */
-static int jni_exit_signaled = 0;
-static int jni_exit_code = 0;
-static int jni_abort_signaled = 0;
-
-static void jni_exit_hook(int code)
-{
-    jni_exit_signaled = -1;
-#if 1
-    jni_abort_signaled = -1;    
-#endif
-    jni_exit_code = code;
-
-    DBPRINTF1("JVM exit hook called %d\n", code);
-}
-
-static void jni_abort_hook()
-{
-    jni_abort_signaled = -1;    
-
-    DBPRINTF0("JVM abort hook called\n");
-}  
-
-/* 'Standard' JNI functions
- *
- */
-
-static JNIEnv *jni_attach(process_t *proc)
-{
-    JNIEnv *env = NULL;
-    int err;
-    JavaVM *jvm = proc->java.jvm;
-
-    if (jvm == NULL || jni_abort_signaled)
-        return NULL;
-    err = (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2);  
-    if (err == 0)
-        return env;        
-    if (err != JNI_EDETACHED) {
-        return NULL;
-    }
-    err = (*jvm)->AttachCurrentThread(jvm,
-                                      (void **)&env,
-                                      NULL);
-    if (err != 0) {
-        return NULL;
-    }
-    return env;
-}
-
-static int jni_detach(process_t *proc)
-{
-    JavaVM *jvm = proc->java.jvm;
-
-    if (jvm == NULL || jni_abort_signaled)
-        return -1;
-    return (*jvm)->DetachCurrentThread(jvm);
-}
-
-/* Destroy the jvm.
- * This method stops the current jvm calling
- * configured stop methods and destroys the loaded jvm.
- */
-static int procrun_destroy_jvm(process_t *proc, HANDLE jh)
-{
-    JavaVM *jvm = proc->java.jvm;
-    int err;
-    JNIEnv *env;
-
-    DBPRINTF2("procrun_destroy_jvm dll %08x jvm %08x\n",proc->java.dll,proc->java.jvm);
-    if (!proc->java.dll || !jvm) {
-        if(proc->java.stop_class != NULL && proc->java.stop_method != NULL && g_env->c->pinfo.dwProcessId) {
-            process_t tc = *g_env->c, tm = *g_env->m;
-            procrun_t tproc;
-            HANDLE threads[2];
-            tproc.c = &tc;
-            tproc.m = &tm;
-            procrun_redirect(proc->service.image,
-                              proc->envp, &tproc, 0);    
-            threads[0] = tc.pinfo.hThread;
-            threads[1] = g_env->c->pinfo.hThread;
-            WaitForMultipleObjects(2,threads, TRUE, 60000);
-        }
-
-        return 0;
-    }
-    env = jni_attach(proc);
-    if (!env) {
-        DBPRINTF0("jni_attach failed\n");
-        goto cleanup;
-    }
-    if (proc->java.stop_bridge && proc->java.stop_mid) {
-        jclass strclass;
-        jarray jargs = NULL;
-        DBPRINTF1("Calling shutdown %s\n", proc->java.stop_class); 
-
-        strclass = (*env)->FindClass(env, "java/lang/String");
-        if (proc->java.stop_param) {
-            jstring arg = (*env)->NewStringUTF(env, proc->java.stop_param);
-            jargs = (*env)->NewObjectArray(env, 1, strclass, NULL);
-            (*env)->SetObjectArrayElement(env, jargs, 0, arg);
-        }
-        (*env)->CallStaticVoidMethod(env,
-                                     proc->java.stop_bridge,
-                                     proc->java.stop_mid,
-                                     jargs);
-        if(jh != NULL)
-            WaitForSingleObject(jh, 60000);
-    }
-    else if (!proc->java.jbin) {
-        /* Call java.lang.System.exit(0) */
-        jclass sysclass;
-        jmethodID exitid;
-        sysclass = (*env)->FindClass(env, "java/lang/System");
-        if (!sysclass)
-            goto cleanup;
-        exitid   = (*env)->GetStaticMethodID(env, sysclass, "exit", "(I)V");
-        if (!exitid)
-            goto cleanup;
-        report_service_status(SERVICE_STOPPED, 0, 0,
-                              g_env->m);
-        DBPRINTF0("Forcing shutdown using System.exit(0)\n");
- 
-        (*env)->CallStaticVoidMethod(env, sysclass, exitid, 0);
-    }
-cleanup:
-    err = (*jvm)->DestroyJavaVM(jvm);
-    FreeLibrary(proc->java.dll);
-    proc->java.dll = NULL;
-    return err;
-}
-
-/* Initialize loaded jvm.dll 
- * Pass the startup options to the jvm,
- * and regiter the start/top classes and methods
- */
-static int procrun_init_jvm(process_t *proc)
-{
-    int jvm_version;
-    JDK1_1InitArgs vm_args11;
-    JavaVMInitArgs vm_args;
-    JavaVMOption options[32];
-    JNIEnv *env;
-    JavaVM *jvm;
-    jclass strclass;
-    jarray jargs = NULL;
-    char *cp;
-    char *opts[32];
-    int optn, i, err;
-
-    vm_args11.version = JNI_VERSION_1_2;
-     
-    DBPRINTF0("Initializing JVM\n");
-    if (jni_JNI_GetDefaultJavaVMInitArgs(&vm_args11) != 0) {
-        DBPRINTF0("Could not find Default InitArgs\n");
-        return -1;
-    }
-    jvm_version= vm_args11.version;
-
-    if (jvm_version != JNI_VERSION_1_2) {
-        DBPRINTF1("Found: %X expecting 1.2 Java Version\n", jvm_version);
-        return -1;
-    }
-    if(proc->service.path != NULL) {
-      SetCurrentDirectory(proc->service.path);
-    }
-    optn = make_array(proc->java.opts, opts, 30, proc);
-    for (i = 0; i < optn; i++)
-        options[i].optionString = remove_quotes(opts[i]);
-    cp = (char *)pool_alloc(proc->pool, strlen("-Djava.class.path=") +
-                            strlen(proc->service.image) + 1);
-    strcpy(cp, "-Djava.class.path=");
-    strcat(cp, remove_quotes(proc->service.image));
-    options[optn++].optionString = cp;
-    DBPRINTF1("-Djava.class.path=%s", proc->service.image);
-    /* Set the abort and exit hooks */
-#if 0
-    options[optn].optionString = "exit";
-    options[optn++].extraInfo = jni_exit_hook;
-#endif
-    options[optn].optionString = "abort";
-    options[optn++].extraInfo = jni_abort_hook; 
-
-    for (i = 0; i < optn; i++)
-    DBPRINTF2("OPT %d %s", i , options[i].optionString);
-
-    vm_args.version = JNI_VERSION_1_2;
-    vm_args.options = options;
-    vm_args.nOptions = optn;    
-    vm_args.ignoreUnrecognized = JNI_TRUE;
- 
-    err = jni_JNI_CreateJavaVM(&jvm, &env, &vm_args);
-    if (err == JNI_EEXIST) {       
-        int vmcount;
-        
-        jni_JNI_GetCreatedJavaVMs(&jvm, 1, &vmcount);        
-        if (jvm == NULL) {
-            DBPRINTF0("Error creating JVM\n");
-            return -1;
-        }
-    }
-    proc->java.jvm = jvm;
-    for (i = 0; i < (int)strlen(proc->java.start_class); i++) {
-        if (proc->java.start_class[i] == '.')
-            proc->java.start_class[i] = '/';
-    }
-    proc->java.start_bridge = (*env)->FindClass(env, proc->java.start_class);
-    if (!proc->java.start_bridge) {
-        DBPRINTF1("Couldn't find Startup class %s\n", proc->java.start_class);
-        goto cleanup;
-    }
-    proc->java.start_mid = (*env)->GetStaticMethodID(env, proc->java.start_bridge,
-                                                     proc->java.start_method, 
-                                                     "([Ljava/lang/String;)V");
-
-    if (!proc->java.start_mid) {
-        DBPRINTF1("Couldn't find Startup class method %s\n", proc->java.start_method);
-        goto cleanup;
-    }
-    if (proc->java.stop_class && proc->java.stop_method) {
-        for (i = 0; i < (int)strlen(proc->java.stop_class); i++) {
-            if (proc->java.stop_class[i] == '.')
-                proc->java.stop_class[i] = '/';
-        }
-        proc->java.stop_bridge = (*env)->FindClass(env, proc->java.stop_class);
-        if (!proc->java.stop_bridge) {
-            goto cleanup;
-        }    
-        proc->java.stop_mid = (*env)->GetStaticMethodID(env, proc->java.stop_bridge,
-                                                        proc->java.stop_method, 
-                                                        "([Ljava/lang/String;)V");
-    }
-    
-    /* check if we have java.exe as worker process 
-     * in that case don't call the startup class. 
-     */
-    if (proc->java.jbin != NULL) {
-        return 0;
-    } 
-    strclass = (*env)->FindClass(env, "java/lang/String");
-    if (proc->java.start_param) {
-        jstring arg = (*env)->NewStringUTF(env, proc->java.start_param);
-        jargs = (*env)->NewObjectArray(env, 1, strclass, NULL);
-        (*env)->SetObjectArrayElement(env, jargs, 0, arg);
-    }
-    (*env)->CallStaticVoidMethod(env,
-                                 proc->java.start_bridge,
-                                 proc->java.start_mid,
-                                 jargs);
-
-    DBPRINTF1("JVM Main class %s finished\n", proc->java.start_class);
-    return 0;
-cleanup:
-    if (proc->java.jvm) {
-        (*(proc->java.jvm))->DestroyJavaVM(proc->java.jvm);
-        FreeLibrary(proc->java.dll);
-        proc->java.dll = NULL;
-        proc->java.jvm = NULL;
-    }
-    return -1;
-}
-
-/* Thread that waits for child process to exit
- * When the child process exits, it sets the
- * event so that we can exit
- */
-DWORD WINAPI wait_thread(LPVOID param)
-{
-    procrun_t *env = (procrun_t *)param;
-
-    /* Wait util a process has finished its initialization. */
-    WaitForInputIdle(env->c->pinfo.hProcess, INFINITE);
-    WaitForSingleObject(env->c->pinfo.hThread, INFINITE);
-    pool_close_handle(env->c->pool, env->c->pinfo.hThread);
-    env->c->pinfo.hThread = NULL;
-    env->c->pinfo.dwProcessId = 0;
-    SetEvent(env->m->events[1]);
-
-    return 0;
-}  
-
-/* Redirected stdout reader thread
- * It reads char at a time and writes
- * either to stdout handle (file or pipe)
- * or calls the gui console printer function.
- */
-DWORD WINAPI stdout_thread(LPVOID param)
-{
-    unsigned char  ch;
-    DWORD readed, written;
-    procrun_t *env = (procrun_t *)param;
-#ifdef PROCRUN_WINAPP
-    static unsigned char buff[MAX_PATH + 1];
-    int n = 0;
-#endif
-
-    while (env->c->h_stdout[3] && 
-           (ReadFile(env->c->h_stdout[3], &ch, 1, &readed, NULL) == TRUE))  {
-        if (readed) {
-#ifdef PROCRUN_WINAPP
-            if (ac_use_dlg) {
-                if (ch == '\n' || n >= MAX_PATH) {
-                    buff[n] = '\0';
-                    DBPRINTF1("RD %s", buff);
-                    ac_add_list_string(buff, n, 0);
-                    n  = 0;
-                } 
-                else if (ch == '\t' && n < (MAX_PATH - 4)) {
-                    int i; /* replace the TAB with four spaces */
-                    for (i = 0; i < 4; ++i)
-                        buff[n++] = ' ';
-                }
-                else if (ch != '\r') /* skip the CR and BELL */
-                    buff[n++] = ch;
-                else if (ch != '\b')
-                    buff[n++] = ' ';
-                SwitchToThread();
-            }
-#endif
-            if (WriteFile(env->m->h_stdout[0], &ch, 1, &written, NULL) == TRUE) {
-                SwitchToThread();
-            }
-            else
-                break;
-            readed = 0;
-        }
-    }
-    /* The client has closed it side of a pipe
-     * meaning that he has finished
-     */
-    SetEvent(env->m->events[2]);
-    return 0;
-}  
-
-/* Redirected stderr reader thread
- * It reads char at a time and writes
- * either to stderr handle (file or pipe)
- * or calls the gui console printer function.
- */
-
-DWORD WINAPI stderr_thread(LPVOID param)
-{
-    unsigned char  ch;
-    DWORD readed, written;
-    procrun_t *env = (procrun_t *)param;
-#ifdef PROCRUN_WINAPP
-    static unsigned char buff[MAX_PATH + 1];
-    int n = 0;
-#endif
-
-    while (env->c->h_stderr[3] && 
-          (ReadFile(env->c->h_stderr[3], &ch, 1, &readed, NULL) == TRUE))  {
-        if (readed) {
-#ifdef PROCRUN_WINAPP
-            if (ac_use_dlg) {
-                if (ch == '\n' || n >= MAX_PATH) {
-                    buff[n] = '\0';
-                    DBPRINTF1("RD %s", buff);
-                    ac_add_list_string(buff, n, 1);
-                    n  = 0;
-                } 
-                else if (ch == '\t' && n < (MAX_PATH - 4)) {
-                    int i;
-                    for (i = 0; i < 4; ++i)
-                        buff[n++] = ' ';
-                }
-                else if (ch != '\r')
-                    buff[n++] = ch;
-                else if (ch != '\b')
-                    buff[n++] = ' ';
-                SwitchToThread();
-            }
-#endif
-            if (WriteFile(env->m->h_stderr[0], &ch, 1, &written, NULL) == TRUE) {
-                SwitchToThread();
-            }
-            else
-                break;
-            readed = 0;
-        }
-    }
-    SetEvent(env->m->events[3]);
-    return 0;
-}  
-
-/* Created redirection pipes, and close the unused sides.
- * 
- */
-static int procrun_create_pipes(procrun_t *env)
-{
-    SECURITY_ATTRIBUTES sa;    
-   
-    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
-    sa.bInheritHandle = TRUE;
-    sa.lpSecurityDescriptor = NULL;
-
-    /* redirect stdout */
-    if (env->m->h_stdout[1] == INVALID_HANDLE_VALUE)
-        env->m->h_stdout[0] = GetStdHandle(STD_OUTPUT_HANDLE);
-    else
-        env->m->h_stdout[0] = env->m->h_stdout[1];
-
-    if (!CreatePipe(&env->c->h_stdout[0],
-                    &env->c->h_stdout[1], &sa, 0)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    SetStdHandle(STD_OUTPUT_HANDLE, env->c->h_stdout[1]);
-    pool_handle(env->c->pool, env->c->h_stdout[1]);
-
-    if (!DuplicateHandle(env->m->pinfo.hProcess,
-                         env->c->h_stdout[0],
-                         env->m->pinfo.hProcess,
-                         &env->c->h_stdout[3], 
-                         0, FALSE, DUPLICATE_SAME_ACCESS)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    pool_close_handle(env->c->pool, env->c->h_stdout[0]);
-    pool_handle(env->c->pool, env->c->h_stdout[3]);
-    
-    /* redirect stderr */
-    if (env->m->h_stderr[1] == INVALID_HANDLE_VALUE)
-        env->m->h_stderr[0] = GetStdHandle(STD_ERROR_HANDLE);
-    else
-        env->m->h_stderr[0] = env->m->h_stderr[1];
-
-    if (!CreatePipe(&env->c->h_stderr[0],
-                    &env->c->h_stderr[1], &sa, 0)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    SetStdHandle(STD_ERROR_HANDLE, env->c->h_stderr[1]);
-    pool_handle(env->c->pool, env->c->h_stderr[1]);
-
-    if (!DuplicateHandle(env->m->pinfo.hProcess,
-                         env->c->h_stderr[0],
-                         env->m->pinfo.hProcess,
-                         &env->c->h_stderr[3], 
-                         0, FALSE, DUPLICATE_SAME_ACCESS)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    pool_close_handle(env->c->pool, env->c->h_stderr[0]);
-    pool_handle(env->c->pool, env->c->h_stderr[3]);
-
-    /* redirect stdin */
-    if (env->m->h_stdin[1] == INVALID_HANDLE_VALUE)
-        env->m->h_stdin[0] = GetStdHandle(STD_INPUT_HANDLE);
-    else
-        env->m->h_stdin[0] = env->m->h_stdin[1];
-
-    if (!CreatePipe(&env->c->h_stdin[0],
-                    &env->c->h_stdin[1], &sa, 0)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    SetStdHandle(STD_INPUT_HANDLE, env->c->h_stdin[0]);  
-    pool_handle(env->c->pool, env->c->h_stdin[0]);
-    if (!DuplicateHandle(env->m->pinfo.hProcess,
-                         env->c->h_stdin[1],
-                         env->m->pinfo.hProcess,
-                         &env->c->h_stdin[3], 
-                         0, FALSE, DUPLICATE_SAME_ACCESS)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    
-    pool_close_handle(env->c->pool, env->c->h_stdin[1]);
-    pool_handle(env->c->pool, env->c->h_stdin[3]);
-
-    return 0;
-}
-
-/* Write the specified file to the childs stdin.
- * This function wraps 'child.exe <some_file'
- */
-static int procrun_write_stdin(procrun_t *env)
-{
-    DWORD readed, written; 
-    char buf[PROC_BUFSIZE]; 
-    
-    if (!env->m->service.infile)
-        return -1;
-
-    for (;;) { 
-        if (!ReadFile(env->m->service.infile, buf, PROC_BUFSIZE, 
-                      &readed, NULL) || readed == 0) 
-             break; 
-        SwitchToThread();
-        if (!WriteFile(env->c->h_stdin[3], buf, readed, 
-            &written, NULL))
-            break;
-        SwitchToThread();
-    } 
- 
-    /* Close the pipe handle so the child process stops reading. */ 
-    if (!pool_close_handle(env->c->pool, env->c->h_stdin[3])) 
-      return -1; 
-    env->c->h_stdin[3] = INVALID_HANDLE_VALUE;
-    return 0;
-}
-
-/* Make the command line for starting or stopping
- * java process.
- */
-static char * set_command_line(procrun_t *env, char *program, int starting){
-        int i, j, len = strlen(env->m->argw) + 8192;
-        char *opts[64], *nargw;
-        char *javaClass = starting ? env->m->java.start_class : env->m->java.stop_class,
-            *javaParam = starting ? env->m->java.start_param : env->m->java.stop_param;
-
-        j = make_array(env->m->java.opts, opts, 60, env->m);
-
-        for (i = 0; i < j; i++)
-            len += strlen(opts[i]);
-       
-        nargw = pool_calloc(env->m->pool, len);
-        if(starting)
-            strcpy(nargw, env->m->argw);
-        else
-            strcpy(nargw, "java");
-        strcat(nargw, " ");
-        for (i = 0; i < j; i++) {
-            strcat(nargw, opts[i]);
-            strcat(nargw, " ");
-        }
-        strcat(nargw, "-Djava.class.path=");
-        if (strchr(program, ' ')) {
-            strcat(nargw, "\"");
-            strcat(nargw, program);
-            strcat(nargw, "\"");
-        }
-        else
-            strcat(nargw, program);
-        strcat(nargw, " ");
-        strcat(nargw, javaClass);
-        if (javaParam) {
-            strcat(nargw, " ");
-            strcat(nargw, javaParam);
-        }
-        env->m->argw = nargw;
-        program = env->m->java.jbin;
-    return program;
-}
-
-/* Main redirection function.
- * Create the redirection pipes
- * Make the child's environment
- * Make the command line
- * Logon as different user
- * Create the child process
- */
-int procrun_redirect(char *program, char **envp, procrun_t *env, int starting)
-{
-    STARTUPINFO si;
-    DWORD  id;
-
-    if (!program) {
-#ifdef PROCRUN_WINAPP
-        MessageBox(NULL, "Service not found ", env->m->service.name,
-                         MB_OK | MB_ICONERROR);
-#else
-        fprintf(stderr, "Service not found %s\n", env->m->service.name); 
-#endif
-        return -1;
-    }
-    memset(&si, 0, sizeof(STARTUPINFO));
-    si.cb = sizeof(si);
-    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
-    si.wShowWindow = SW_HIDE;
-
-    if(starting) {
-        if (procrun_create_pipes(env)) {
-            DBPRINTF0("Create pipe failed.\n");
-            return -1;
-        }
-        si.hStdOutput = env->c->h_stdout[1];
-        si.hStdError  = env->c->h_stderr[1];
-        si.hStdInput  = env->c->h_stdin[0]; 
-    }
-    else
-        si.dwFlags = STARTF_USESHOWWINDOW;
-    
-    env->m->envw = make_environment(env->c->env, envp, env->m);
-    DBPRINTF1("Creating process %s.\n", program);
-    DBPRINTF1("Creating process %s.\n", env->m->argw);
-    /* for java.exe merge Arguments and Java options */
-    if (env->m->java.jbin) {
-      program = set_command_line(env, program, starting);
-    }
-    DBPRINTF2("RUN [%s] %s\n", program, env->m->argw);
-    if (env->m->service.account && env->m->service.password && starting) {
-        /* Run the child process under a different user account */
-        HANDLE user, token;
-        DBPRINTF2("RUNASUSER %s@%s\n", env->m->service.account, env->m->service.password);
-        if (!LogonUser(env->m->service.account, 
-                       NULL, 
-                       env->m->service.password, 
-                       LOGON32_LOGON_SERVICE,
-                       LOGON32_PROVIDER_DEFAULT,
-                       &user)) {
-            DBPRINTF0(NULL);
-            DBPRINTF0("LogonUser failed\n");
-            return -1;
-        }
-
-        DuplicateTokenEx(user, 
-                         TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY, 
-                         NULL,
-                         SecurityImpersonation,
-                         TokenPrimary,
-                         &token);
-        DBPRINTF0(NULL);
-
-        DBPRINTF2("Launching as %s:%s", env->m->service.account, env->m->service.password);
-        ImpersonateLoggedOnUser(token);
-        DBPRINTF0(NULL);
-        si.lpDesktop = (LPSTR) "Winsta0\\Default";
-        if (!CreateProcessAsUser(token,
-                                 program,
-                                 env->m->argw,
-                                 NULL,
-                                 NULL,
-                                 TRUE,
-                                 CREATE_SUSPENDED | CREATE_NEW_CONSOLE | 
-                                 CREATE_NEW_PROCESS_GROUP,
-                                 env->m->envw,
-                                 env->m->service.path,
-                                 &si,
-                                 &env->c->pinfo)) {
-
-            DBPRINTF1("Error redirecting '%s'\n", program);
-            DBPRINTF0(NULL);
-            return -1;
-        }
-    }
-    else {
-        if (!CreateProcess(program,
-                           env->m->argw,
-                           NULL,
-                           NULL,
-                           TRUE,
-                           CREATE_SUSPENDED | CREATE_NEW_CONSOLE | 
-                           CREATE_NEW_PROCESS_GROUP,
-                           env->m->envw,
-                           env->m->service.path,
-                           &si,
-                           &env->c->pinfo)) {
-        
-            DBPRINTF1("Error redirecting '%s'\n", program);
-            DBPRINTF0(NULL);
-            return -1;
-        }
-    }
-    DBPRINTF1("started child thread %08x",env->c->pinfo.hThread);
-    if(starting) {
-        pool_handle(env->c->pool, env->c->pinfo.hThread);
-        pool_handle(env->c->pool, env->c->pinfo.hProcess);
-
-        SetStdHandle(STD_OUTPUT_HANDLE, env->m->h_stdout[0]);
-        SetStdHandle(STD_ERROR_HANDLE, env->m->h_stderr[0]);
-        SetStdHandle(STD_INPUT_HANDLE, env->m->h_stdin[0]);  
-        pool_close_handle(env->c->pool, env->c->h_stdout[1]);
-        pool_close_handle(env->c->pool, env->c->h_stderr[1]);
-        pool_close_handle(env->c->pool, env->c->h_stdin[0]); 
-
-        CloseHandle(CreateThread(NULL, 0, stdout_thread, env, 0, &id));     
-        CloseHandle(CreateThread(NULL, 0, stderr_thread, env, 0, &id));     
-        ResumeThread(env->c->pinfo.hThread);    
-        CloseHandle(CreateThread(NULL, 0, wait_thread, env, 0, &id));     
-
-        procrun_write_stdin(env);
-    }
-    else
-        ResumeThread(env->c->pinfo.hThread);        
-    return 0;
-}
-
-/* Delete the value from the registry
- */
-static int del_service_param(process_t *proc, const char *name)
-{
-    HKEY key;
-    char skey[256];
-    DWORD err, c;
-
-    sprintf(skey, PROCRUN_REGKEY_RPARAMS, proc->service.name);
-    if ((err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, skey, 0, NULL,
-        0, KEY_ALL_ACCESS,
-        NULL, &key, &c)) != ERROR_SUCCESS) {
-        DBPRINTF0(NULL);
-        DBPRINTF2("Failed Opening [%s] [%d]\n", skey, err);
-        return -1;
-    }
-
-    err = RegDeleteValue(key, name);
-    RegCloseKey(key); 
-    return (err != ERROR_SUCCESS);
-
-}
-
-/* Update or create the value in the registry
- *
- */
-static int set_service_param(process_t *proc, const char *name,
-                             const char *value, int len, int service)
-{
-    HKEY key;
-    char skey[256];
-    DWORD err;
-    DWORD c, type = REG_SZ;
-
-
-    if (service == 1) {
-        sprintf(skey, PROCRUN_REGKEY_SERVICES, proc->service.name);
-        if ((err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, skey,
-                            0, KEY_SET_VALUE, &key)) != ERROR_SUCCESS) {
-        DBPRINTF2("Failed Creating [%s] name [%s]\n", skey, name);
-            return -1;
-        }
-    }
-    else {
-        sprintf(skey, PROCRUN_REGKEY_RPARAMS, proc->service.name);
-        if ((err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, skey, 0, NULL,
-                              0, KEY_SET_VALUE,
-                              NULL, &key, &c)) != ERROR_SUCCESS) {
-        DBPRINTF0(NULL);
-        DBPRINTF2("Failed Creating [%s] [%d]\n", skey, err);
-            return -1;
-        }
-    }
-    DBPRINTF2("Creating [%s] name  [%s]\n", skey, name);
-    DBPRINTF2("Creating [%s] value [%s]\n", skey, value);
-    if (value) {
-        if (service == 2)
-            type = REG_BINARY;
-        else if (len > 0)
-            type = REG_MULTI_SZ;
-        else
-            len = strlen(value);
-        err = RegSetValueEx(key, name, 0, type,
-            (unsigned char *)value, len);
-    }
-    else 
-        err = RegSetValueEx(key, name, 0, REG_DWORD,
-        (unsigned char *)&len, sizeof(int));
-
-    RegCloseKey(key); 
-    return (err != ERROR_SUCCESS);
-}
-static const char *location_jvm_default[] = {
-    "\\jre\\bin\\classic\\jvm.dll",           /* Sun JDK 1.3 */
-    "\\bin\\classic\\jvm.dll",                /* Sun JRE 1.3 */
-    "\\jre\\bin\\client\\jvm.dll",            /* Sun JDK 1.4 */
-    "\\bin\\client\\jvm.dll",                 /* Sun JRE 1.4 */
-    NULL,
-};
-  
-/* 
- * Attempt to locate the jvm from the installation.
- */
-static char *procrun_find_java(process_t *proc, char *jhome)
-{
-  char path[MAX_PATH+1];
-  int x = 0;
-  HMODULE hm;
-  for(x=0; location_jvm_default[x] != NULL; x++) {
-      strcpy(path,jhome);
-      strcat(path,location_jvm_default[x]);
-      hm = LoadLibraryEx(path, NULL, 0); 
-      if(hm != NULL) {
-          DBPRINTF1("Found library at %s\n",path);
-          FreeLibrary(hm);
-          return pool_strdup(proc->pool, path);
-      }
-  }
-  return NULL;
-}
-   
-/*
- * Process the arguments and fill the process_t stuct.
- */
-static int process_args(process_t *proc, int argc, char **argv,
-                        char **java, char *path)
-{
-    int arglen = 0;
-    char *argp;
-    int i,n, sp;
-
-    /* parse command line */
-    *java = NULL;
-    if (!GetModuleFileName(NULL, path, MAX_PATH - 
-                           strlen(proc->service.name) - 7)) {
-        DBPRINTF0("GetModuleFileName failed\n");
-        return -1;
-    } 
-    strcat(path, " " PROC_ARG_RUN_SERVICE);
-    sp = strchr(proc->service.name, ' ') != NULL;
-    if(sp) {
-        strcat(path,"\"");
-    }
-    strcat(path, proc->service.name); 
-    if(sp) {
-        strcat(path,"\"");
-    }
-    for (i = 2; i < argc; i++) {
-        DBPRINTF2("Parsing %d [%s]\n", i, argv[i]);
-        if (strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == '-') {
-            argp = &argv[i][2];
-            if (STRNI_COMPARE(argp, PROCRUN_PARAMS_IMAGE))
-                proc->service.image = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_DESCRIPTION))
-                proc->service.description = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_DISPLAY))
-                proc->service.display = argv[++i];
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_WORKPATH))
-                proc->service.path = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_JVM_OPTS)) {
-                proc->java.opts = pool_calloc(proc->pool, strlen(argv[++i]) + 2);
-                strcpy(proc->java.opts, argv[i]);
-            }
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_JVM))
-                *java = argv[++i];
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STDINFILE))
-                proc->service.inname = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STDOUTFILE))
-                proc->service.outname = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STDERRFILE))
-                proc->service.errname = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STARTCLASS))
-                proc->java.start_class = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STOPCLASS))
-                proc->java.stop_class = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STARTUP)) {
-                ++i;
-                if (stricmp(argv[i], "auto") == 0)
-                    proc->service.startup = SERVICE_AUTO_START;
-                else if (stricmp(argv[i], "manual") == 0)
-                    proc->service.startup = SERVICE_DEMAND_START;
-            }
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_ACCOUNT))
-                proc->service.account = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_PASSWORD))
-                proc->service.password = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_INSTALL)) {
-                strcpy(path, argv[++i]); 
-                strcat(path, " " PROC_ARG_RUN_SERVICE);
-                if(sp) {
-                    strcat(path,"\"");
-                }
-                strcat(path, proc->service.name);
-                if(sp) {
-                    strcat(path, "\"");
-                }
-            }
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_ENVIRONMENT)) {
-              proc->service.environment = pool_strdup(proc->pool, argv[++i]);
-            }
-            else {
-                DBPRINTF1("Unrecognized option %s\n", argv[i]);
-                break;
-            }
-        }
-        else {
-           DBPRINTF1("Not an Command option option %s\n", argv[i]);
-           break; 
-        }
-    }
-    if (*java && !strnicmp(*java, "java", 4)) {
-        arglen = strlen(*java) + 1;
-    } else if(*java) {
-        int jlen = strlen(*java) +1;
-        if(stricmp(*java+(jlen-5),".dll")) {
-            /* Assume it is the java installation */
-            char *njava = procrun_find_java(proc, *java);
-            DBPRINTF1("Attempting to locate jvm from %s\n",*java);
-            if(njava != NULL) {
-              *java = njava;
-            }
-        }
-    } else if (proc->service.name)
-        arglen = strlen(proc->service.name) + 1;
-    for (n = i; n < argc; n++) {
-        arglen += (strlen(argv[n]) + 1);
-        if (strchr(argv[n], ' '))
-            arglen += 2;
-    }
-    if (arglen) {
-        ++arglen;
-        proc->argw = (char *)pool_calloc(proc->pool, arglen);
-        if (*java && !strnicmp(*java, "java", 4)) 
-            strcpy(proc->argw, *java);
-        else 
-            strcpy(proc->argw, proc->service.name);
-        for (n = i; n < argc; n++) {
-            strcat(proc->argw, " ");
-            if (strchr(argv[n], ' ')) {
-                strcat(proc->argw, "\"");
-                strcat(proc->argw, argv[n]);
-                strcat(proc->argw, "\"");
-            }
-            else
-                strcat(proc->argw, argv[n]);
-            DBPRINTF1("Adding cmdline %s\n", argv[n]);
-        }
-    }
-    if (!proc->service.startup)
-        proc->service.startup = SERVICE_AUTO_START;
-    return 0;
-}
-
-/*
- * Save the parameters in registry
- */
-void save_service_params(process_t *proc, char *java)
-{
-    int i;
-
-    if (proc->argw)
-        set_service_param(proc, PROCRUN_PARAMS_CMDARGS, proc->argw, 0, 0);
-    if (proc->service.description) {
-        set_service_param(proc, PROCRUN_PARAMS_DESCRIPTION,
-                          proc->service.description, 0, 0);
-        set_service_param(proc, PROCRUN_PARAMS_DESCRIPTION,
-                          proc->service.description, 0, 1);
-    }
-    if (proc->service.display) {
-        set_service_param(proc, PROCRUN_PARAMS_DISPLAY,
-                          proc->service.display, 0, 0);
-        set_service_param(proc, PROCRUN_PARAMS_DISPLAY,
-                          proc->service.display, 0, 1);
-    }
-    if (proc->service.image)
-        set_service_param(proc, PROCRUN_PARAMS_IMAGE,
-                          proc->service.image, 0, 0);
-    if (proc->service.path)
-        set_service_param(proc, PROCRUN_PARAMS_WORKPATH,
-                          proc->service.path, 0, 0);
-    if (proc->service.inname)
-        set_service_param(proc, PROCRUN_PARAMS_STDINFILE,
-                          proc->service.inname, 0, 0);
-    if (proc->service.outname)
-        set_service_param(proc, PROCRUN_PARAMS_STDOUTFILE,
-                          proc->service.outname, 0, 0);
-    if (proc->service.errname)
-        set_service_param(proc, PROCRUN_PARAMS_STDERRFILE,
-                          proc->service.errname, 0, 0);
-    if (java)
-        set_service_param(proc, PROCRUN_PARAMS_JVM,
-                          java, 0, 0);
-    if (proc->java.start_class)
-        set_service_param(proc, PROCRUN_PARAMS_STARTCLASS,
-                          proc->java.start_class, 0, 0);
-    if (proc->java.stop_class)
-        set_service_param(proc, PROCRUN_PARAMS_STOPCLASS,
-                          proc->java.stop_class, 0, 0);
-    /* Account and password allways comes as pair */
-    if (proc->service.account && proc->service.password) {
-        if (*proc->service.account == '-') {
-            del_service_param(proc, PROCRUN_PARAMS_ACCOUNT);
-            del_service_param(proc, PROCRUN_PARAMS_PASSWORD);
-        }
-        else {
-            unsigned char b[256];
-            set_service_param(proc, PROCRUN_PARAMS_ACCOUNT,
-                              proc->service.account, 0, 0);
-            simple_encrypt(100, proc->service.password, b);
-            set_service_param(proc, PROCRUN_PARAMS_PASSWORD,
-                              b, 256, 2);
-        }
-        
-    }
-    if (proc->service.environment) {
-        int l = strlen(proc->service.environment);
-        for(i=0; i < l; i++) {
-            if(proc->service.environment[i] == '#')
-                proc->service.environment[i] = '\0';
-        }
-        set_service_param(proc, PROCRUN_PARAMS_ENVIRONMENT,
-                        proc->service.environment, l+2, 0);
-    }
-
-
-    if (proc->service.startup != SERVICE_NO_CHANGE)
-        set_service_param(proc, PROCRUN_PARAMS_STARTUP,
-            proc->service.startup == SERVICE_AUTO_START ? "auto" : "manual",
-            0, 0);
-
-    if (proc->java.opts) {
-        int l = strlen(proc->java.opts);
-        /* change the string to zero separated for MULTI_SZ */
-        for (i = 0; i < l; i ++) {
-            if (proc->java.opts[i] == '#')
-                proc->java.opts[i] = '\0';
-        }
-        set_service_param(proc, PROCRUN_PARAMS_JVM_OPTS,
-                          proc->java.opts, l + 2, 0);
-    }
-}
-
-/* Install the service
- */
-static int procrun_install_service(process_t *proc, int argc, char **argv)
-{
-    SC_HANDLE service;
-    SC_HANDLE manager;
-    char path[MAX_PATH+1] = {0};
-    char *java = NULL;
-
-    if (!proc->service.name) {
-        return -1;
-    }
-
-    if (process_args(proc, argc, argv, &java, path)) {
-         DBPRINTF0("Installing NT service: process_args failed\n");
-         return -1;
-    }
-
-    DBPRINTF2("Installing NT service %s %s", path, proc->service.display);
-
-    manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
-    if (!manager) {    
-        return -1;
-    }
-
-    service = CreateService(manager, 
-                            proc->service.name,
-                            proc->service.display,
-                            SERVICE_ALL_ACCESS,
-                            SERVICE_WIN32_OWN_PROCESS,
-                            proc->service.startup,
-                            SERVICE_ERROR_NORMAL,
-                            path,
-                            NULL,
-                            NULL,
-                            SERVICE_DEPENDENCIES,
-                            NULL,
-                            NULL);
-    if (service) {
-        CloseServiceHandle(service);
-        CloseServiceHandle(manager);
-    }
-    else {
-        DBPRINTF0("CreateService failed\n");
-        CloseServiceHandle(manager);
-        return -1;
-    }
-
-    /* Save parameters in registry */
-    save_service_params(proc,java);
-
-    DBPRINTF0("NT service installed succesfully\n");
-    SetEvent(proc->events[0]);
-    return 0;
-}
-
-/* Install service on win9x */
-static int procrun_install_service9x(process_t *proc, int argc, char **argv)
-{
-    HKEY        hkey;
-    DWORD rv;
-    char szPath[MAX_PATH+1] = {0};
-
-    char path[MAX_PATH+1];
-    char *display = NULL;
-    char *java = NULL;
-
-    DBPRINTF0( "InstallSvc for non-NT\r\n");
-
-    if (!proc->service.name) {
-        return -1;
-    }
-
-    rv = RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows"
-              "\\CurrentVersion\\RunServices", &hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF0( "Could not open the RunServices registry key\r\n");
-        return -1;
-    }
-
-    if (process_args(proc, argc, argv, &java, path)) {
-         DBPRINTF0("Installing service: process_args failed\n");
-         return -1;
-    }
-
-    DBPRINTF1("Installing service %s\n", path);
-
-    rv = RegSetValueEx(hkey, proc->service.name, 0, REG_SZ,
-               (unsigned char *) path,
-               strlen(path) + 1);
-    RegCloseKey(hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF2( "Could not add %s:%s to RunServices Registry Key\r\n",
-                  proc->service.name, path);
-        return -1;
-    }
-
-    strcpy(szPath,
-         "SYSTEM\\CurrentControlSet\\Services\\");
-    strcat(szPath,proc->service.name);
-    rv = RegCreateKey(HKEY_LOCAL_MACHINE, szPath, &hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF1( "Could not create/open the %s registry key\r\n",
-            szPath);
-        return -1;
-    }
-    rv = RegSetValueEx(hkey, "ImagePath", 0, REG_SZ,
-               (unsigned char *) path,
-               strlen(path) + 1);
-    if (rv != ERROR_SUCCESS) {
-        RegCloseKey(hkey);
-        DBPRINTF0( "Could not add ImagePath to our Registry Key\r\n");
-        return -1;
-    }
-    rv = RegSetValueEx(hkey, "DisplayName", 0, REG_SZ,
-               (unsigned char *) proc->service.display,
-               strlen(proc->service.display) + 1);
-    RegCloseKey(hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF0( "Could not add DisplayName to our Registry Key\r\n");
-        return -1;
-    }
-
-    /* Save parameters in registry */
-    save_service_params(proc,java);
-
-    DBPRINTF0("service installed succesfully\n");
-    SetEvent(proc->events[0]);
-    return 0;
-}
-
-/* Update the service parameters
- * This is the main parser for //US//
- */
-int procrun_update_service(process_t *proc, int argc, char **argv)
-{
-    SC_HANDLE service;
-    SC_HANDLE manager;
-    char *argp;
-    char path[MAX_PATH+1];
-    char *java = NULL;
-    int arglen = 0, sp;
-
-    int i, n;
-    if (!proc->service.name) {
-        return -1;
-    }
-    if (!GetModuleFileName(NULL, path, MAX_PATH - 
-                           strlen(proc->service.name) - 7)) {
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    sp = strchr(proc->service.name, ' ') != NULL;
-    strcat(path, " " PROC_ARG_RUN_SERVICE);
-    if(sp) {
-        strcat(path,"\"");
-    }
-    strcat(path, proc->service.name);
-    if(sp) {
-        strcat(path, "\"");
-    }
-    DBPRINTF1("Updating service %s\n", path);
-
-    manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
-    if (!manager) {    
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    service = OpenService(manager, proc->service.name, SERVICE_ALL_ACCESS);
-    if (!service) {
-        DBPRINTF0(NULL);
-        CloseServiceHandle(manager);
-        return -1;
-    }
-    proc->service.startup = SERVICE_NO_CHANGE;
-    proc->service.image = NULL;
-    proc->service.description = NULL;
-    proc->service.path = NULL;
-    proc->service.inname = NULL;
-    proc->service.outname = NULL;
-    proc->service.errname = NULL;
-    proc->java.start_class = NULL;
-    proc->java.stop_class = NULL;
-    proc->java.opts = NULL;
-    proc->service.account  = NULL;
-    proc->service.password = NULL;
-    proc->service.display = NULL;
-    proc->argw = NULL;
-    /* parse command line */
-    for (i = 2; i < argc; i++) {
-        if (strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == '-') {
-            argp = &argv[i][2];
-            if (STRNI_COMPARE(argp, PROCRUN_PARAMS_IMAGE))
-                proc->service.image = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_DESCRIPTION))
-                proc->service.description = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_DISPLAY))
-                proc->service.display = argv[++i];
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_WORKPATH))
-                proc->service.path = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_JVM_OPTS)) {
-                proc->java.opts = pool_calloc(proc->pool, strlen(argv[++i]) + 2);
-                strcpy(proc->java.opts, argv[i]);
-            }
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_JVM))
-                java = argv[++i];
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STDINFILE))
-                proc->service.inname = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STDOUTFILE))
-                proc->service.outname = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STDERRFILE))
-                proc->service.errname = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STARTCLASS))
-                proc->java.start_class = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STOPCLASS))
-                proc->java.stop_class = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_STARTUP)) {
-                ++i;
-                if (stricmp(argv[i], "auto") == 0)
-                    proc->service.startup = SERVICE_AUTO_START;
-                else if (stricmp(argv[i], "manual") == 0)
-                    proc->service.startup = SERVICE_DEMAND_START;
-            }
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_ACCOUNT))
-                proc->service.account = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_PASSWORD))
-                proc->service.password = pool_strdup(proc->pool, argv[++i]);
-            else if (STRNI_COMPARE(argp, PROCRUN_PARAMS_ENVIRONMENT))
-                proc->service.environment = pool_strdup(proc->pool, argv[++i]);
-            else
-                break;
-        }
-        else
-            break;
-    }
-
-    if (java && strnicmp(java, "java", 4)) {
-        int jlen = strlen(java) + 1;
-        if(stricmp(java+(jlen-5),".dll")) {
-            /* Assume it is the java installation */
-            char *njava = procrun_find_java(proc, java);
-            DBPRINTF1("Attempting to locate jvm from %s\n",java);
-            if(njava != NULL) {
-              java = njava;
-            }
-        }
-    }
- 
-    if (i < argc) {
-        if (java && !strnicmp(java, "java", 4))
-            arglen = strlen(java) + 1;
-        else if (proc->service.name)
-            arglen = strlen(proc->service.name) + 1;
-        for (n = i; n < argc; n++) {
-            arglen += strlen(argv[n]) + 1;
-            if (strchr(argv[n], ' '))
-                arglen += 2;
-        }
-        if (arglen) {
-            ++arglen;
-            proc->argw = (char *)pool_calloc(proc->pool, arglen);
-            if (java && !strnicmp(java, "java", 4))
-                strcpy(proc->argw, java);
-            else
-                strcpy(proc->argw, proc->service.name);
-            for (n = i; n < argc; n++) {
-                strcat(proc->argw, " ");
-                if (strchr(argv[n], ' ')) {
-                    strcat(proc->argw, "\"");
-                    strcat(proc->argw, argv[n]);
-                    strcat(proc->argw, "\"");
-                }
-                else
-                    strcat(proc->argw, argv[n]);
-                DBPRINTF1("Adding cmdline %s\n", argv[n]);
-            }
-        }
-    }
-    ChangeServiceConfig(service,
-                        SERVICE_NO_CHANGE,
-                        proc->service.startup,
-                        SERVICE_NO_CHANGE,
-                        NULL,
-                        NULL,
-                        NULL,
-                        NULL,
-                        NULL,
-                        NULL,
-                        proc->service.display);
-
-    CloseServiceHandle(service);
-    CloseServiceHandle(manager);
-    
-    save_service_params(proc,java);
-
-    return 0;
-}
-
-/* Delete the service
- * Removes the service form registry and SCM.
- * Stop the service if running.
- */
-static int procrun_delete_service(process_t *proc)
-{
-    SC_HANDLE service;
-    SC_HANDLE manager;
-    SERVICE_STATUS status;
-    char skey[MAX_PATH+1];
-    DWORD err;
-
-    if (!proc->service.name) {
-        return -1;
-    }
-    DBPRINTF1("Deleting service %s", proc->service.name);
-
-    sprintf(skey, PROCRUN_REGKEY_RSERVICES, proc->service.name);
-    if ((err = SHDeleteKey(HKEY_LOCAL_MACHINE, skey)) != ERROR_SUCCESS) {
-        DBPRINTF2("Failed Deleting [%s] [%d]\n", skey, err);
-    }
-
-    manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
-    if (!manager) {    
-        DBPRINTF0(NULL);
-        return -1;
-    }
-    service = OpenService(manager, proc->service.name, SERVICE_ALL_ACCESS);
-    
-    if (service) {
-        BOOL ss = FALSE;
-        QueryServiceStatus(service, &status);
-        if (status.dwCurrentState != SERVICE_RUNNING)
-            ss = DeleteService(service);
-        else {
-            /* Stop the service */
-            if (ControlService(service, SERVICE_CONTROL_STOP, &status)) {
-                Sleep(1000);
-                while (QueryServiceStatus(service, &status)) {
-                    if (status.dwCurrentState == SERVICE_STOP_PENDING)
-                        Sleep(1000);
-                    else
-                        break;
-                }
-            }
-            QueryServiceStatus(service, &status);
-            if (status.dwCurrentState != SERVICE_RUNNING)
-                ss = DeleteService(service);
-        }
-        CloseServiceHandle(service);
-        CloseServiceHandle(manager);
-        if (!ss)
-            return -1;
-    }
-    else {
-        DBPRINTF0(NULL);
-        CloseServiceHandle(manager);
-        return -1;
-    }
-    DBPRINTF0("NT service deleted succesfully\n");
-    SetEvent(proc->events[0]);
-    return 0;
-}
- 
-/* remove service (non NT) stopping it looks ugly!!! so we let it run. */
-static int procrun_delete_service9x(process_t *proc)
-{
-    HKEY hkey;
-    DWORD rv;
- 
-    if (!proc->service.name) {
-        return -1;
-    }
-    DBPRINTF1("Deleting service %s", proc->service.name);
-
-    rv = RegOpenKey(HKEY_LOCAL_MACHINE,
-        "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices",
-        &hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF0( "Could not open the RunServices registry key.\r\n");
-        return -1;
-    }
-    rv = RegDeleteValue(hkey, proc->service.name);
-    RegCloseKey(hkey);
-    if (rv != ERROR_SUCCESS)
-        DBPRINTF0( "Could not delete the RunServices entry.\r\n");
- 
-    rv = RegOpenKey(HKEY_LOCAL_MACHINE,
-        "SYSTEM\\CurrentControlSet\\Services", &hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF0( "Could not open the Services registry key.\r\n");
-        return -1;
-    }
-    rv = RegDeleteKey(hkey, proc->service.name);
-    RegCloseKey(hkey);
-    if (rv != ERROR_SUCCESS) {
-        DBPRINTF0( "Could not delete the Services registry key.\r\n");
-        return -1;
-    }
-    DBPRINTF0("service deleted succesfull\n");
-    SetEvent(proc->events[0]);
-    return 0;
-}
-
-/* This is the WndProc procedure for our invisible window.
- * When our subclasssed tty window receives the WM_CLOSE, WM_ENDSESSION,
- * or WM_QUERYENDSESSION messages, the message is dispatched to our hidden
- * window (this message process), and we call the installed HandlerRoutine
- * that was registered by the app.
- */
-#ifndef ENDSESSION_LOGOFF
-#define ENDSESSION_LOGOFF    0x80000000
-#endif
-static LRESULT CALLBACK ttyConsoleCtrlWndProc(HWND hwnd, UINT msg,
-                                              WPARAM wParam, LPARAM lParam)
-{
-
-    if (msg == WM_CREATE) {
-        DBPRINTF0("ttyConsoleCtrlWndProc WM_CREATE\n");
-        return 0;
-    } else if (msg == WM_DESTROY) {
-        DBPRINTF0("ttyConsoleCtrlWndProc WM_DESTROY\n");
-        return 0;
-    } else if (msg == WM_CLOSE) {
-        /* Call StopService?. */
-        DBPRINTF0("ttyConsoleCtrlWndProc WM_CLOSE\n");
-        return 0; /* May return 1 if StopService failed. */
-    } else if ((msg == WM_QUERYENDSESSION) || (msg == WM_ENDSESSION)) {
-        if (lParam & ENDSESSION_LOGOFF) {
-            /* Here we have nothing to our hidden windows should stay. */
-            DBPRINTF0(TEXT("ttyConsoleCtrlWndProc LOGOFF\n"));
-            return(1); /* Otherwise it cancels the logoff */
-        } else {
-            /* Stop Service. */
-            DBPRINTF0("ttyConsoleCtrlWndProc SHUTDOWN\n");
-            SetEvent(g_env->m->events[0]);
-
-            /* Wait for the JVM to stop */
-            DBPRINTF1("Stopping: main thread %08x\n",g_env->m->pinfo.hThread);
-            if (g_env->m->pinfo.hThread != NULL) {
-                DBPRINTF0("ttyConsoleCtrlWndProc waiting for main\n");
-                WaitForSingleObject(g_env->m->pinfo.hThread, 60000); 
-                DBPRINTF0("ttyConsoleCtrlWndProc main thread finished\n");
-            }
-
-            return(1); /* Otherwise it cancels the shutdown. */
-        }
-    }
-    return (DefWindowProc(hwnd, msg, wParam, lParam));
-}                                                                               
-/* ttyConsoleCreateThread is the process that runs within the user app's
- * context.  It creates and pumps the messages of a hidden monitor window,
- * watching for messages from the system, or the associated subclassed tty
- * window.  Things can happen in our context that can't be done from the
- * tty's context, and visa versa, so the subclass procedure and this hidden
- * window work together to make it all happen.
- */
-static DWORD WINAPI ttyConsoleCtrlThread(LPVOID param)
-{
-    HWND monitor_hwnd;
-    WNDCLASS wc;
-    MSG msg;
-    wc.style         = CS_GLOBALCLASS;
-    wc.lpfnWndProc   = ttyConsoleCtrlWndProc;
-    wc.cbClsExtra    = 0;
-    wc.cbWndExtra    = 8;
-    wc.hInstance     = NULL;
-    wc.hIcon         = NULL;
-    wc.hCursor       = NULL;
-    wc.hbrBackground = NULL;
-    wc.lpszMenuName  = NULL;
-    wc.lpszClassName = "ApacheJakartaService";
- 
-    if (!RegisterClass(&wc)) {
-        DBPRINTF0("RegisterClass failed\n");
-        return 0;
-    }
- 
-    /* Create an invisible window */
-    monitor_hwnd = CreateWindow(wc.lpszClassName, 
-                                "ApacheJakartaService",
-                                WS_OVERLAPPED & ~WS_VISIBLE,
-                                CW_USEDEFAULT, CW_USEDEFAULT,
-                                CW_USEDEFAULT, CW_USEDEFAULT,
-                                NULL, NULL,
-                                GetModuleHandle(NULL), NULL);
- 
-    if (!monitor_hwnd) {
-        DBPRINTF0("RegisterClass failed\n");
-        return 0;
-    }
- 
-    while (GetMessage(&msg, NULL, 0, 0))
-    {
-        TranslateMessage(&msg);
-        DispatchMessage(&msg);
-    }
- 
-    return 0;
-}
-/*
- * Register the process to resist logoff and start the thread that will receive
- * the shutdown via a hidden window.
- */
-BOOL Windows9xServiceCtrlHandler()
-{
-    HANDLE hThread;
-    DWORD tid;
-    HINSTANCE hkernel;
-    DWORD (WINAPI *register_service_process)(DWORD, DWORD) = NULL;
-
-    /* If we have not yet done so */
-    FreeConsole();
-
-    /* Make sure the process will resist logoff */
-    hkernel = LoadLibrary("KERNEL32.DLL");
-    if (!hkernel) {
-        DBPRINTF0("LoadLibrary KERNEL32.DLL failed\n");
-        return 0;
-    }
-    register_service_process = (DWORD (WINAPI *)(DWORD, DWORD)) 
-        GetProcAddress(hkernel, "RegisterServiceProcess");
-    if (register_service_process == NULL) {
-        DBPRINTF0("dlsym RegisterServiceProcess failed\n");
-        return 0;
-    }
-    if (!register_service_process(0,TRUE)) {
-        FreeLibrary(hkernel);
-        DBPRINTF0("register_service_process failed\n");
-        return 0;
-    }
-    DBPRINTF0("procrun registered as a service\n");
-
-    /*
-     * To be handle notice the shutdown, we need a thread and window.
-     */
-     hThread = CreateThread(NULL, 0, ttyConsoleCtrlThread,
-                               (LPVOID)NULL, 0, &tid);
-     if (hThread) {
-        CloseHandle(hThread);
-        return TRUE;
-     }
-    DBPRINTF0("jsvc shutdown listener start failed\n");
-    return TRUE;
-}
-
-/* Report the service status to the SCM
- */
-int report_service_status(DWORD dwCurrentState,
-                          DWORD dwWin32ExitCode,
-                          DWORD dwWaitHint,
-                          process_t *proc)
-{
-   static DWORD dwCheckPoint = 1;
-   BOOL fResult = TRUE;
-
-   if (proc->service.mode && proc->service.h_status) {
-      if (dwCurrentState == SERVICE_START_PENDING)
-         proc->service.status.dwControlsAccepted = 0;
-      else
-         proc->service.status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
-
-      proc->service.status.dwCurrentState = dwCurrentState;
-      proc->service.status.dwWin32ExitCode = dwWin32ExitCode;
-      proc->service.status.dwWaitHint = dwWaitHint;
-
-      if ((dwCurrentState == SERVICE_RUNNING) ||
-          (dwCurrentState == SERVICE_STOPPED))
-         proc->service.status.dwCheckPoint = 0;
-      else
-        proc->service.status.dwCheckPoint = dwCheckPoint++;
-      if (g_is_windows_nt)
-         fResult = SetServiceStatus(proc->service.h_status, &proc->service.status);
-      if (!fResult) {
-         DBPRINTF0("SetServiceStatus Failed\n");
-         DBPRINTF0(NULL);
-      }
-   }
-   return fResult;
-}
-
-/* Service controll handler
- */
-void WINAPI service_ctrl(DWORD dwCtrlCode)
-{
-    switch (dwCtrlCode) {
-        case SERVICE_CONTROL_STOP:
-            report_service_status(SERVICE_STOP_PENDING, NO_ERROR, 0,
-                                  g_env->m);
-            DBPRINTF0("ServiceCtrl STOP\n");
-            SetEvent(g_env->m->events[0]);
-            return;
-        case SERVICE_CONTROL_INTERROGATE:
-        break;
-        default:
-        break;
-   }
-
-   report_service_status(g_env->m->service.status.dwCurrentState,
-                         NO_ERROR, 0, g_env->m);
-}
-
-/* Console controll handler
- * 
- */
-BOOL WINAPI console_ctrl(DWORD dwCtrlType)
-{
-    switch (dwCtrlType) {
-        case CTRL_BREAK_EVENT:
-            DBPRINTF0("Captured CTRL+BREAK Event\n");
-            SetEvent(g_env->m->events[0]);
-            return TRUE;
-        case CTRL_C_EVENT:
-            DBPRINTF0("Captured CTRL+C Event\n");
-            SetEvent(g_env->m->events[0]);
-            return TRUE;
-        case CTRL_CLOSE_EVENT:
-            DBPRINTF0("Captured CLOSE Event\n");
-            SetEvent(g_env->m->events[0]);
-            return TRUE;
-        case CTRL_SHUTDOWN_EVENT:
-            DBPRINTF0("Captured SHUTDOWN Event\n");
-            SetEvent(g_env->m->events[0]);
-            return TRUE;
-        break;
-
-   }
-   return FALSE;
-}
-
-/* Main JVM thread
- * Like redirected process, the redirected JVM application
- * is run in the separate thread.
- */
-DWORD WINAPI java_thread(LPVOID param)
-{
-    DWORD rv;
-    procrun_t *env = (procrun_t *)param;
-    
-    if (!param)
-        return -1;
-    rv = procrun_init_jvm(env->m);
-    jni_detach(env->m);
-
-    SetEvent(env->m->events[0]);
-    return rv;
-}
-
-int service_main(int argc, char **argv)
-{
-    DWORD fired = 0;
-    HANDLE jh;
-    int   rv = -1;
-    
-    
-    g_env->m->service.status.dwServiceType      = SERVICE_WIN32_OWN_PROCESS;
-    g_env->m->service.status.dwCurrentState     = SERVICE_START_PENDING; 
-    g_env->m->service.status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE; 
-    g_env->m->service.status.dwWin32ExitCode    = 0; 
-    g_env->m->service.status.dwServiceSpecificExitCode = 0; 
-    g_env->m->service.status.dwCheckPoint       = 0; 
-    g_env->m->service.status.dwWaitHint         = 0; 
-
-    g_env->m->service.status.dwServiceSpecificExitCode = 0;
-    if (g_env->m->service.mode && g_is_windows_nt) {
-        g_env->m->service.h_status = RegisterServiceCtrlHandler(g_env->m->service.name,
-                                                                     service_ctrl);
-        if (!g_env->m->service.h_status)
-            goto cleanup;
-    } else
-        g_env->m->service.h_status = 0;
-
-    report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000,
-                          g_env->m);
-    if (g_env->m->java.dll) {
-        if (g_env->m->java.jbin == NULL) {
-            DWORD id;
-            /* Create the main JVM thread so we don't get blocked */
-            jh = CreateThread(NULL, 0, java_thread, g_env, 0, &id);
-            pool_handle(g_env->m->pool, jh);
-            rv = 0;
-        }
-        else {
-            /* Redirect java or javaw */
-            if ((rv = procrun_init_jvm(g_env->m)) == 0) {
-                rv = procrun_redirect(g_env->m->service.image,
-                                      g_env->m->envp, g_env, 1);    
-            }
-        }
-    } 
-    else {
-        rv = procrun_redirect(g_env->m->service.image,
-                              g_env->m->envp, g_env, 1);    
-    }
-    if (rv == 0) {
-        report_service_status(SERVICE_RUNNING, NO_ERROR, 0,
-                              g_env->m);
-        DBPRINTF2("Service %s Started %d\n", g_env->m->service.name, rv);
-
-    }
-    /* Wait for shutdown event or child exit */
-    while (rv == 0) {
-        fired = WaitForMultipleObjects(4, g_env->m->events,
-                                       FALSE, INFINITE); 
-        
-        if (fired == WAIT_OBJECT_0 ||
-            fired == (WAIT_OBJECT_0 + 1) ||
-            fired == WAIT_TIMEOUT)
-            break;
-    }
-
-cleanup:
-    DBPRINTF1("Stoping Service %s\n", g_env->m->service.name);
-    report_service_status(SERVICE_STOP_PENDING, NO_ERROR, 3000,
-                          g_env->m);
-    procrun_destroy_jvm(g_env->m, jh);
-
-    inject_exitprocess(&g_env->c->pinfo);
-    report_service_status(SERVICE_STOPPED, 0, 0,
-                          g_env->m);
-
-    DBPRINTF0("Setting Shutdown Event 0\n");
-    SetEvent(g_env->m->events[0]);
-    return rv;
-}
-
-/* Procrun main function
- */
-int procrun_main(int argc, char **argv, char **envp, procrun_t *env)
-{
-    int i, mode = 0;
-    char event[64];
-    DWORD fired;
-    int   rv = -1;
-    OSVERSIONINFO osver;
-    HANDLE handle;
-    BOOL isok;
-
-    SERVICE_TABLE_ENTRY dispatch_table[] = {
-        {NULL, NULL},
-        {NULL, NULL}
-    };
-
-   osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-    if (GetVersionEx(&osver)) {
-        if (osver.dwPlatformId >= VER_PLATFORM_WIN32_NT)
-            g_is_windows_nt = 1;
-    }
-    DBPRINTF1("OS Version %d\n", g_is_windows_nt);
-
-    /* Set console handler to capture CTRL events */
-    SetConsoleCtrlHandler((PHANDLER_ROUTINE)console_ctrl, TRUE);
-    env->m->pool = pool_create();
-    env->c->pool = pool_create();
-    for (i = 0; i < 4; i ++) {
-        env->m->h_stdin[i]   = INVALID_HANDLE_VALUE;
-        env->m->h_stdout[i]  = INVALID_HANDLE_VALUE;
-        env->m->h_stderr[i]  = INVALID_HANDLE_VALUE;
-        env->c->h_stdin[i]  = INVALID_HANDLE_VALUE;
-        env->c->h_stdout[i] = INVALID_HANDLE_VALUE;
-        env->c->h_stderr[i] = INVALID_HANDLE_VALUE;
-    }
-
-    env->m->pinfo.dwProcessId = GetCurrentProcessId();
-    env->m->pinfo.dwThreadId = GetCurrentThreadId();
-
-    isok = DuplicateHandle(GetCurrentProcess(),GetCurrentProcess(),
-                    GetCurrentProcess(),&handle,PROCESS_ALL_ACCESS,
-                    FALSE,0);
-    if (isok)
-        env->m->pinfo.hProcess = handle;
-    else {
-        DBPRINTF0("DuplicateHandle failed on Process\n");
-        env->m->pinfo.hProcess = GetCurrentProcess();
-    }
-
-
-    isok = DuplicateHandle(GetCurrentProcess(),GetCurrentThread(),
-                    GetCurrentProcess(),&handle,PROCESS_ALL_ACCESS,
-                    FALSE,0);
-    if (isok)
-        env->m->pinfo.hThread = handle;
-    else {
-        DBPRINTF0("DuplicateHandle failed on Thread\n");
-        env->m->pinfo.hThread = GetCurrentThread();
-    }
-    env->m->envp = envp;
-
-    DBPRINTF2("handles: proc %08x thread %08x\n",env->m->pinfo.hProcess,env->m->pinfo.hThread);
-
-    SetProcessShutdownParameters(0x300, SHUTDOWN_NORETRY);
-    if (argc > 1)
-        mode = parse_args(argc, argv, env->m);
-    else /* nothing to do. exit... */
-        return 0;
-    
-    procrun_readenv(env->m, envp);
-    
-    /* Add the pid to the client env */
-    procrun_addenv(PROCRUN_ENV_PPID, NULL, (int)GetCurrentProcessId(),
-                   env->m);
-    
-    procrun_service_params(env->m);
-    /* Check if we have a JVM */
-    if (procrun_load_jvm(env->m, mode) < 0)
-        goto cleanup;
-    if(env->m->service.environment) {
-        char *nenv = env->m->service.environment;
-        while(*nenv) {
-            char *cenv = pool_strdup(env->c->pool, nenv);
-            char *equals = strchr(cenv, '=');
-            if(equals != NULL) {
-                char *value = nenv + (equals-cenv)+1;
-                *++equals = '\0';
-                procrun_addenv(cenv, value, 0, env->c);
-            }
-            nenv += strlen(nenv)+1;
-        }
-    }
-    /* Create the four events that will cause us to exit
-     */
-    sprintf(event, "PROC_SHUTDOWN_EVENT%d", GetCurrentProcessId());
-    env->m->events[0] = CreateEvent(NULL, TRUE, FALSE, event);
-    sprintf(event, "PROC_EXITWAIT_EVENT%d", GetCurrentProcessId());
-    env->m->events[1] = CreateEvent(NULL, TRUE, FALSE, event);
-    sprintf(event, "PROC_CLOSESTDOUT_EVENT%d", GetCurrentProcessId());
-    env->m->events[2] = CreateEvent(NULL, TRUE, FALSE, event);
-    sprintf(event, "PROC_CLOSESTDERR_EVENT%d", GetCurrentProcessId());
-    env->m->events[3] = CreateEvent(NULL, TRUE, FALSE, event);
-    pool_handle(env->m->pool, env->m->events[0]);
-    pool_handle(env->m->pool, env->m->events[1]);
-    pool_handle(env->m->pool, env->m->events[2]);
-    pool_handle(env->m->pool, env->m->events[3]);
-
-    DBPRINTF2("running in mode %d %p\n", mode, env->m->java.dll);
-    DBPRINTF1("Events %p\n", env->m->events[0]);
-
-    switch (mode) {
-        /* Standard run modes */
-        case PROCRUN_CMD_TEST_SERVICE:
-#ifdef PROCRUN_WINAPP
-        /*
-         * GUIT: Display as Try application
-         * GUOD: Immediately popup console dialog wrapper
-         */
-        case PROCRUN_CMD_GUIT_SERVICE:
-        case PROCRUN_CMD_GUID_SERVICE:
-            {
-                DWORD gi;
-                /* This one if for about box */
-                LoadLibrary("riched32.dll");
-                CreateThread(NULL, 0, gui_thread, g_env, 0, &gi);
-            }
-#else
-            if (env->m->service.description)
-                SetConsoleTitle(env->m->service.description);
-            else if (env->m->service.name)
-                SetConsoleTitle(env->m->service.name);
-#endif
-#ifdef _DEBUG
-            debug_process(argc, argv, env->m);
-#endif
-            service_main(argc, argv);
-            break;
-#ifdef PROCRUN_WINAPP
-        /* Display the service properties dialog
-         */
-        case PROCRUN_CMD_EDIT_SERVICE:
-            LoadLibrary("riched32.dll");
-            gui_thread(g_env);
-            break;
-#endif
-        /* Management modes */
-        case PROCRUN_CMD_INSTALL_SERVICE:
-            if (g_is_windows_nt)
-                rv = procrun_install_service(env->m, argc, argv);
-            else
-                rv = procrun_install_service9x(env->m, argc, argv);
-            break;
-        case PROCRUN_CMD_UPDATE_SERVICE:
-            if (g_is_windows_nt) {
-                rv = procrun_update_service(env->m, argc, argv);
-                SetEvent(env->m->events[0]);
-            }
-            else {
-              // rv = procrun_update_service9x(env->m, argc, argv);
-                rv = -1;
-                DBPRINTF0("UPDATE SERVICE is unimplemented on 9x for now\n");
-            }
-            break;
-        case PROCRUN_CMD_DELETE_SERVICE:
-            if (g_is_windows_nt)
-                rv = procrun_delete_service(env->m);
-            else
-                rv = procrun_delete_service9x(env->m);
-            break;
-        case PROCRUN_CMD_STOP_SERVICE:
-            rv = -1;
-            DBPRINTF0("STOP SERVICE is unimplemented for now\n");
-            break;
-        case PROCRUN_CMD_RUN_SERVICE:
-            if (g_proc_stderr_file==0) {
-                g_proc_stderr_file = open("c:/jakarta-service.log",O_CREAT|O_APPEND|O_RDWR);
-                if (g_proc_stderr_file < 0)
-                    g_proc_stderr_file = 0;
-            }
-            debug_process(argc, argv, env->m);
-            env->m->service.mode = 1;
-            if (g_is_windows_nt) {
-                dispatch_table[0].lpServiceName = env->m->service.name;
-                dispatch_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)service_main;
-                rv = (StartServiceCtrlDispatcher(dispatch_table) == FALSE);
-            } else {
-                Windows9xServiceCtrlHandler();
-                service_main(argc,argv);
-            }
-            break;
-#ifdef PROCRUN_WINAPP
-        case PROCRUN_CMD_GUID_PROCESS:
-            /* run as WIN32 application */
-            {
-                DWORD gi;
-                ac_use_try = 1;
-                LoadLibrary("riched32.dll");
-                CreateThread(NULL, 0, gui_thread, g_env, 0, &gi);
-            }
-            env->m->service.name = argv[0];
-            env->m->service.description = argv[2];
-            rv = procrun_redirect(argv[2], envp, env, 1);
-            break;
-
-#endif
-        default:
-            /* Run the process 
-             * We can be master or called by env.
-             */
-            rv = procrun_redirect(argv[1], envp, env, 1);
-            break;
-    }
-    
-    /* Wait for shutdown event or child exit */
-    while (rv == 0) {
-        fired = WaitForMultipleObjects(4, env->m->events,
-                                       FALSE, INFINITE); 
-        
-        if (fired == WAIT_OBJECT_0 ||
-            fired == (WAIT_OBJECT_0 + 1) ||
-            fired == WAIT_TIMEOUT)
-            break;
-    }
-    DBPRINTF1("Exiting from mode %d\n", mode);
-    /* clean up... */
-cleanup:
-
-#ifdef PROCRUN_WINAPP
-    if (ac_main_hwnd)
-        ac_show_try_icon(ac_main_hwnd, NIM_DELETE, NULL, 0);
-#endif
-    procrun_destroy_jvm(env->m, NULL);
-    inject_exitprocess(&env->c->pinfo);
-    i = pool_destroy(env->m->pool);
-    i = pool_destroy(env->c->pool);
-    if (g_proc_stderr_file)
-        close(g_proc_stderr_file);
-    return 0;
-}
-
-static procrun_t *alloc_environment()
-{
-
-    procrun_t *env = (procrun_t *)malloc(sizeof(procrun_t));
-    if (env) {
-        env->m = (process_t *)calloc(1, sizeof(process_t));
-        env->c = (process_t *)calloc(1, sizeof(process_t));
-    }
-    return env;
-}
-
-static void free_environment(procrun_t *env)
-{
-    if (env) {
-        free(env->m);
-        free(env->c);
-        free(env);
-        env = NULL;
-    }
-}
-
-#if defined(PROCRUN_WINAPP)
-#pragma message("Compiling WIN32 Application mode")
-
-int WINAPI WinMain(HINSTANCE hInstance,
-                    HINSTANCE hPrevInstance,
-                    LPSTR lpCmdLine,
-                    int nCmdShow)
-{
-    int rv;
-    procrun_t *env = alloc_environment();
-    g_proc_mode = PROCRUN_MODE_WINAPP;
-    g_env = env;
-    ac_instance = hInstance;
-    rv = procrun_main(__argc, __argv, _environ, env);
-
-    free_environment(env);
-    return rv;
-}
-#elif defined(PROCRUN_CONSOLE)
-#pragma message("Compiling CONSOLE Application mode")
-
-void __cdecl main(int argc, char **argv)
-{
-
-    procrun_t *env = alloc_environment();
-    g_proc_mode = PROCRUN_MODE_CONSOLE;
-    g_env = env;
-
-    procrun_main(argc, argv, _environ, env);
-
-    free_environment(env);
-}
-#elif defined(PROCRUN_WINDLL)
-#pragma message("Compiling Control Panel Application mode")
-
-BOOL WINAPI DllMain(HINSTANCE hInst,
-                    ULONG ulReason,
-                    LPVOID lpReserved)
-{ 
-
-    switch (ulReason) {
-        case DLL_PROCESS_ATTACH:
-            g_env = NULL;
-        break;
-        case DLL_PROCESS_DETACH:
-            free_environment(g_env);
-        break;
-        default:
-        break;
-    } 
-    return TRUE;     
-}
-
-/* DLL mode functions
- * Ment to be used either from other programs
- * or from installers
- */
-
-/* Install the service.
- * This is a wrapper for //IS//
- */
-__declspec(dllexport) void InstallService(const char *service_name,
-                                          const char *install,
-                                          const char *image_path,
-                                          const char *display_name,
-                                          const char *description)
-{
-    int argc = 0;
-    char *argv[12];
-    char b[MAX_PATH];
-
-    procrun_t *env = alloc_environment();
-    g_proc_mode = PROCRUN_MODE_WINDLL;
-    g_env = env;
-    
-    argv[argc++] = "PROCRUN.DLL";
-    strcpy(b, PROC_ARG_INSTALL_SERVICE);
-    strcat(b, service_name);
-    argv[argc++] = b;
-    argv[argc++] = "--" PROCRUN_PARAMS_IMAGE;
-    argv[argc++] = (char *)image_path;
-    argv[argc++] = "--" PROCRUN_PARAMS_INSTALL;
-    argv[argc++] = (char *)install;
-    argv[argc++] = "--" PROCRUN_PARAMS_DISPLAY;
-    argv[argc++] = (char *)display_name;
-    argv[argc++] = "--" PROCRUN_PARAMS_DESCRIPTION;
-    argv[argc++] = (char *)description;
-    
-    procrun_main(argc, argv, _environ, env);
-
-    free_environment(env);
-    g_env = NULL;
-}
-
-/* Update the service.
- * This is a wrapper for //US//
- * 
- */
-
-__declspec(dllexport) void UpdateService(const char *service_name,
-                                         const char *param,
-                                         const char *value)
-{
-    int argc = 0;
-    char *argv[4];
-    char b[MAX_PATH], p[MAX_PATH];
-
-    procrun_t *env = alloc_environment();
-    g_proc_mode = PROCRUN_MODE_WINDLL;
-    g_env = env;
-    
-    argv[argc++] = "PROCRUN.DLL";
-    strcpy(b, PROC_ARG_UPDATE_SERVICE);
-    strcat(b, service_name);
-    strcpy(p, "--");
-    strcat(p, param);
-    argv[argc++] = b;
-    argv[argc++] = p;
-    argv[argc++] = (char *)value;
-    
-    procrun_main(argc, argv, _environ, env);
-
-    free_environment(env);
-    g_env = NULL;
-}
-
-/* Remove the service.
- * This is a wrapper for //DS//
- */
-
-__declspec(dllexport) void RemoveService(const char *service_name)
-{
-    int argc = 0;
-    char *argv[4];
-    char b[MAX_PATH];
-
-    procrun_t *env = alloc_environment();
-    g_proc_mode = PROCRUN_MODE_WINDLL;
-    g_env = env;
-    
-    argv[argc++] = "PROCRUN.DLL";
-    strcpy(b, PROC_ARG_DELETE_SERVICE);
-    strcat(b, service_name);
-    argv[argc++] = b;
-    procrun_main(argc, argv, _environ, env);
-
-    free_environment(env);
-    g_env = NULL;
-}  
-
-#else
-#error Unknown application mode
-#endif
-
diff --git a/src/native/nt/procrun/procrun.dev b/src/native/nt/procrun/procrun.dev
deleted file mode 100644
index 111b011..0000000
--- a/src/native/nt/procrun/procrun.dev
+++ /dev/null
@@ -1,62 +0,0 @@
-[Project]
-FileName=procrun.dev
-Name=procrun
-UnitCount=2
-Type=1
-Ver=1
-ObjFiles=
-Includes=C:\DEVTOOLS\JAVA\141\include;C:\DEVTOOLS\JAVA\141\include\win32
-Libs=
-PrivateResource=procrun_private.rc
-ResourceIncludes=
-MakeIncludes=
-Resources=procrun.rc
-Compiler=-DPROCRUN_CONSOLE -O2
-Linker=-lshlwapi
-IsCpp=0
-Icon=
-ExeOutput=bin
-ObjectOutput=release
-OverrideOutput=0
-OverrideOutputName=procrun.exe
-HostApplication=
-Folders=
-CommandLine=
-IncludeVersionInfo=0
-SupportXPThemes=0
-CompilerSet=0
-CompilerSettings=000000000000000000
-
-[Unit1]
-FileName=procrun.c
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
-[Unit2]
-FileName=procrun.h
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
-[VersionInfo]
-Major=0
-Minor=1
-Release=1
-Build=1
-LanguageID=1033
-CharsetID=1252
-CompanyName=
-FileVersion=
-FileDescription=Developed using the Dev-C++ IDE
-InternalName=
-LegalCopyright=
-LegalTrademarks=
-OriginalFilename=
-ProductName=
-ProductVersion=
-
diff --git a/src/native/nt/procrun/procrun.dsp b/src/native/nt/procrun/procrun.dsp
deleted file mode 100644
index 7f0f120..0000000
--- a/src/native/nt/procrun/procrun.dsp
+++ /dev/null
@@ -1,293 +0,0 @@
-# Microsoft Developer Studio Project File - Name="procrun" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Application" 0x0101
-
-CFG=procrun - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "procrun.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "procrun.mak" CFG="procrun - Win32 Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "procrun - Win32 Debug" (based on "Win32 (x86) Application")
-!MESSAGE "procrun - Win32 Release" (based on "Win32 (x86) Application")
-!MESSAGE "procrun - Win32 Debug CONSOLE" (based on "Win32 (x86) Application")
-!MESSAGE "procrun - Win32 Release CONSOLE" (based on "Win32 (x86) Application")
-!MESSAGE "procrun - Win32 DebugDLL" (based on "Win32 (x86) Application")
-!MESSAGE "procrun - Win32 ReleaseDLL" (based on "Win32 (x86) Application")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "procrun - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "_DEBUG_TRACE" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINAPP" /D "_MBCS" /GZ PRECOMP_VC7_TOBEREMOVED /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "_DEBUG_TRACE" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINAPP" /D "_MBCS" /GZ /c
-# ADD BASE MTL /nologo /win32
-# ADD MTL /nologo /win32
-# ADD BASE RSC /l 0x409 /d "_MSC_VER"
-# ADD RSC /l 0x409 /d "_MSC_VER"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:IX86 /out:"Debug\procrunw.exe" /pdbtype:sept
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:IX86 /out:"bin\procrunwd.exe" /pdbtype:sept
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /Zi /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINAPP" /D "_MBCS" /GF PRECOMP_VC7_TOBEREMOVED /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINAPP" /D "_MBCS" /GF /c
-# ADD BASE MTL /nologo /win32
-# ADD MTL /nologo /win32
-# ADD BASE RSC /l 0x409 /d "_MSC_VER"
-# ADD RSC /l 0x409 /d "_MSC_VER"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:IX86 /out:"bin\procrunw.exe" /pdbtype:sept /opt:ref /opt:icf
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:IX86 /out:"bin\procrunw.exe" /pdbtype:sept /opt:ref /opt:icf
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 Debug CONSOLE"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "DebugCONSOLE"
-# PROP BASE Intermediate_Dir "DebugCONSOLE"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "DebugCONSOLE"
-# PROP Intermediate_Dir "DebugCONSOLE"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "_DEBUG_TRACE" /D "_CONSOLE" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_CONSOLE" /D "_MBCS" /GZ PRECOMP_VC7_TOBEREMOVED /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "_DEBUG_TRACE" /D "_CONSOLE" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_CONSOLE" /D "_MBCS" /GZ /c
-# ADD BASE MTL /nologo /win32
-# ADD MTL /nologo /win32
-# ADD BASE RSC /l 0x409
-# ADD RSC /l 0x409
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:console /debug /machine:IX86 /pdbtype:sept
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:console /debug /machine:IX86 /out:"bin\procrund.exe" /pdbtype:sept
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 Release CONSOLE"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "ReleaseCONSOLE"
-# PROP BASE Intermediate_Dir "ReleaseCONSOLE"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "ReleaseCONSOLE"
-# PROP Intermediate_Dir "ReleaseCONSOLE"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /Zi /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_CONSOLE" /D "_MBCS" /GF PRECOMP_VC7_TOBEREMOVED /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_CONSOLE" /D "_MBCS" /GF /c
-# ADD BASE MTL /nologo /win32
-# ADD MTL /nologo /win32
-# ADD BASE RSC /l 0x409
-# ADD RSC /l 0x409
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:console /debug /machine:IX86 /out:"bin\procrun.exe" /pdbtype:sept /opt:ref /opt:icf
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:console /debug /machine:IX86 /out:"bin\procrun.exe" /pdbtype:sept /opt:ref /opt:icf
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 DebugDLL"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "DebugDLL"
-# PROP BASE Intermediate_Dir "DebugDLL"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "DebugDLL"
-# PROP Intermediate_Dir "DebugDLL"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "_DEBUG_TRACE" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINDLL" /D "_MBCS" /GZ PRECOMP_VC7_TOBEREMOVED /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "_DEBUG_TRACE" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINDLL" /D "_MBCS" /GZ /c
-# ADD BASE MTL /nologo /win32
-# ADD MTL /nologo /win32
-# ADD BASE RSC /l 0x409
-# ADD RSC /l 0x409
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /dll /debug /machine:IX86 /pdbtype:sept
-# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /dll /debug /machine:IX86 /out:"bin\procrund.dll" /pdbtype:sept
-# SUBTRACT LINK32 /pdb:none
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 ReleaseDLL"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "ReleaseDLL"
-# PROP BASE Intermediate_Dir "ReleaseDLL"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "ReleaseDLL"
-# PROP Intermediate_Dir "ReleaseDLL"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /Zi /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINDLL" /D "_MBCS" /GF PRECOMP_VC7_TOBEREMOVED /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "STRICT" /D _WIN32_WINNT=0x0400 /D "PROCRUN_WINDLL" /D "_MBCS" /GF /c
-# ADD BASE MTL /nologo /win32
-# ADD MTL /nologo /win32
-# ADD BASE RSC /l 0x409
-# ADD RSC /l 0x409
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /dll /debug /machine:IX86 /out:"bin\procrun.dll" /pdbtype:sept /opt:ref /opt:icf
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib shlwapi.lib /nologo /subsystem:windows /dll /debug /machine:IX86 /out:"bin\procrun.dll" /pdbtype:sept /opt:ref /opt:icf
-
-!ENDIF 
-
-# Begin Target
-
-# Name "procrun - Win32 Debug"
-# Name "procrun - Win32 Release"
-# Name "procrun - Win32 Debug CONSOLE"
-# Name "procrun - Win32 Release CONSOLE"
-# Name "procrun - Win32 DebugDLL"
-# Name "procrun - Win32 ReleaseDLL"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;def;odl;idl;hpj;bat;asm"
-# Begin Source File
-
-SOURCE=procgui.c
-DEP_CPP_PROCG=\
-	".\procrun.h"\
-	"C:\DEVTOOLS\JAVA\142\include\jni.h"\
-	"C:\DEVTOOLS\JAVA\142\include\win32\jni_md.h"\
-	
-# End Source File
-# Begin Source File
-
-SOURCE=procrun.c
-DEP_CPP_PROCR=\
-	".\procrun.h"\
-	"C:\DEVTOOLS\JAVA\142\include\jni.h"\
-	"C:\DEVTOOLS\JAVA\142\include\win32\jni_md.h"\
-	
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl;inc"
-# Begin Source File
-
-SOURCE=procrun.h
-# End Source File
-# Begin Source File
-
-SOURCE=resource.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# Begin Source File
-
-SOURCE="jakarta-banner.bmp"
-# End Source File
-# Begin Source File
-
-SOURCE=procrun.rc
-
-!IF  "$(CFG)" == "procrun - Win32 Debug"
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 Release"
-
-# ADD BASE RSC /l 0x41a
-# ADD RSC /l 0x41a /d "PROCRUN_WINAPP"
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 Debug CONSOLE"
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 Release CONSOLE"
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 DebugDLL"
-
-!ELSEIF  "$(CFG)" == "procrun - Win32 ReleaseDLL"
-
-!ENDIF 
-
-# End Source File
-# Begin Source File
-
-SOURCE=proctry.ico
-# End Source File
-# Begin Source File
-
-SOURCE=tomcatp.ico
-# End Source File
-# Begin Source File
-
-SOURCE=tomcatr.ico
-# End Source File
-# Begin Source File
-
-SOURCE=.\tomcats.ico
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=License.rtf
-# End Source File
-# End Target
-# End Project
diff --git a/src/native/nt/procrun/procrun.dsw b/src/native/nt/procrun/procrun.dsw
deleted file mode 100644
index ad0ad14..0000000
--- a/src/native/nt/procrun/procrun.dsw
+++ /dev/null
@@ -1,41 +0,0 @@
-Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "procrun"=.\procrun.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "testchild"=.\testchild\testchild.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/src/native/nt/procrun/procrun.h b/src/native/nt/procrun/procrun.h
deleted file mode 100644
index 30394a8..0000000
--- a/src/native/nt/procrun/procrun.h
+++ /dev/null
@@ -1,359 +0,0 @@
-/* ====================================================================
-     Copyright 2002-2004 The Apache Software Foundation.
-   
-     Licensed 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.
-*/
-
-/* ====================================================================
- * procrun
- *
- * Contributed by Mladen Turk <mturk at apache.org>
- *
- * 05 Aug 2002
- * ==================================================================== 
- */
-
-#ifndef PROC_H_INCLUDED
-#define PROC_H_INCLUDED
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(PROCRUN_EXTENDED)
-#include "extend.h"
-#endif
-
-#define IDD_DLGCONSOLE        101
-#define IDS_CONWRAPTITLE      102
-#define IDS_CONWRAPCLASS      103
-#define IDM_CONSOLE           104
-#define IDM_EXIT              105
-#define IDI_ICOCONWRAP        106
-#define IDC_STATBAR           107
-#define IDC_SSTATUS           108
-#define IDB_BMPHEADER         109
-#define IDL_STDOUT            110
-#define IDR_CMENU             111
-#define IDM_MENU_EXIT         112
-#define IDM_MENU_EDIT         113
-#define IDM_MENU_ABOUT        114
-#define IDI_ICOCONTRY         115
-#define IDR_RTFLIC            116
-#define IDB_BMPJAKARTA        117
-#define IDD_ABOUTBOX          118
-#define IDC_RICHEDIT21        119
-#define IDM_ABOUT             120
-#define IDI_ICOCONTRYSTOP     121
-#define IDB_BMPSPLASH         122
-#define IDD_DLGSPLASH         123
-#define IDL_INFO              124
-#define IDI_ICOI              125
-#define IDI_ICOS              126
-#define IDI_ICOW              127
-#define IDM_OPTIONS           128
-#define RC_DLG_SRVOPT         130
-#define RC_LBL_VER            131
-#define RC_LISTVIEW           132
-
-#define RC_TAB_SRVOPT        1000
-#define RC_GRP_MSP           1001
-#define RC_BTN_APPLY         1002
-#define RC_LBL_SN            1003
-#define RC_TXT_SN            1004
-#define RC_LBL_SD            1005
-#define RC_TXT_SD            1006
-#define RC_LBL_IP            1007
-#define RC_TXT_IP            1008
-#define RC_BTN_BIP           1009
-#define RC_LBL_WP            1010
-#define RC_TXT_WP            1011
-#define RC_BTN_BWP           1012
-#define RC_CHK_AUTO          1013
-#define RC_LBL_UN            1014
-#define RC_TXT_UN            1015
-#define RC_LBL_UP            1016
-#define RC_TXT_UP            1017
-#define RC_DLG_JVMOPT        1999
-#define RC_GRP_JVMOPT        2000
-#define RC_LBL_JVM           2001
-#define RC_TXT_JVM           2002
-#define RC_BTN_JVM           2003
-#define RC_CHK_JVM           2004
-#define RC_LBL_JO            2005
-#define RC_TXT_JO            2006
-#define RC_LBL_SC            2007
-#define RC_TXT_SC            2008
-#define RC_LBL_EC            2009
-#define RC_TXT_EC            2010
-#define RC_DLG_STDOPT        2999
-#define RC_GRP_STDOPT        3000
-#define RC_LBL_STDI          3001
-#define RC_TXT_STDI          3002
-#define RC_BTN_STDI          3003
-#define RC_CHK_STDI          3004
-#define RC_LBL_STDO          3005
-#define RC_TXT_STDO          3006
-#define RC_BTN_STDO          3007
-#define RC_LBL_STDE          3008
-#define RC_TXT_STDE          3009
-#define RC_BTN_STDE          3010
-#define RC_ABOUT_TXT         3012
-
-#define IDC_STATIC          -1
-
-#define PROC_ENV_COUNT  32
-#define PROC_ARG_COUNT  128
-#define PROC_BUFSIZE    4096 
-#define PROC_POOL_SIZE  128
-#define PROC_VERSION    "1.1.0\0"
-#define SERVICE_DEPENDENCIES        "Tcpip\0Afd\0\0"
-
-#define PROC_ARG_ENVPREFIX          "//EP//"
-#define PROC_ARG_RUN_JAVA           "//RJ//"
-#define PROC_ARG_INSTALL_SERVICE    "//IS//"
-#define PROC_ARG_RUN_SERVICE        "//RS//"
-#define PROC_ARG_STOP_SERVICE       "//SS//"
-#define PROC_ARG_DELETE_SERVICE     "//DS//"
-#define PROC_ARG_TEST_SERVICE       "//TS//"
-#define PROC_ARG_GUIT_SERVICE       "//GT//"
-#define PROC_ARG_GUID_SERVICE       "//GD//"
-#define PROC_ARG_GUID_PROCESS       "//GP//"
-#define PROC_ARG_UPDATE_SERVICE     "//US//"
-#define PROC_ARG_EDIT_SERVICE       "//ES//"
-
-#define PROCRUN_VERSION_STR         "1.1"
-
-#ifndef PROCRUN_REGKEY_ROOT
-#define PROCRUN_REGKEY_ROOT         "SOFTWARE\\Apache Software Foundation\\Process Runner " PROCRUN_VERSION_STR
-#endif
-
-#ifndef PROCRUN_GUI_DISPLAY
-#define PROCRUN_GUI_DISPLAY         "Apache Process Runner"
-#endif
-
-#define PROCRUN_REGKEY_SERVICES     "System\\CurrentControlSet\\Services\\%s"
-#define PROCRUN_REGKEY_PARAMS       "System\\CurrentControlSet\\Services\\%s\\Parameters"
-#define PROCRUN_REGKEY_RSERVICES    PROCRUN_REGKEY_ROOT "\\%s"
-#define PROCRUN_REGKEY_RPARAMS      PROCRUN_REGKEY_ROOT "\\%s\\Parameters"
-
-#define JAVASOFT_REGKEY             "SOFTWARE\\JavaSoft\\Java Runtime Environment\\"
-#define JAVAHOME_REGKEY             "SOFTWARE\\JavaSoft\\Java Development Kit\\"
- 
-#define PROCRUN_PARAMS_DISPLAY      "DisplayName"
-#define PROCRUN_PARAMS_IMAGE        "ImagePath"
-#define PROCRUN_PARAMS_DESCRIPTION  "Description"
-#define PROCRUN_PARAMS_CMDARGS      "Arguments"
-#define PROCRUN_PARAMS_WORKPATH     "WorkingPath"
-#define PROCRUN_PARAMS_JVM          "Java"
-#define PROCRUN_PARAMS_JVM_OPTS     "JavaOptions"
-#define PROCRUN_PARAMS_STDINFILE    "StdInputFile"
-#define PROCRUN_PARAMS_STDOUTFILE   "StdOutputFile"
-#define PROCRUN_PARAMS_STDERRFILE   "StdErrorFile"
-#define PROCRUN_PARAMS_STARTCLASS   "StartupClass"
-#define PROCRUN_PARAMS_STOPCLASS    "ShutdownClass"
-#define PROCRUN_PARAMS_STARTUP      "Startup"
-#define PROCRUN_PARAMS_ACCOUNT      "User"
-#define PROCRUN_PARAMS_PASSWORD     "Password"
-#define PROCRUN_PARAMS_INSTALL      "Install"
-#define PROCRUN_PARAMS_ENVIRONMENT  "Environment"
-/* Console Window position and color */
-#define PROCRUN_PARAMS_WINPOS       "WindowPosition"
-#define PROCRUN_PARAMS_WINCLR       "WindowColor"
-#define PROCRUN_PARAMS_WINBACK      "WindowBackground"
-#define PROCRUN_PARAMS_USELVIEW     "WindowListView"
-
-
-#define PROCRUN_DEFAULT_CLASS       "Main"
-
-#define PROCRUN_ENV_PPID            "PROCRUN_PPID="
-#define PROCRUN_ENV_STDIN           "PROCRUN_STDIN="
-#define PROCRUN_ENV_STDOUT          "PROCRUN_STDOUT="
-#define PROCRUN_ENV_STDERR          "PROCRUN_STDERR="
-#define PROCRUN_ENV_ERRFILE         "PROCRUN_ERRFILE="
-#define PROCRUN_ENV_SHMNAME         "PROCRUN_SHMNAME="
-
-#define STRN_SIZE(x) (sizeof(x) - 1)
-#define STRN_COMPARE(x, s) (strncmp((x), (s), sizeof((s)) -1) == 0)
-#define STRNI_COMPARE(x, s) (strnicmp((x), (s), sizeof((s)) -1) == 0)
-#define STR_NOT_NULL(s) { if((s) == NULL) (s) = ""; }
-
-    enum { 
-        PROCRUN_MODE_WINAPP = 1,
-        PROCRUN_MODE_GUI,
-        PROCRUN_MODE_CONSOLE,
-        PROCRUN_MODE_WINDLL
-    };
-
-    enum { 
-        PROCRUN_CMD_ENVPREFIX = 1,
-        PROCRUN_CMD_RUN_JAVA,
-        PROCRUN_CMD_INSTALL_SERVICE,
-        PROCRUN_CMD_RUN_SERVICE,
-        PROCRUN_CMD_TEST_SERVICE,
-        PROCRUN_CMD_GUIT_SERVICE,
-        PROCRUN_CMD_GUID_SERVICE,
-        PROCRUN_CMD_STOP_SERVICE,
-        PROCRUN_CMD_DELETE_SERVICE,
-        PROCRUN_CMD_UPDATE_SERVICE,
-        PROCRUN_CMD_EDIT_SERVICE,
-        PROCRUN_CMD_GUID_PROCESS
-    };
-
-    typedef struct mpool_t mpool_t;
-    struct mpool_t {
-        void    *m;
-        HANDLE  h;
-    };
-
-    typedef struct pool_t pool_t;
-    struct pool_t {
-        mpool_t   mp[PROC_POOL_SIZE];
-        CRITICAL_SECTION lock;
-        int       size;
-    };
-
-    typedef struct buffer_t buffer_t;
-    struct buffer_t {
-        char *buf;
-        int  siz;
-        int  len;
-        int  pos;
-    };
-    
-    typedef struct service_t service_t;
-    struct service_t {
-        char                  *name;
-        char                  *description;
-        char                  *display;
-        char                  *path;
-        char                  *image;
-        char                  *account;
-        char                  *password;
-        char                  *environment;
-        HANDLE                infile;
-        HANDLE                outfile;
-        HANDLE                errfile;
-        char                  *inname;
-        char                  *outname;
-        char                  *errname;
-        SERVICE_STATUS        status;
-        SERVICE_STATUS_HANDLE h_status;
-        int                   mode;
-        int                   startup;
-    };
-
-    typedef struct java_t java_t;
-    struct java_t {
-        char         *path;
-        char         *jpath;
-        char         *jbin;
-        char         *start_class;
-        char         *stop_class;
-        HMODULE      dll;
-        JavaVM       *jvm;
-        JNIEnv       *env;
-        jclass       start_bridge;
-        jclass       stop_bridge;
-        jmethodID    start_mid; 
-        jmethodID    stop_mid; 
-        char         *start_method;
-        char         *stop_method;
-        char         *start_param;
-        char         *stop_param;
-        char         *opts;
-        char         *display;
-    };
-
-    typedef struct process_t process_t;
-    struct process_t {
-        HANDLE      events[4];
-        HANDLE      h_stdin[4];
-        HANDLE      h_stdout[4];
-        HANDLE      h_stderr[4];
-        char        *files[3];
-        buffer_t    buff_in;
-        buffer_t    buff_out;
-        buffer_t    buff_err;
-        PROCESS_INFORMATION  pinfo;
-        int         ppid;
-        char        *env[PROC_ENV_COUNT];
-        char        **envp;
-        char        *argw;
-        char        *envw;
-        char        *env_prefix;
-        service_t   service;
-        java_t      java;
-        pool_t      *pool;
-    };
-
-    typedef struct procrun_t procrun_t;
-    struct procrun_t {
-        process_t   *m;
-        process_t   *c;
-    };
-    
-    int procrun_main(int argc, char **argv, char **envp, procrun_t *env);
-    int procrun_update_service(process_t *proc, int argc, char **argv);
-    void save_service_params(process_t *proc, char *java);
-    pool_t *pool_create();
-    int pool_destroy(pool_t *pool);
-    
-    typedef struct prcrun_lview_t {
-        char *  label;
-        DWORD   width;
-    } prcrun_lview_t;
-
-#if !defined(PROCRUN_CONSOLE)
-
-extern DWORD WINAPI gui_thread(LPVOID param);
-
-extern void ac_add_list_string(const char *str, int len, int from);
-extern int  ac_use_try;
-extern int  ac_use_dlg;
-extern int  ac_use_show;
-extern int  ac_use_props;
-extern int  ac_use_lview;
-extern int  ac_lview_current;
-extern int  ac_splash_timeout;
-
-extern  RECT            ac_winpos;
-extern  HINSTANCE       ac_instance;
-extern  HWND            ac_main_hwnd;
-extern  HWND            ac_list_hwnd;
-extern  char            *ac_cmdname;
-extern  char            *ac_splash_msg;
-extern  prcrun_lview_t  *ac_columns;
-
-void    ac_show_try_icon(HWND hwnd, DWORD message, const char *tip, int stop);
-void    ac_center_window(HWND hwnd);
-
-typedef void (*lv_parse_cb_t)(const char *data, int from);
-
-extern lv_parse_cb_t    lv_parser;
-
-#if defined(PROCRUN_EXTENDED)
-
-void acx_init_extended();
-
-
-#endif
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PROC_H_INCLUDED */
-
diff --git a/src/native/nt/procrun/procrun.rc b/src/native/nt/procrun/procrun.rc
deleted file mode 100644
index ccd6bf1..0000000
--- a/src/native/nt/procrun/procrun.rc
+++ /dev/null
@@ -1,232 +0,0 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- *    if any, must include the following acknowledgment:
- *       "This product includes software developed by the
- *        Apache Software Foundation (http://www.apache.org/)."
- *    Alternately, this acknowledgment may appear in the software itself,
- *    if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" must
- *    not be used to endorse or promote products derived from this
- *    software without prior written permission. For written
- *    permission, please contact apache at apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- *    nor may "Apache" appear in their name, without prior written
- *    permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- * Portions of this software are based upon public domain software
- * originally written at the National Center for Supercomputing Applications,
- * University of Illinois, Urbana-Champaign.
- */
- 
-#include "procrun.h"
-#include "windows.h"
-
-#ifndef PROCRUN_CONSOLE
-#if !defined(EXT_ICOCONWRAP)
-IDI_ICOCONWRAP         ICON                    "proctry.ico"
-#endif
-#if !defined(EXT_ICOCONTRY)
-IDI_ICOCONTRY          ICON                    "proctry.ico"
-#endif
-#if !defined(EXT_ICOCONTRY)
-IDI_ICOCONTRYSTOP      ICON                    "proctry.ico"
-#endif
-
-IDR_RTFLIC             RTF                     "License.rtf"
-
-#if !defined(EXT_BMPSPLASH)
-BMPSPLASH              BITMAP                  "splash.bmp"
-#endif
-
-IDI_ICOI               ICON                    "icoi.ico"
-IDI_ICOS               ICON                    "icos.ico"
-IDI_ICOW               ICON                    "icow.ico"
-
-BMPJAKARTA             BITMAP                  "jakarta-banner.bmp"
-IDR_CMENU MENUEX DISCARDABLE 
-BEGIN
-    POPUP "&Process",65535,MFT_STRING,MFS_ENABLED
-    BEGIN
-        MENUITEM "E&xit",                       IDM_MENU_EXIT
-    END
-    POPUP "&Edit",65535,MFT_STRING,MFS_ENABLED
-    BEGIN
-        MENUITEM "&Copy",                       IDM_MENU_EDIT
-    END
-    POPUP "&Help",65535,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
-    BEGIN
-        MENUITEM "&About",                      IDM_MENU_ABOUT
-    END
-END
-
-IDD_DLGCONSOLE DIALOGEX 0, 0, 480, 240
-STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | 
-    WS_SYSMENU | WS_THICKFRAME
-EXSTYLE WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT
-CAPTION "Apache Service Monitor"
-MENU IDR_CMENU
-FONT 10, "Courier New"
-BEGIN
-    LISTBOX         IDL_STDOUT,0,0,200,200,NOT LBS_NOTIFY | LBS_USETABSTOPS | 
-                    LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | NOT WS_BORDER | 
-                    WS_VSCROLL | WS_HSCROLL | WS_TABSTOP,WS_EX_CLIENTEDGE
-END
-
-IDD_ABOUTBOX DIALOGEX 0, 0, 337, 167
-STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
-CAPTION "About Apache Process Runner"
-FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
-BEGIN
-    DEFPUSHBUTTON   "&OK",IDOK,285,150,50,14
-    CONTROL         "",IDC_RICHEDIT21,"RichEdit20A",ES_MULTILINE | 
-                    ES_READONLY | WS_BORDER | WS_VSCROLL,0,31,335,115
-    CONTROL         "BMPJAKARTA",IDC_STATIC,"Static",SS_BITMAP,0,0,337,30
-    LTEXT           "Apache Process Runner ver. 1.1.0",IDC_STATIC,2,150,270,12
-END
-
-RC_DLG_SRVOPT DIALOGEX 0, 0, 337, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE | WS_BORDER
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
-    GROUPBOX        " Main Service Parameters ",RC_GRP_MSP,4,16,324,158
-    CONTROL         "Auto Start",RC_CHK_AUTO,"Button",BS_AUTOCHECKBOX | 
-                    BS_LEFTTEXT | WS_TABSTOP,20,153,62,12
-    LTEXT           "Name :",RC_LBL_SN,22,48,50,12
-    EDITTEXT        RC_TXT_SN,76,48,179,12,ES_AUTOHSCROLL | ES_READONLY | 
-                    NOT WS_TABSTOP
-    LTEXT           "Description :",RC_LBL_SD,22,66,50,12
-    EDITTEXT        RC_TXT_SD,76,66,219,12,ES_AUTOHSCROLL
-    LTEXT           "Image path :",RC_LBL_IP,21,79,50,12
-    EDITTEXT        RC_TXT_IP,75,79,219,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",RC_BTN_BIP,297,79,18,12
-    LTEXT           "Work path :",RC_LBL_WP,21,94,50,12
-    EDITTEXT        RC_TXT_WP,75,92,219,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",RC_BTN_BWP,297,92,18,12
-    LTEXT           "Username :",RC_LBL_UN,21,105,50,12
-    EDITTEXT        RC_TXT_UN,75,105,108,12,ES_AUTOHSCROLL
-    LTEXT           "Password :",RC_LBL_UP,21,118,50,12
-    EDITTEXT        RC_TXT_UP,75,118,108,12,ES_PASSWORD | ES_AUTOHSCROLL
-END
-
-RC_DLG_JVMOPT DIALOGEX 0, 0, 337, 186
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE | WS_BORDER
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
-    GROUPBOX        " Java Virtual Machine ",RC_GRP_JVMOPT,4,16,324,158
-    CONTROL         "Auto",RC_CHK_JVM,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | 
-                    WS_TABSTOP,22,48,62,12
-    LTEXT           "Java VM :",RC_LBL_JVM,22,66,50,12
-    EDITTEXT        RC_TXT_JVM,76,66,219,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",RC_BTN_JVM,298,66,18,12
-    LTEXT           "Java Options :",RC_LBL_JO,22,82,50,12
-    EDITTEXT        RC_TXT_JO,76,82,219,30,ES_MULTILINE | ES_AUTOHSCROLL | 
-                    ES_WANTRETURN | WS_VSCROLL
-    LTEXT           "Start class :",RC_LBL_SC,22,120,50,12
-    EDITTEXT        RC_TXT_SC,76,120,219,12,ES_AUTOHSCROLL
-    LTEXT           "Stop class :",RC_LBL_EC,22,138,50,12
-    EDITTEXT        RC_TXT_EC,76,138,219,12,ES_AUTOHSCROLL
-END
-
-RC_DLG_STDOPT DIALOGEX 0, 0, 337, 186
-STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE | WS_BORDER
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
-BEGIN
-    GROUPBOX        " Standard I/O Streams ",RC_GRP_STDOPT,4,16,324,158
-    CONTROL         "Read on startup",RC_CHK_STDI,"Button",BS_AUTOCHECKBOX | 
-                    WS_TABSTOP,76,66,55,12
-    LTEXT           "Input :",RC_LBL_STDI,22,48,50,12
-    EDITTEXT        RC_TXT_STDI,76,48,219,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",RC_BTN_STDI,298,48,18,12
-    LTEXT           "Output :",RC_LBL_STDO,22,84,50,12
-    EDITTEXT        RC_TXT_STDO,76,84,219,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",RC_BTN_STDO,298,84,18,12
-    LTEXT           "Error :",RC_LBL_STDE,22,102,50,12
-    EDITTEXT        RC_TXT_STDE,76,102,219,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",RC_BTN_STDE,298,102,18,12
-END
-
-IDD_DLGSPLASH DIALOGEX 0, 0, 322, 151
-STYLE DS_SYSMODAL | DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | 
-    WS_BORDER
-EXSTYLE WS_EX_TOPMOST
-FONT 8, "Microsoft Sans Serif", 400, 0, 0x0
-BEGIN
-    LISTBOX         IDL_INFO,7,126,217,9, LBS_NOINTEGRALHEIGHT | 
-                    LBS_NOSEL | NOT WS_BORDER | NOT LBS_USETABSTOPS
-    CONTROL         "BMPSPLASH",IDC_STATIC,"Static",SS_BITMAP |
-                    SS_CENTERIMAGE,0,0,322,151
-END 
-
-#endif
-
-1 VERSIONINFO
- FILEVERSION 2,1,1,0
- PRODUCTVERSION 2,1,1,0
- FILEFLAGSMASK 0x3fL
-#if defined(_DEBUG)
- FILEFLAGS 0x03L
-#else
- FILEFLAGS 0x02L
-#endif
- FILEOS 0x40004L
- FILETYPE 0x1L
- FILESUBTYPE 0x0L
-BEGIN
-  BLOCK "StringFileInfo"
-  BEGIN
-    BLOCK "040904b0"
-    BEGIN
-      VALUE "Comments", "All rights reserved.  The license is available at <http://www.apache.org/LICENSE.txt>.  The Apache HTTP Server project pages are at <http://httpd.apache.org/>.\0"
-      VALUE "CompanyName", "Apache Software Foundation\0"
-      VALUE "FileDescription", "Apache Process Runner\0"
-      VALUE "FileVersion", PROC_VERSION
-      VALUE "InternalName", "procrunw.exe\0"
-      VALUE "LegalCopyright", "Copyright � 2000-2003 The Apache Software Foundation.\0"
-      VALUE "OriginalFilename", "procrunw.exe\0"
-      VALUE "ProductName", "Apache Process Runner\0"
-      VALUE "ProductVersion", PROC_VERSION
-    END
-  END
-  BLOCK "VarFileInfo"
-  BEGIN
-    VALUE "Translation", 0x409, 1200
-  END
-END
diff --git a/src/native/nt/procrun/procrun.sln b/src/native/nt/procrun/procrun.sln
index 482830d..ec54d89 100644
--- a/src/native/nt/procrun/procrun.sln
+++ b/src/native/nt/procrun/procrun.sln
@@ -1,36 +1,88 @@
 Microsoft Visual Studio Solution File, Format Version 8.00
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "procrun", "procrun.vcproj", "{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libprocrun", "libprocrun.vcproj", "{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}"
 	ProjectSection(ProjectDependencies) = postProject
 	EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testchild", "testchild\testchild.vcproj", "{C815B005-1292-47F7-9052-F46676CE2879}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "apsvcmgr", "apps\apsvcmgr\apsvcmgr.vcproj", "{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}"
 	ProjectSection(ProjectDependencies) = postProject
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6} = {A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cchild", "samples\cchild.vcproj", "{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}"
+	ProjectSection(ProjectDependencies) = postProject
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jar2exe", "apps\jar2exe\jar2exe.vcproj", "{DA9F3DDA-F85A-492A-B914-6A361429FC41}"
+	ProjectSection(ProjectDependencies) = postProject
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6} = {A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prunsrv", "apps\prunsrv\prunsrv.vcproj", "{DC1701B5-D480-461A-A16F-67E383AF376D}"
+	ProjectSection(ProjectDependencies) = postProject
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6} = {A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "prunmgr", "apps\prunmgr\prunmgr.vcproj", "{98E56B10-BB3E-404A-A587-0FE95CFFB77B}"
+	ProjectSection(ProjectDependencies) = postProject
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6} = {A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}
 	EndProjectSection
 EndProject
 Global
 	GlobalSection(SolutionConfiguration) = preSolution
 		Debug = Debug
-		Debug CONSOLE = Debug CONSOLE
+		Debug Unicode = Debug Unicode
 		Release = Release
-		Release CONSOLE = Release CONSOLE
+		Release Unicode = Release Unicode
 	EndGlobalSection
 	GlobalSection(ProjectConfiguration) = postSolution
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Debug.ActiveCfg = Debug|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Debug.Build.0 = Debug|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Debug CONSOLE.ActiveCfg = Debug CONSOLE|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Debug CONSOLE.Build.0 = Debug CONSOLE|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Release.ActiveCfg = Release|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Release.Build.0 = Release|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Release CONSOLE.ActiveCfg = ReleaseDLL|Win32
-		{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}.Release CONSOLE.Build.0 = ReleaseDLL|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Debug.ActiveCfg = Debug|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Debug.Build.0 = Debug|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Debug CONSOLE.ActiveCfg = Debug|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Debug CONSOLE.Build.0 = Debug|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Release.ActiveCfg = Release|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Release.Build.0 = Release|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Release CONSOLE.ActiveCfg = Release|Win32
-		{C815B005-1292-47F7-9052-F46676CE2879}.Release CONSOLE.Build.0 = Release|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Debug.ActiveCfg = Debug|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Debug.Build.0 = Debug|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Debug Unicode.ActiveCfg = Debug Unicode|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Debug Unicode.Build.0 = Debug Unicode|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Release.ActiveCfg = Release|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Release.Build.0 = Release|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Release Unicode.ActiveCfg = Release Unicode|Win32
+		{A4CE30CB-D4D3-4C03-83ED-565BFE4640D6}.Release Unicode.Build.0 = Release Unicode|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Debug.ActiveCfg = Debug|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Debug.Build.0 = Debug|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Debug Unicode.ActiveCfg = Debug Unicode|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Debug Unicode.Build.0 = Debug Unicode|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Release.ActiveCfg = Release|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Release.Build.0 = Release|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Release Unicode.ActiveCfg = Release Unicode|Win32
+		{3D8C70CD-F3D4-4191-89FD-7BFE2A3EDDE4}.Release Unicode.Build.0 = Release Unicode|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Debug.ActiveCfg = Debug|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Debug.Build.0 = Debug|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Debug Unicode.ActiveCfg = Debug Unicode|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Debug Unicode.Build.0 = Debug Unicode|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Release.ActiveCfg = Release|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Release.Build.0 = Release|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Release Unicode.ActiveCfg = Release Unicode|Win32
+		{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}.Release Unicode.Build.0 = Release Unicode|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Debug.ActiveCfg = Debug|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Debug.Build.0 = Debug|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Debug Unicode.ActiveCfg = Debug|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Debug Unicode.Build.0 = Debug|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Release.ActiveCfg = Release|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Release.Build.0 = Release|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Release Unicode.ActiveCfg = Release|Win32
+		{DA9F3DDA-F85A-492A-B914-6A361429FC41}.Release Unicode.Build.0 = Release|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Debug.ActiveCfg = Debug|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Debug.Build.0 = Debug|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Debug Unicode.ActiveCfg = Debug|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Debug Unicode.Build.0 = Debug|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Release.ActiveCfg = Release|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Release.Build.0 = Release|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Release Unicode.ActiveCfg = Release|Win32
+		{DC1701B5-D480-461A-A16F-67E383AF376D}.Release Unicode.Build.0 = Release|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Debug.ActiveCfg = Debug|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Debug.Build.0 = Debug|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Debug Unicode.ActiveCfg = Debug Unicode|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Debug Unicode.Build.0 = Debug Unicode|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Release.ActiveCfg = Release|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Release.Build.0 = Release|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Release Unicode.ActiveCfg = Release|Win32
+		{98E56B10-BB3E-404A-A587-0FE95CFFB77B}.Release Unicode.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 	EndGlobalSection
diff --git a/src/native/nt/procrun/procrun.vcproj b/src/native/nt/procrun/procrun.vcproj
deleted file mode 100644
index 02b3676..0000000
--- a/src/native/nt/procrun/procrun.vcproj
+++ /dev/null
@@ -1,374 +0,0 @@
-<?xml version="1.0" encoding="windows-1250"?>
-<VisualStudioProject
-	ProjectType="Visual C++"
-	Version="7.10"
-	Name="procrun"
-	ProjectGUID="{A90DF83B-1E82-4610-AFA2-3AC7010BF5D9}"
-	Keyword="Win32Proj">
-	<Platforms>
-		<Platform
-			Name="Win32"/>
-	</Platforms>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory="Debug"
-			IntermediateDirectory="Debug"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				OptimizeForProcessor="0"
-				AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
-				PreprocessorDefinitions="_WIN32,WIN32,_DEBUG,_DEBUG_TRACE,_WINDOWS,STRICT,_WIN32_WINNT=0x0400,PROCRUN_WINAPP"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="FALSE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="comctl32.lib shlwapi.lib"
-				OutputFile="Debug/tomcatw.exe"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/procrun.pdb"
-				SubSystem="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"
-				PreprocessorDefinitions="_MSC_VER"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			OutputDirectory="Release"
-			IntermediateDirectory="Release"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
-				PreprocessorDefinitions="_WIN32,WIN32,NDEBUG,_WINDOWS,STRICT,_WIN32_WINNT=0x0400,PROCRUN_WINAPP"
-				StringPooling="TRUE"
-				RuntimeLibrary="0"
-				EnableFunctionLevelLinking="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="FALSE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="comctl32.lib shlwapi.lib"
-				OutputFile="bin/tomcatw.exe"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="2"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"
-				PreprocessorDefinitions="_MSC_VER"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="Debug CONSOLE|Win32"
-			OutputDirectory="DebugCONSOLE"
-			IntermediateDirectory="DebugCONSOLE"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
-				PreprocessorDefinitions="_WIN32,WIN32,_DEBUG,_DEBUG_TRACE,_CONSOLE,STRICT,_WIN32_WINNT=0x0400,PROCRUN_CONSOLE"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="FALSE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="comctl32.lib shlwapi.lib"
-				OutputFile="Debug/tomcat.exe"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/procrun.pdb"
-				SubSystem="1"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release CONSOLE|Win32"
-			OutputDirectory="ReleaseCONSOLE"
-			IntermediateDirectory="ReleaseCONSOLE"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
-				PreprocessorDefinitions="_WIN32,WIN32,NDEBUG,_CONSOLE,STRICT,_WIN32_WINNT=0x0400,PROCRUN_CONSOLE"
-				StringPooling="TRUE"
-				RuntimeLibrary="0"
-				EnableFunctionLevelLinking="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="FALSE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="comctl32.lib shlwapi.lib"
-				OutputFile="bin/tomcat.exe"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="1"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="DebugDLL|Win32"
-			OutputDirectory="DebugDLL"
-			IntermediateDirectory="DebugDLL"
-			ConfigurationType="2"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
-				PreprocessorDefinitions="_WIN32,WIN32,_DEBUG,_DEBUG_TRACE,_WINDOWS,STRICT,_WIN32_WINNT=0x0400,PROCRUN_WINDLL"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="FALSE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="comctl32.lib shlwapi.lib"
-				OutputFile="Debug/tomcat.cpl"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/procrun.pdb"
-				SubSystem="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="ReleaseDLL|Win32"
-			OutputDirectory="ReleaseDLL"
-			IntermediateDirectory="ReleaseDLL"
-			ConfigurationType="2"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				AdditionalIncludeDirectories="$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
-				PreprocessorDefinitions="_WIN32,WIN32,NDEBUG,_WINDOWS,STRICT,_WIN32_WINNT=0x0400,PROCRUN_WINDLL"
-				StringPooling="TRUE"
-				RuntimeLibrary="0"
-				EnableFunctionLevelLinking="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="FALSE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="comctl32.lib shlwapi.lib"
-				OutputFile="bin/tomcat.cpl"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="2"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-	</Configurations>
-	<References>
-	</References>
-	<Files>
-		<Filter
-			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
-			<File
-				RelativePath="procgui.c">
-			</File>
-			<File
-				RelativePath="procrun.c">
-			</File>
-		</Filter>
-		<Filter
-			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc">
-			<File
-				RelativePath="procrun.h">
-			</File>
-			<File
-				RelativePath="resource.h">
-			</File>
-		</Filter>
-		<Filter
-			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
-			<File
-				RelativePath="jakarta-banner.bmp">
-			</File>
-			<File
-				RelativePath="procrun.rc">
-			</File>
-			<File
-				RelativePath="proctry.ico">
-			</File>
-			<File
-				RelativePath="tomcatp.ico">
-			</File>
-			<File
-				RelativePath="tomcatr.ico">
-			</File>
-		</Filter>
-		<File
-			RelativePath="License.rtf">
-		</File>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
diff --git a/src/native/nt/procrun/procrund.dev b/src/native/nt/procrun/procrund.dev
deleted file mode 100644
index a0792ca..0000000
--- a/src/native/nt/procrun/procrund.dev
+++ /dev/null
@@ -1,62 +0,0 @@
-[Project]
-FileName=procrund.dev
-Name=procrun
-UnitCount=2
-Type=3
-Ver=1
-ObjFiles=
-Includes=C:\DEVTOOLS\JAVA\141\include;C:\DEVTOOLS\JAVA\141\include\win32
-Libs=
-PrivateResource=procrun_private.rc
-ResourceIncludes=
-MakeIncludes=
-Resources=procrun.rc
-Compiler=-DPROCRUN_WINDLL -O2
-Linker=-lshlwapi
-IsCpp=0
-Icon=
-ExeOutput=bin
-ObjectOutput=ReleaseDLL
-OverrideOutput=1
-OverrideOutputName=procrun.dll
-HostApplication=
-Folders=
-CommandLine=
-IncludeVersionInfo=0
-SupportXPThemes=0
-CompilerSet=0
-CompilerSettings=000000000000000000
-
-[Unit1]
-FileName=procrun.c
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
-[Unit2]
-FileName=procrun.h
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
-[VersionInfo]
-Major=0
-Minor=1
-Release=1
-Build=1
-LanguageID=1033
-CharsetID=1252
-CompanyName=
-FileVersion=
-FileDescription=Developed using the Dev-C++ IDE
-InternalName=
-LegalCopyright=
-LegalTrademarks=
-OriginalFilename=
-ProductName=
-ProductVersion=
-
diff --git a/src/native/nt/procrun/procrunw.dev b/src/native/nt/procrun/procrunw.dev
deleted file mode 100644
index 82f3243..0000000
--- a/src/native/nt/procrun/procrunw.dev
+++ /dev/null
@@ -1,70 +0,0 @@
-[Project]
-FileName=procrunw.dev
-Name=procrun
-UnitCount=3
-Type=0
-Ver=1
-ObjFiles=
-Includes=C:\DEVTOOLS\JAVA\141\include;C:\DEVTOOLS\JAVA\141\include\win32
-Libs=
-PrivateResource=procrun_private.rc
-ResourceIncludes=
-MakeIncludes=
-Resources=procrun.rc
-Compiler=-DPROCRUN_WINAPP -O2
-Linker=-lshlwapi -lcomctl32
-IsCpp=0
-Icon=
-ExeOutput=bin
-ObjectOutput=release
-OverrideOutput=0
-OverrideOutputName=procrunw.exe
-HostApplication=
-Folders=
-CommandLine=
-IncludeVersionInfo=0
-SupportXPThemes=0
-CompilerSet=0
-CompilerSettings=000000000000000000
-
-[Unit1]
-FileName=procrun.c
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
-[Unit2]
-FileName=procrun.h
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
-[VersionInfo]
-Major=0
-Minor=1
-Release=1
-Build=1
-LanguageID=1033
-CharsetID=1252
-CompanyName=
-FileVersion=
-FileDescription=Developed using the Dev-C++ IDE
-InternalName=
-LegalCopyright=
-LegalTrademarks=
-OriginalFilename=
-ProductName=
-ProductVersion=
-
-[Unit3]
-FileName=procgui.c
-Folder=procrun
-Compile=1
-CompileCpp=0
-OverrideBuildCmd=0
-BuildCmd=
-
diff --git a/src/native/nt/procrun/proctry.ico b/src/native/nt/procrun/proctry.ico
deleted file mode 100644
index ab60f9e..0000000
Binary files a/src/native/nt/procrun/proctry.ico and /dev/null differ
diff --git a/src/native/nt/procrun/readme.txt b/src/native/nt/procrun/readme.txt
deleted file mode 100644
index 3565d72..0000000
--- a/src/native/nt/procrun/readme.txt
+++ /dev/null
@@ -1,149 +0,0 @@
-Procrun
-
-Features:
-
-1. Redirect console applications
-2. Running redirected applications as services
-3. Console or Windows GUI application mode to avoid any
-   temporarily flashing console windows in case the procrun
-   is invoked by a GUI program.
-4. Running Java applications using default or specified JVM
-5. Service management Install/Start/Stop/Delete/Update
-
-
-Invocation:
-
-procrun [action] [options] [parameters]
-
-Actions:
-Actions are two letter codes encapsulated inside double slashes followed
-by service name. The service name has to be without spaces.
-
-//IS//<serviceName> Install the service 
-//RS//<serviceName> Run service
-                    called only when running as service. Do not call that
-                    directly.
-//DS//<serviceName> Delete the service
-//TS//<serviceName> Test the service
-                    Run service as ordinary console application.
-//US//<serviceName> Update service
-                    Change services startup parameters
-//GT//<serviceName> Test (Run) the service using windows try
-                    The service will run and put the icon in the
-                    system try.
-//GD//<serviceName> Test (Run) the service using windows try
-                    The service will run and and show console window.
-
-
-Options:
-Options are used for install and update actions and are written to the
-serviceName registry parameters.
-Options are followed with option parameter. If the option parameter
-needs spaces it has to be quoted.
-
---DisplayName   <service display name>
-                This is the name shown in the Windows Services
-                manager.
---Description   <service description>
-                This is the service description shown in the windows
-                Services manager.
-
---ImagePath     <full path to process executable>
-                Full path to the executable to be run as service,
-                or name of the Java Class Path. In cases when the
-                service runs JVM or Java binary this is the
-                parameter passed to -Djava.class.path option.
-
---Arguments     <arguments passed to the service>
-                Arguments are enclosed inside double quotation
-                marks and passed to the service image
-
---WorkingPath   <services working path>
-                Sets the working path to the desired value.
-
---Java          [auto|java|path to the jvm.dll]
-                auto:
-                    Auto will cause to load the default JVM read
-                    read from registry.
-                java[w]:
-                    The default java.exe or javaw.exe will be
-                    located and executed with
-                    -Djava.class.path=ImagePath
-                If neither java or auto are specified then this
-                parameter is treated as full path to the jvm.dll
-
---JavaOptions   <list of java options>
-                This is the list of options to be passed to the JVM
-                The options are separated using hash (#) simbol.
-                For Example:
-                -Xmx=100M#-Djava.compiler=NONE
-                                
---StartupClass  <class name>
-                Class name that will be called if started from JVM
-                when the applications starts.
-                The method name is separated by semicolon after the
-                class name.
-                The parameters passed to the class method are semicolon
-                separated values after the method name.
-                For example:
-                org/apache/jk/apr/TomcatStarter;Main;start
-                
---ShutdownClass <class name>
-                Class name that will be called if started from JVM
-                when the applications stops. The class has to have
-                the method Main.
-                The method name is separated by semicolon after the
-                class name.
-                The parameters passed to the class method are semicolon
-                separated values after the method name.
-                For example:
-                org/apache/jk/apr/TomcatStarter;Main;stop;some;dummy;params
-                
---StdInputFile  <path to the file>
-                The file that will be read an passed as standard
-                input stream to the redirected application
---StdOutputFile <path to the file>
-                Path to the redirected stdout.
---StdErrorFile  <path to the file>
-                Path to the redirected stderr.
-
---Startup       <auto|manual>
-                The services startup mode Automatic or Manual.
-                Default value is auto.
-
---User          <username>
-                The User account used for launching redirected process.
-
---Password      <password>
-                The password of User account used for launching
-                redirected process.
-
---Install       <procrun.exe>
-                Used as Service manager ImagePath when installing
-                service from installation program using procrunw.
-                                
-Examples:
-
-Installing Tomcat as service:
-    procrun //IS//Tomcat4 --DisplayName "Tomcat 4.1.19" \
-            --Description "Tomcat 4.1.19 LE JDK 1.4 http://jakarta.apache.org" \
-            --ImagePath "c:\devtools\tomcat\41\bin\bootstrap.jar" \
-            --StartupClass org.apache.catalina.startup.Bootstrap;main;start \
-            --ShutdownClass org.apache.catalina.startup.Bootstrap;main;stop \
-            --Java auto
-
-Installing Tomcat as service without popup console window:
-    procrunw //IS//Tomcat4 --DisplayName "Tomcat 4.1.19" \
-            --Description "Tomcat 4.1.19 LE JDK 1.4 http://jakarta.apache.org" \
-            --Install "c:\devtools\tomcat\41\bin\procrun.exe"
-
-After installing you may call update service to add or change service
-parameters:    
-    procrunw //US//Tomcat4 \
-            --ImagePath "c:\devtools\tomcat\41\bin\bootstrap.jar" \            
-            --StartupClass org.apache.catalina.startup.Bootstrap;main;start \
-            --ShutdownClass org.apache.catalina.startup.Bootstrap;main;stop \
-            --Java auto
-
-Notice:
-    You may change all parameters except service name and Install image.
diff --git a/src/native/nt/procrun/resources/apsvcmgr.ico b/src/native/nt/procrun/resources/apsvcmgr.ico
new file mode 100644
index 0000000..ecc896b
Binary files /dev/null and b/src/native/nt/procrun/resources/apsvcmgr.ico differ
diff --git a/src/native/nt/procrun/jakarta-banner.bmp b/src/native/nt/procrun/resources/jakarta.bmp
similarity index 100%
rename from src/native/nt/procrun/jakarta-banner.bmp
rename to src/native/nt/procrun/resources/jakarta.bmp
diff --git a/src/native/nt/procrun/resources/license.rtf b/src/native/nt/procrun/resources/license.rtf
new file mode 100644
index 0000000..622e284
--- /dev/null
+++ b/src/native/nt/procrun/resources/license.rtf
@@ -0,0 +1,33 @@
+{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}
+{\f1\fswiss\fcharset238\fprq2{\*\panose 020b0604020202020204}Arial;}{\f39\froman\fcharset0\fprq2 Times New Roman;}{\f38\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f40\froman\fcharset161\fprq2 Times New Roman Greek;}
+{\f41\froman\fcharset162\fprq2 Times New Roman Tur;}{\f42\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f43\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f44\froman\fcharset186\fprq2 Times New Roman Baltic;}
+{\f45\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f49\fswiss\fcharset0\fprq2 Arial;}{\f48\fswiss\fcharset204\fprq2 Arial Cyr;}{\f50\fswiss\fcharset161\fprq2 Arial Greek;}{\f51\fswiss\fcharset162\fprq2 Arial Tur;}
+{\f52\fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f53\fswiss\fcharset178\fprq2 Arial (Arabic);}{\f54\fswiss\fcharset186\fprq2 Arial Baltic;}{\f55\fswiss\fcharset163\fprq2 Arial (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;
+\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;
+\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive 
+\ssemihidden Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv 
+\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}{\*\cs15 \additive \ul\cf2 \sbasedon10 Hyperlink;}}
+{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\rsidtbl \rsid1379267\rsid3345586\rsid5638524\rsid6496053\rsid6510316\rsid6697379\rsid7028353\rsid9000330\rsid9454304\rsid10124145\rsid10819759\rsid12321742\rsid12593955\rsid14358633\rsid15670059\rsid16132583
+}{\*\generator Microsoft Word 11.0.5604;}{\info{\author Mladen Turk}{\operator Mladen Turk}{\creatim\yr2003\mo4\dy9\hr14\min37}{\revtim\yr2004\mo4\dy7\hr8\min42}{\version14}{\edmins11}{\nofpages1}{\nofwords96}{\nofchars549}
+{\*\company Apache Software Foundation}{\nofcharsws644}{\vern24689}}\margl1417\margr1417\margt1417\margb1417 \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701
+\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind4\viewscale100\nolnhtadjtbl\rsidroot9000330 \fet0\sectd \linex0\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang 
+{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang 
+{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain 
+\qc \li0\ri0\nowidctlpar\faauto\rin0\lin0\itap0\pararsid14358633 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\f1\insrsid16132583\charrsid12321742 The Apache Software License, Version 2.0
+\par }\pard \ql \li0\ri0\nowidctlpar\faauto\rin0\lin0\itap0 {\f1\fs18\insrsid16132583\charrsid16132583 
+\par }\pard \ql \li0\ri0\nowidctlpar\faauto\rin0\lin0\itap0\pararsid9454304 {\f1\fs18\insrsid9454304   }{\f1\fs18\insrsid16132583\charrsid16132583 Copyright 2002-2004 The Apache Software Foundation.
+\par }\pard \ql \li0\ri0\nowidctlpar\faauto\rin0\lin0\itap0\pararsid1379267 {\f1\fs18\insrsid16132583\charrsid16132583    
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 Licensed under the Apache License, Version 2.0 (the "License");
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 you may not use this file except in compliance with the License.
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 You may obtain a copy of the License at
+\par }{\f1\fs18\insrsid12593955 
+\par }{\f1\fs18\insrsid16132583\charrsid16132583    
+\par }{\cf2\insrsid6510316   }{\ul\cf2\insrsid16132583\charrsid6510316 http://www.apache.org/licenses/LICENSE-2.0
+\par }{\f1\fs18\insrsid12593955 
+\par 
+\par }{\f1\fs18\insrsid12321742 \line }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 Unless required by applicable law or agreed to in writing, software
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 distributed under the License is distributed on an "AS IS" BASIS,}{\f1\fs18\insrsid14358633  }{\f1\fs18\insrsid16132583\charrsid16132583 
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid16132583\charrsid16132583 See the License for the specific language governing permissions and
+\par }{\f1\fs18\insrsid14358633   }{\f1\fs18\insrsid14358633\charrsid16132583 L}{\f1\fs18\insrsid16132583\charrsid16132583 imitations under the License.
+\par }}
\ No newline at end of file
diff --git a/src/native/nt/procrun/resources/procrunr.ico b/src/native/nt/procrun/resources/procrunr.ico
new file mode 100644
index 0000000..390aa6d
Binary files /dev/null and b/src/native/nt/procrun/resources/procrunr.ico differ
diff --git a/src/native/nt/procrun/resources/procruns.ico b/src/native/nt/procrun/resources/procruns.ico
new file mode 100644
index 0000000..5d99878
Binary files /dev/null and b/src/native/nt/procrun/resources/procruns.ico differ
diff --git a/src/native/nt/procrun/resources/procrunw.ico b/src/native/nt/procrun/resources/procrunw.ico
new file mode 100644
index 0000000..79f3038
Binary files /dev/null and b/src/native/nt/procrun/resources/procrunw.ico differ
diff --git a/src/native/nt/procrun/resources/sorterd.bmp b/src/native/nt/procrun/resources/sorterd.bmp
new file mode 100644
index 0000000..0dd6ccd
Binary files /dev/null and b/src/native/nt/procrun/resources/sorterd.bmp differ
diff --git a/src/native/nt/procrun/resources/sorteru.bmp b/src/native/nt/procrun/resources/sorteru.bmp
new file mode 100644
index 0000000..1f6723b
Binary files /dev/null and b/src/native/nt/procrun/resources/sorteru.bmp differ
diff --git a/src/native/nt/procrun/resources/sstatus.bmp b/src/native/nt/procrun/resources/sstatus.bmp
new file mode 100644
index 0000000..870c143
Binary files /dev/null and b/src/native/nt/procrun/resources/sstatus.bmp differ
diff --git a/src/native/nt/procrun/resources/susers.bmp b/src/native/nt/procrun/resources/susers.bmp
new file mode 100644
index 0000000..d7bac45
Binary files /dev/null and b/src/native/nt/procrun/resources/susers.bmp differ
diff --git a/src/native/nt/procrun/resources/toolbar.bmp b/src/native/nt/procrun/resources/toolbar.bmp
new file mode 100644
index 0000000..41dcf40
Binary files /dev/null and b/src/native/nt/procrun/resources/toolbar.bmp differ
diff --git a/src/native/nt/procrun/samples/cchild.c b/src/native/nt/procrun/samples/cchild.c
new file mode 100644
index 0000000..6a610ed
--- /dev/null
+++ b/src/native/nt/procrun/samples/cchild.c
@@ -0,0 +1,133 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/* Simple console child */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <conio.h>
+#include <time.h>
+#include <process.h>    /* _beginthread, _endthread */
+#include <fcntl.h>
+#include <io.h>
+
+#define STDIN_FILENO  0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+#define STDO_MESSAGE "Simple STDOUT_FILENO message\n"
+#define STDE_MESSAGE "Simple STDERR_FILENO message\n"
+
+#define NLOOPS          5
+#define NTHREADS       10
+
+static int do_echo = 0;
+BOOL WINAPI ControlHandler ( DWORD dwCtrlType )
+{
+   printf("\nCTRL Event %d ", dwCtrlType);
+   switch (dwCtrlType) {
+   case CTRL_BREAK_EVENT:
+      printf("CTRL+BREAK\n");
+      exit(1);
+      return TRUE;
+   case CTRL_C_EVENT:
+      printf("CTRL+C");
+      return TRUE;
+      break;
+
+   }
+   putch('\n');
+   return FALSE;
+}
+
+unsigned __stdcall threadfunc(void *args)
+{
+    int i, p , r;
+    p = (int)(size_t)args;
+    printf("Created thread %d %04x\n", p, GetCurrentThreadId());
+    srand((unsigned)time(NULL) + p);
+    for (i = 0; i < NLOOPS; i++) {
+        r = rand() % 1000;
+        Sleep(r);
+        printf("Thread %d message %d\n", p, i);
+    }
+    printf("Quiting thread %d %04x\n", p, GetCurrentThreadId());
+    _endthreadex(0);
+    return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+    int i, conio = 0, threads = 0;
+    char buf[256];
+    HANDLE htrd[NTHREADS];
+
+    OutputDebugString("cchild starting");
+    fprintf(stdout, "cchild starting %s\n", argv[0]);
+    fflush(stdout);
+    SetConsoleCtrlHandler(ControlHandler, TRUE);
+    Sleep(1000);
+    
+    for (i = 0; i < __argc; i++) {
+        fprintf(stdout, "argv[%d] %s\n", i, __argv[i]);
+        fflush(stdout);
+        if (strcmp(__argv[i], "--") == 0)
+            do_echo = 1;
+        else if (strcmp(__argv[i], "-c") == 0)
+            conio = 1;
+        else if (strcmp(__argv[i], "-t") == 0)
+            threads = 1;
+    }
+    fflush(stdout);
+    fprintf(stderr, "Simple stderr message\n");
+    fflush(stderr);
+    write(STDOUT_FILENO, STDO_MESSAGE, sizeof(STDO_MESSAGE) - 1);
+    write(STDERR_FILENO, STDE_MESSAGE, sizeof(STDE_MESSAGE) - 1);
+    
+    if (conio) {
+        cputs("Type 'Y' when finished typing keys...");
+        do {
+            i = getch();
+            i = toupper(i);
+        } while (i != 'Y');
+        putch('\n');
+    }
+    if (do_echo) {
+        cputs("Going to echo loop...\n");
+        while ((i = read(STDIN_FILENO, buf, 256)) > 0) {
+            buf[i] = '\0';
+            fputs(buf, stdout);
+            if (strcmp(buf, "quit\n") == 0)
+                break;
+        }
+    }
+    if (threads) {
+        for (i = 0; i < NTHREADS; i++) {
+            unsigned id;
+            htrd[i] = (HANDLE)_beginthreadex(NULL, 0, threadfunc, (void *)(size_t)i, 0, &id);
+        }
+        WaitForMultipleObjects(10, htrd, TRUE, INFINITE);
+    }
+
+    fprintf(stdout, "cchild finishing\n");
+    fprintf(stdout, "cchild finished\n");
+    Sleep(1000);
+    OutputDebugString("cchild Ended");
+    return 0;
+}
+
diff --git a/src/native/nt/procrun/samples/cchild.vcproj b/src/native/nt/procrun/samples/cchild.vcproj
new file mode 100644
index 0000000..c3c4666
--- /dev/null
+++ b/src/native/nt/procrun/samples/cchild.vcproj
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="cchild"
+	ProjectGUID="{E9ABF9C5-CCF7-4372-B42A-07584D2441D8}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="..\obj\Release"
+			IntermediateDirectory="..\obj\Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="../bin/cchild.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				EntryPointSymbol=""
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="..\obj\Debug"
+			IntermediateDirectory="..\obj\Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="../bin/cchildd.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/cchild.pdb"
+				SubSystem="1"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug Unicode|Win32"
+			OutputDirectory="..\obj\$(ConfigurationName)"
+			IntermediateDirectory="..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_UNICODE"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="../bin/cchildud.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/cchild.pdb"
+				SubSystem="1"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release Unicode|Win32"
+			OutputDirectory="..\obj\$(ConfigurationName)"
+			IntermediateDirectory="..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="../bin/cchildu.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\cchild.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/splash.bmp b/src/native/nt/procrun/splash.bmp
deleted file mode 100644
index ff67143..0000000
Binary files a/src/native/nt/procrun/splash.bmp and /dev/null differ
diff --git a/src/native/nt/procrun/src/cmdline.c b/src/native/nt/procrun/src/cmdline.c
new file mode 100644
index 0000000..62e70d6
--- /dev/null
+++ b/src/native/nt/procrun/src/cmdline.c
@@ -0,0 +1,276 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+#define EXE_SUFFIX      L".EXE"
+#define EXE_SUFFIXLEN   (sizeof(EXE_SUFFIX) / sizeof(WCHAR) - 1)
+
+/* Those two are declared in handles.c */
+extern LPWSTR   *_st_sys_argvw;
+extern int      _st_sys_argc;
+
+static WCHAR    _st_sys_appexe[MAX_PATH];
+/*
+ * argv parsing.
+ * Parse the argv[0] and split to ExePath and
+ * Executable name. Strip the extension ('.exe').
+ * Check for command in argv[1] //CMD//Application
+ * Parse the options --option value or --option==value
+ * break on first argument that doesn't start with '--'
+ */
+LPAPXCMDLINE apxCmdlineParse(
+    APXHANDLE hPool,
+    APXCMDLINEOPT   *lpOptions,
+    LPCWSTR         *lpszCommands)
+{
+
+    LPAPXCMDLINE lpCmdline = NULL;
+    DWORD l, i = 0, s = 1;
+    LPWSTR p;
+    WCHAR  cmd[4];
+    DWORD  match;
+    BOOL   add;
+    if (_st_sys_argc < 1)
+        return NULL;
+
+    l = lstrlenW(_st_sys_argvw[0]);
+    if (l < EXE_SUFFIXLEN)
+        return NULL;
+    if (!(lpCmdline = (LPAPXCMDLINE)apxPoolCalloc(hPool, sizeof(APXCMDLINE))))
+        return NULL;
+    lpCmdline->hPool       = hPool;
+    lpCmdline->lpOptions   = lpOptions;
+    lpCmdline->szExePath   = _st_sys_argvw[0];
+    p = lpCmdline->szExePath + l;
+
+    while (p > lpCmdline->szExePath) {
+        if (*p == L'\\') {
+            *p++ = L'\0';
+            break;
+        }
+        p--;
+    }
+    /* Find the path if it wasn't specified in the argv[0] */
+    if (p == lpCmdline->szExePath) {
+        WCHAR  mh[4096];
+        LPWSTR m;
+        if (GetModuleFileNameW(GetModuleHandle(NULL), mh, 4096)) {
+            lpCmdline->szExePath = apxPoolStrdupW(hPool, mh);
+            m = lpCmdline->szExePath + lstrlenW(lpCmdline->szExePath);
+            while (m > lpCmdline->szExePath) {
+                if (*(m--) == L'\\') {
+                    *(++m) = L'\0';
+                    break;
+                }
+            }
+        }
+    }
+    lpCmdline->szExecutable = p;
+    p = _st_sys_argvw[0] + l - EXE_SUFFIXLEN;
+    if (lstrcmpiW(p, EXE_SUFFIX) == 0)
+        *p = L'\0';
+    if (lpszCommands && _st_sys_argc > 1 && lstrlenW(_st_sys_argvw[1]) > 5) {
+        if (_st_sys_argvw[1][0] == L'/' &&
+            _st_sys_argvw[1][1] == L'/' &&
+            _st_sys_argvw[1][5] == L'/') { /* allow max tree char command */
+            l = 2;
+            while (_st_sys_argvw[1][l] != L'/') {
+                cmd[l - 2] = _st_sys_argvw[1][l];
+                if (l++ > 3)
+                    break;
+            }
+            cmd[l - 2] = L'\0';
+            while (lpszCommands[i]) {
+                if (lstrcmpW(lpszCommands[i++], cmd) == 0) {
+                    lpCmdline->dwCmdIndex = i;
+                    s = 2;
+                    break;
+                }
+            }
+            if (lpCmdline->dwCmdIndex) {
+                _st_sys_argvw[1][l+1] = L'\0';
+                lpCmdline->szApplication = &(_st_sys_argvw[1][l+2]);
+                if (!lstrlenW(lpCmdline->szApplication))
+                    lpCmdline->szApplication = _st_sys_argvw[0];
+            }
+            else {
+                apxLogWrite(APXLOG_MARK_ERROR "Unrecognized cmd option %s", cmd);
+                s = 2;
+            }
+        }
+    }
+    else {
+        lpCmdline->szApplication = lpCmdline->szExecutable;
+        lpCmdline->dwCmdIndex = 1;
+        return lpCmdline;
+    }
+    for (i = s; i < (DWORD)_st_sys_argc; i++) {
+        LPWSTR e = NULL;
+        if (_st_sys_argvw[i][0] != L'-' ||
+            _st_sys_argvw[i][1] != L'-') {
+            if (_st_sys_argvw[i][0] != L'+' ||
+                _st_sys_argvw[i][1] != L'+')
+                break;
+            else
+                add = TRUE;
+        }
+        else
+            add = FALSE;
+        p = &(_st_sys_argvw[i][2]);
+        /* Find if the option has '=' char
+         * for --option==value or --option value cases.
+         */
+        while (*p) {
+            if (*p == L'=') {
+                *p = L'\0';
+                e = p + 1;
+                break;
+            }
+            else
+                p++;
+        }
+        match = 0;
+        for (l = 0; lpOptions[l].szName; l++) {
+            if (lstrcmpW(lpOptions[l].szName, &(_st_sys_argvw[i][2])) == 0) {
+                LPWSTR val;
+                /* check if arg is needed */
+                if (e)
+                    val = e;
+                else if ((i + 1) < (DWORD)_st_sys_argc)
+                    val = _st_sys_argvw[++i];
+                else {
+                    lpOptions[l].dwValue = 0;
+                    lpOptions[l].szValue = NULL;
+                    lpOptions[l].dwType |= APXCMDOPT_FOUND;
+                    break;
+                }
+                if (lpOptions[l].dwType & APXCMDOPT_STR)
+                    lpOptions[l].szValue = val;
+                else if (lpOptions[l].dwType & APXCMDOPT_INT)
+                    lpOptions[l].dwValue = (DWORD)apxAtoulW(val);
+                else if (lpOptions[l].dwType & APXCMDOPT_MSZ) {
+                    LPWSTR pp;
+                    BOOL insquote = FALSE, indquote=FALSE;
+                    DWORD sp = 0;
+                    LPWSTR ov = lpOptions[l].szValue;
+                    if (lpOptions[l].dwValue > 2) {
+                        sp = (lpOptions[l].dwValue - sizeof(WCHAR)) / sizeof(WCHAR);
+                    }
+                    lpOptions[l].dwValue = (sp + lstrlenW(val) + 2) * sizeof(WCHAR);
+                    lpOptions[l].szValue = (LPWSTR)apxPoolCalloc(hPool,
+                                                lpOptions[l].dwValue);
+                    if (sp) {
+                        AplMoveMemory(lpOptions[l].szValue, ov, sp * sizeof(WCHAR));
+                        apxFree(ov);
+                    }
+                    pp = val;
+                    while(*pp) {
+                        if (*pp == L'\'')
+                            insquote = !insquote;
+                        else if (*pp == L'"') {
+                            indquote = !indquote;
+                            lpOptions[l].szValue[sp++] = L'"';
+                        }
+                        else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
+                            lpOptions[l].szValue[sp++] = L'\0';
+                        else
+                            lpOptions[l].szValue[sp++] = *pp;
+                        pp++;
+                    }
+                }
+                lpOptions[l].dwType |= APXCMDOPT_FOUND;
+                if (add)
+                    lpOptions[l].dwType |= APXCMDOPT_ADD;
+                match = l + 1;
+                break;
+            }
+        }
+    }
+    if (i < (DWORD)_st_sys_argc) {
+        lpCmdline->dwArgc = _st_sys_argc - i;
+        lpCmdline->lpArgvw = &_st_sys_argvw[i];
+    }
+    return lpCmdline;
+}
+
+/* Used for future expansion */
+void apxCmdlineFree(
+    LPAPXCMDLINE lpCmdline)
+{
+
+    apxFree(lpCmdline);
+}
+
+/*
+ * Environment variables parsing
+ * Each variable is prfixed with PR_
+ * for example 'set PR_JVM=auto' has a same meaning as providing '--Jvm auto'
+ * on the command line.
+ * Multistring varisables are added to the present conf.
+ */
+void apxCmdlineLoadEnvVars(
+    LPAPXCMDLINE lpCmdline)
+{
+    WCHAR szEnv[64];
+    int i = 0;
+    if (!lpCmdline || !lpCmdline->lpOptions)
+        return;
+
+    while (lpCmdline->lpOptions[i].szName) {
+        DWORD l;
+        WCHAR szVar[SIZ_HUGLEN];
+        lstrcpyW(szEnv, L"PR_");
+        lstrcatW(szEnv, lpCmdline->lpOptions[i].szName);
+        l = GetEnvironmentVariableW(szEnv, szVar, SIZ_HUGMAX);
+        if (l == 0 && GetLastError() !=  ERROR_ENVVAR_NOT_FOUND) {
+            apxLogWrite(APXLOG_MARK_ERROR "Error geting environment variable %S",
+                        szEnv);
+            ++i;
+            continue;
+        }
+        if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_STR)) {
+            lpCmdline->lpOptions[i].szValue = apxPoolStrdupW(lpCmdline->hPool, szVar);
+            lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND;
+        }
+        else if (l && (lpCmdline->lpOptions[i].dwType & APXCMDOPT_MSZ)) {
+            LPWSTR pp;
+            BOOL insquote = FALSE, indquote = FALSE;
+            DWORD sp = 0;
+            lpCmdline->lpOptions[i].szValue = apxPoolCalloc(lpCmdline->hPool,
+                                                            (lstrlenW(szVar) + 2) *
+                                                            sizeof(WCHAR));
+            lstrcpyW(lpCmdline->lpOptions[i].szValue, szVar);
+            pp = szVar;
+            while(*pp) {
+                if (*pp == L'\'')
+                    insquote = !insquote;
+                else if (*pp == L'"') {
+                    indquote = !indquote;
+                    lpCmdline->lpOptions[i].szValue[sp++] = L'"';
+                }
+                else if ((*pp == L'#' || *pp == L';') && !insquote && !indquote)
+                    lpCmdline->lpOptions[i].szValue[sp++] = L'\0';
+                else
+                    lpCmdline->lpOptions[i].szValue[sp++] = *pp;
+                pp++;
+            }
+            lpCmdline->lpOptions[i].dwType |= APXCMDOPT_FOUND | APXCMDOPT_ADD;
+        }
+        ++i;
+    }
+
+}
\ No newline at end of file
diff --git a/src/native/nt/procrun/src/console.c b/src/native/nt/procrun/src/console.c
new file mode 100644
index 0000000..9ce8bee
--- /dev/null
+++ b/src/native/nt/procrun/src/console.c
@@ -0,0 +1,149 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+/** Console layout saved in the registry as binary */
+typedef struct stAPXCONSOLE_LAYOUT {
+    /** Main window size */
+    POINT   ptSize;
+    /** Main window size and position */
+    RECT    rcPos;
+    /** Client window size */
+    POINT   ptClientSize;
+    /** Client size and position */
+    RECT    rcClientPos;
+    /** Scroll position */
+    POINT   ptScrollPos;
+    /** Maximum Scroll position */
+    POINT   ptScrollMax;
+    /** Caret position */
+    POINT   ptCaretPos;
+    /** Background color */
+    COLORREF clrBackground;
+    /** Text color */
+    COLORREF clrText;
+    /** Selected text background color */
+    COLORREF clrSelectBackground;
+    /** Selected rext color */
+    COLORREF clrSelectText;
+    /** Character size */
+    POINT    ptCharSize;
+    /** Current Screen size */
+    POINT    ptScreenSize;    
+    /** Font size */
+    INT      nFontSize;
+    /** Caret size */
+    POINT    ptCaretSize;
+    /** Caret Bilnk time in ms */
+    UINT     nCaretBlinkTime;
+    /** Typeface name of the font (32 char max including the null terminator) */
+    TCHAR   szFontName[32];
+    
+} stAPXCONSOLE_LAYOUT, *APXCONSOLE_LAYOUT;
+
+typedef struct stAPXCONSOLE {
+    /** Application instance handle */
+    HINSTANCE   hInstance;
+    /** Console Screen Buffer */
+    TCHAR       lpScreenBuffer;   
+    /** The size of the Console Screen Buffer */
+    DWORD       dwScreenBufferSize;
+    /** Main window Handle */
+    HWND        hWnd;
+    /** Console window Handle */
+    HWND        hConsole;
+    /** Console Window Layout */
+    stAPXCONSOLE_LAYOUT stLayout;
+    /** Console Keyboard Buffer */
+    TCHAR       lpKeyboardBuffer;
+    /** The size of the Keyboard Buffer */
+    DWORD       dwKeyboardBufferSize;
+    /** Console Handler routine */
+    PHANDLER_ROUTINE fnHandlerRoutine;
+    /** Console Reference Count */
+    DWORD       dwReferenceCount;
+} stAPXCONSOLE, *APXCONSOLE;
+
+APXHANDLE  __st_sys_console = NULL;
+
+static BOOL __apxConsoleCallback(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam)
+{
+    APXCONSOLE lpConsole = APXHANDLE_DATA(hObject);
+
+    if (hObject->dwType != APXHANDLE_TYPE_CONSOLE)
+        return FALSE;
+    switch (uMsg) {
+        case WM_CLOSE:
+            
+        break;
+        default:
+        break;
+    }
+    return TRUE;
+}
+
+APXHANDLE
+apxAllocConsoleHandle(APXHANDLE hPool)
+{
+    APXHANDLE hConsole;
+
+    hConsole = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT |
+                               APXHANDLE_OWNS_LOCK, NULL,
+                               sizeof(stAPXCONSOLE),
+                               __apxConsoleCallback);
+
+    return hConsole;
+}
+
+BOOL
+apxFreeConsoleHandle(APXHANDLE hConsole)
+{
+    APXCONSOLE lpConsole = APXHANDLE_DATA(hConsole);
+    if (hConsole->dwType != APXHANDLE_TYPE_CONSOLE)
+        return FALSE;
+        
+    return apxCloseHandle(hConsole);
+}
+
+
+
+
+
+/** Standard Console Functions */
+BOOL
+apxAllocConsole()
+{
+
+    if (!__st_sys_console) {
+        __st_sys_console = apxAllocConsoleHandle(NULL);
+        return TRUE;
+    }
+    else
+        return FALSE;
+}
+
+BOOL
+apxFreeConsole()
+{
+    if (apxFreeConsoleHandle(__st_sys_console)) {
+        __st_sys_console = NULL;
+        return TRUE;
+    }
+    else
+        return FALSE;
+}
diff --git a/src/native/nt/procrun/src/gui.c b/src/native/nt/procrun/src/gui.c
new file mode 100644
index 0000000..b057b23
--- /dev/null
+++ b/src/native/nt/procrun/src/gui.c
@@ -0,0 +1,1024 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+#define BALLON_TIMEOUT  1000
+/* Offset for listview dots */
+#define DOTOFFSET       0
+
+static HMODULE      _st_sys_riched;
+static APXGUISTORE  _st_sys_gui;
+static HIMAGELIST   _st_sel_users_il = NULL;
+static WNDPROC      _st_sel_users_lvm;
+
+typedef struct PROGRESS_DLGPARAM {
+    LPCTSTR szHead;
+    LPCWSTR szText;
+    LPVOID  cbData;
+    LPAPXFNCALLBACK fnCb;
+    HANDLE  hThread;
+    HWND    hDialog;
+} PROGRESS_DLGPARAM, *LPPROGRESS_DLGPARAM;
+
+APXLVITEM lvUsers[] = {
+    { 0, FALSE, 180, 180, LVCFMT_LEFT, TEXT("User") },
+    { 0, TRUE,  180, 180, LVCFMT_LEFT, TEXT("Full Name") },
+    { 0, TRUE,  235, 235, LVCFMT_LEFT, TEXT("Comment") }
+};
+
+
+#define NUMLVUSERS    (sizeof(lvUsers) / sizeof(lvUsers[0]))
+
+static UINT __getWhellScrollLines()
+{
+    HWND hdlMsWheel;
+    UINT ucNumLines = 3;  /* 3 is the default */
+    UINT uiMsh_MsgScrollLines;
+   
+    APX_OSLEVEL os = apxGetOsLevel();
+    /* In Windows 9x & Windows NT 3.51, query MSWheel for the
+     * number of scroll lines. In Windows NT 4.0 and later,
+     * use SystemParametersInfo.
+     */
+    if (os < APX_WINVER_NT_4) {
+        hdlMsWheel = FindWindow(MSH_WHEELMODULE_CLASS, 
+                                MSH_WHEELMODULE_TITLE);
+        if (hdlMsWheel) {
+            uiMsh_MsgScrollLines = RegisterWindowMessage(MSH_SCROLL_LINES);
+            if (uiMsh_MsgScrollLines)
+                ucNumLines = (int)SendMessage(hdlMsWheel,
+                                              uiMsh_MsgScrollLines, 
+                                              0, 0);
+        }
+    }
+    else {
+        SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
+                             &ucNumLines, 0);
+    }
+    return ucNumLines;
+}
+
+/* Initialize the Gui
+ */
+LPAPXGUISTORE apxGuiInitialize(WNDPROC lpfnWndProc, LPCTSTR szAppName)
+{
+    INITCOMMONCONTROLSEX stCmn;
+    WNDCLASSEX wcex;
+
+    _st_sys_gui.hInstance = GetModuleHandleA(NULL);
+    GetStartupInfo(&_st_sys_gui.stStartupInfo);
+
+    lstrcpy(_st_sys_gui.szWndClass, szAppName);
+    lstrcat(_st_sys_gui.szWndClass, TEXT("_CLASS"));
+
+    /* Single instance or general application mutex */
+    lstrcpy(_st_sys_gui.szWndMutex, szAppName);
+    lstrcat(_st_sys_gui.szWndMutex, TEXT("_MUTEX"));
+
+
+    stCmn.dwSize = sizeof(INITCOMMONCONTROLSEX);
+    stCmn.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES | ICC_COOL_CLASSES |
+                  ICC_INTERNET_CLASSES | ICC_PAGESCROLLER_CLASS | ICC_BAR_CLASSES;
+                  
+    InitCommonControlsEx(&stCmn);
+
+    _st_sys_riched      = LoadLibraryA("RICHED32.DLL"); 
+    _st_sys_gui.hIconSm = LoadImage(_st_sys_gui.hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+                                     IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); 
+    _st_sys_gui.hIcon   = LoadImage(_st_sys_gui.hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+                                     IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR); 
+    _st_sys_gui.hIconHg = LoadImage(_st_sys_gui.hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+                                     IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR); 
+    _st_sys_gui.hAccel  = LoadAccelerators(_st_sys_gui.hInstance,
+                                            MAKEINTRESOURCE(IDC_APPLICATION));
+    _st_sys_gui.stState.rcPosition.left   = CW_USEDEFAULT;
+    _st_sys_gui.stState.rcPosition.top    = CW_USEDEFAULT;
+    _st_sys_gui.stState.rcPosition.right  = CW_USEDEFAULT;
+    _st_sys_gui.stState.rcPosition.bottom = CW_USEDEFAULT;
+
+    _st_sys_gui.nWhellScroll = __getWhellScrollLines();
+
+    wcex.cbSize = sizeof(WNDCLASSEX); 
+
+    wcex.style          = 0;
+    wcex.lpfnWndProc    = lpfnWndProc;
+    wcex.cbClsExtra     = 0;
+    wcex.cbWndExtra     = 0;
+    wcex.hInstance      = _st_sys_gui.hInstance;
+    wcex.hIcon          = _st_sys_gui.hIcon;
+    wcex.hIconSm        = _st_sys_gui.hIconSm;
+    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
+    wcex.hbrBackground  = (HBRUSH)(COLOR_INACTIVEBORDER+1);
+    wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_APPLICATION);
+    wcex.lpszClassName  = _st_sys_gui.szWndClass;
+
+    if (RegisterClassEx(&wcex)) {
+        return &_st_sys_gui;
+    }
+    else
+        return NULL;
+}
+
+
+BOOL apxCenterWindow(HWND hwndChild, HWND hwndParent)
+{
+    RECT    rChild, rParent, rWorkArea;
+    int     wChild, hChild, wParent, hParent;
+    int     xNew, yNew;
+    BOOL    bResult;
+
+    /* Get the Height and Width of the child window */
+    GetWindowRect(hwndChild, &rChild);
+    wChild = rChild.right - rChild.left;
+    hChild = rChild.bottom - rChild.top;
+
+    /* Get the Height and Width of the parent window */
+    GetWindowRect(hwndParent, &rParent);
+    wParent = rParent.right - rParent.left;
+    hParent = rParent.bottom - rParent.top;
+
+    if (wParent < wChild && hParent < hChild) {
+        GetWindowRect(GetDesktopWindow(), &rParent);
+        wParent = rParent.right - rParent.left;
+        hParent = rParent.bottom - rParent.top;
+    }
+    /* Get the limits of the 'workarea' */
+    bResult = SystemParametersInfo(SPI_GETWORKAREA, sizeof(RECT),
+        &rWorkArea, 0);
+    if (!bResult) {
+        rWorkArea.left = rWorkArea.top = 0;
+        rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
+        rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
+    }
+
+    /* Calculate new X position, then adjust for workarea */
+    xNew = rParent.left + ((wParent - wChild) /2);
+    if (xNew < rWorkArea.left)
+        xNew = rWorkArea.left;
+    else if ((xNew+wChild) > rWorkArea.right)
+        xNew = rWorkArea.right - wChild;
+
+    /* Calculate new Y position, then adjust for workarea */
+    yNew = rParent.top  + ((hParent - hChild) /2);
+    if (yNew < rWorkArea.top)
+        yNew = rWorkArea.top;
+    else if ((yNew+hChild) > rWorkArea.bottom)
+        yNew = rWorkArea.bottom - hChild;
+
+    /* Set it, and return */
+    return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
+}
+
+/***************************************************************************
+ * Function: LoadRcString
+ *
+ * Purpose: Loads a resource string from string table and returns a pointer
+ *          to the string.
+ *
+ * Parameters: wID - resource string id
+ *
+ */
+
+/** Load the resource string with the ID given, and return a
+ * pointer to it.  Notice that the buffer is common memory so
+ * the string must be used before this call is made a second time.
+ */
+
+LPSTR apxLoadResourceA(UINT wID, UINT nBuf)
+
+{
+    static CHAR szBuf[4][SIZ_BUFLEN];
+    if (nBuf > 4)
+        return "";
+    if (LoadStringA(_st_sys_gui.hInstance,wID ,szBuf[nBuf], SIZ_BUFMAX) > 0)
+        return szBuf[nBuf];
+    else
+        return "";
+}
+
+LPWSTR apxLoadResourceW(UINT wID, UINT nBuf)
+
+{
+    static WCHAR szBuf[4][SIZ_BUFLEN];
+    if (nBuf > 4)
+        return L"";
+    if (LoadStringW(_st_sys_gui.hInstance,wID ,szBuf[nBuf], SIZ_BUFMAX) > 0)
+        return szBuf[nBuf];
+    else
+        return L"";
+}
+
+/* Add the item to the Try popup menu
+ */
+void apxAppendMenuItem(HMENU hMenu, UINT idMenu, LPCTSTR szName,
+                       BOOL bDefault, BOOL bEnabled)
+{
+    MENUITEMINFO miI;
+    
+    AplZeroMemory(&miI, sizeof(MENUITEMINFO));
+    miI.cbSize = sizeof(MENUITEMINFO);
+    miI.fMask  = MIIM_TYPE | MIIM_STATE;
+    if (szName && lstrlen(szName)) {
+        miI.fMask |= MIIM_ID;
+        miI.fType = MFT_STRING;
+        miI.wID   = idMenu;
+        if (bDefault)
+            miI.fState = MFS_DEFAULT;
+        if (!bEnabled)
+            miI.fState |= MFS_DISABLED;
+        miI.dwTypeData = (LPTSTR)szName;
+    }
+    else {
+        miI.fType = MFT_SEPARATOR;
+    }
+    InsertMenuItem(hMenu, idMenu, FALSE, &miI);
+}
+
+/* Add the item to the Try popup menu
+ */
+void apxAppendMenuItemBmp(HMENU hMenu, UINT idMenu, LPCTSTR szName)
+{
+    MENUITEMINFO miI;
+    HBITMAP hBmp;
+
+    hBmp = LoadImage(_st_sys_gui.hInstance, szName,
+                     IMAGE_BITMAP, 0, 0,
+                     LR_CREATEDIBSECTION | LR_SHARED);
+
+    AplZeroMemory(&miI, sizeof(MENUITEMINFO));
+    miI.cbSize = sizeof(MENUITEMINFO);
+    miI.fMask  = MIIM_BITMAP | MFT_MENUBARBREAK;
+
+    miI.hbmpItem = hBmp;
+    InsertMenuItem(hMenu, idMenu, FALSE, &miI);
+}
+
+/* Try icon helper
+ * Add/Change/Delete icon from the windows try.
+ */
+void apxManageTryIconA(HWND hWnd, DWORD dwMessage, LPCSTR szInfoTitle,
+                       LPCSTR szInfo, HICON hIcon)
+{
+    static BOOL inTry = FALSE;
+    NOTIFYICONDATAA nId;
+    AplZeroMemory(&nId, sizeof(NOTIFYICONDATAA));
+
+    nId.cbSize = sizeof(NOTIFYICONDATAA);
+    nId.hWnd = hWnd;
+    nId.uID = 0xFF;
+    nId.uCallbackMessage = WM_TRAYMESSAGE;
+    nId.uFlags =  NIF_MESSAGE;
+    
+    if (dwMessage == NIM_ADD && inTry)
+        return;
+    if (dwMessage != NIM_DELETE) {
+        nId.uFlags |= NIF_ICON;
+        if (! szInfoTitle) {
+            nId.uFlags |= NIF_TIP;
+            lstrcpynA(nId.szTip, szInfo, 63);
+        }
+        else if (szInfo) {
+            nId.uFlags |= NIF_INFO;
+            lstrcpynA(nId.szInfo, szInfo, 255);
+            lstrcpynA(nId.szInfoTitle, szInfoTitle, 63);
+            nId.dwInfoFlags = NIIF_INFO;
+            nId.uTimeout    = BALLON_TIMEOUT;
+        }
+
+        nId.hIcon = hIcon ? hIcon : _st_sys_gui.hIconSm;
+        inTry = TRUE;
+    }
+    else
+        inTry = FALSE;
+
+    Shell_NotifyIconA(dwMessage, &nId);
+} 
+
+void apxManageTryIconW(HWND hWnd, DWORD dwMessage, LPCWSTR szInfoTitle,
+                       LPCWSTR szInfo, HICON hIcon)
+{
+    
+    NOTIFYICONDATAW nId;
+    AplZeroMemory(&nId, sizeof(NOTIFYICONDATAW));
+
+    nId.cbSize = sizeof(NOTIFYICONDATAW);
+    nId.hWnd = hWnd;
+    nId.uID = 0xFF;
+    nId.uCallbackMessage = WM_TRAYMESSAGE;
+    nId.uFlags =  NIF_MESSAGE;
+
+    if (dwMessage != NIM_DELETE) {
+        nId.uFlags |= NIF_ICON;
+        if (! szInfoTitle) {
+            nId.uFlags |= NIF_TIP;
+            lstrcpynW(nId.szTip, szInfo, 63);
+        }
+        else if (szInfo) {
+            nId.uFlags |= NIF_INFO;
+            lstrcpynW(nId.szInfo, szInfo, 255);
+            lstrcpynW(nId.szInfoTitle, szInfoTitle, 63);
+            nId.dwInfoFlags = NIIF_INFO;
+            nId.uTimeout    = BALLON_TIMEOUT;
+        }
+        nId.hIcon = hIcon ? hIcon : _st_sys_gui.hIconSm;
+    }
+
+    Shell_NotifyIconW(dwMessage, &nId);
+} 
+
+static void __apxShellAbout(HWND hWnd)
+{
+    TCHAR szApplication[512];
+
+    wsprintf(szApplication , TEXT("About - %s#Windows"), 
+             apxLoadResource(IDS_APPLICATION, 0));
+
+    ShellAbout(hWnd, szApplication,
+               apxLoadResource(IDS_APPDESCRIPTION, 1),
+               _st_sys_gui.hIconHg);
+}
+
+
+static LRESULT CALLBACK __apxAboutDlgProc(HWND hDlg, UINT uMsg,
+                                          WPARAM wParam, LPARAM lParam)
+{
+    static  HWND  hRich = NULL;
+    static  POINT ptScroll;
+    HRSRC   hRsrc;
+    HGLOBAL hGlob;
+    LPSTR   szTxt;
+
+    switch (uMsg) {
+        case WM_INITDIALOG:
+            apxCenterWindow(hDlg, _st_sys_gui.hMainWnd);
+            hRich = GetDlgItem(hDlg, IDC_LICENSE);
+            hRsrc = FindResource(GetModuleHandleA(NULL), MAKEINTRESOURCE(IDR_LICENSE),
+                                 TEXT("RTF"));
+            hGlob = LoadResource(GetModuleHandleA(NULL), hRsrc);
+            szTxt = (LPSTR)LockResource(hGlob);
+            
+            SendMessageA(hRich, WM_SETTEXT, 0, (LPARAM)szTxt);
+            SetDlgItemText(hDlg, IDC_ABOUTAPP, apxLoadResource(IDS_APPFULLNAME, 0));
+            ptScroll.x = 0;
+            ptScroll.y = 0;
+            return TRUE;
+        break;
+        case WM_COMMAND:
+            if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
+                EndDialog(hDlg, LOWORD(wParam));
+                return TRUE;
+            }
+            else if (LOWORD(wParam) == IAB_SYSINF)
+                __apxShellAbout(hDlg);
+        break;
+        case WM_MOUSEWHEEL:
+            {
+                int nScroll, nLines;
+                if ((SHORT)HIWORD(wParam) < 0)
+                    nScroll = _st_sys_gui.nWhellScroll;
+                else
+                    nScroll = _st_sys_gui.nWhellScroll * (-1);
+                ptScroll.y += (nScroll * 11);
+                if (ptScroll.y < 0)
+                    ptScroll.y = 0;
+                nLines = (int)SendMessage(hRich, EM_GETLINECOUNT, 0, 0) + 1;
+                if (ptScroll.y / 11 > nLines)
+                    ptScroll.y = nLines * 11;
+                SendMessage(hRich, EM_SETSCROLLPOS, 0, (LPARAM)&ptScroll);
+            }
+        break;
+
+    }
+    return FALSE;
+} 
+
+void apxAboutBox(HWND hWnd)
+{
+    DialogBox(_st_sys_gui.hInstance,
+              MAKEINTRESOURCE(IDD_ABOUTBOX),
+              hWnd,
+              (DLGPROC)__apxAboutDlgProc);
+}
+
+static DWORD WINAPI __apxProgressWorkerThread(LPVOID lpParameter)
+{
+    LPPROGRESS_DLGPARAM lpDlgParam = (LPPROGRESS_DLGPARAM)lpParameter;
+
+    (*lpDlgParam->fnCb)(NULL, WM_USER+1, 0, (LPARAM)lpDlgParam->hDialog); 
+    CloseHandle(lpDlgParam->hThread);
+    ExitThread(0);
+    return 0;
+}
+
+static LRESULT CALLBACK __apxProgressDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    LPPROGRESS_DLGPARAM lpDlgParam;
+    DWORD dwId;
+    switch (uMsg) {
+        case WM_INITDIALOG:
+            lpDlgParam = (LPPROGRESS_DLGPARAM)lParam;
+            apxCenterWindow(hDlg, _st_sys_gui.hMainWnd);
+            if (lpDlgParam && lpDlgParam->szHead && lpDlgParam->szText) {
+                SetDlgItemText(hDlg, IDDP_HEAD, lpDlgParam->szHead);
+                SetDlgItemTextW(hDlg, IDDP_TEXT, lpDlgParam->szText);
+            }
+            lpDlgParam->hDialog = hDlg;
+            lpDlgParam->hThread = CreateThread(NULL, 0, __apxProgressWorkerThread,
+                                               lpDlgParam, 0, &dwId); 
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDOK:
+                    EndDialog(hDlg, LOWORD(wParam));
+                    return TRUE;
+                break;
+            }
+        break;
+        case WM_USER+1:
+            SendMessage(GetDlgItem(hDlg, IDDP_PROGRESS), PBM_STEPIT, 0, 0);
+        break;
+    }
+    return FALSE;
+} 
+
+int apxProgressBox(HWND hWnd, LPCTSTR szHeader,
+                   LPCWSTR szText,
+                   LPAPXFNCALLBACK fnProgressCallback,
+                   LPVOID cbData)
+{
+    PROGRESS_DLGPARAM dlgParam;
+    int rv;
+
+    dlgParam.szHead  = szHeader;
+    dlgParam.szText  = szText;
+    dlgParam.cbData  = cbData;
+    dlgParam.fnCb    = fnProgressCallback;
+    dlgParam.hThread = NULL;
+    rv =  (int)DialogBoxParam(_st_sys_gui.hInstance,
+                              MAKEINTRESOURCE(IDD_PROGRESS),
+                              hWnd,
+                              (DLGPROC)__apxProgressDlgProc,
+                              (LPARAM)&dlgParam);
+    return rv;
+}
+
+BOOL apxYesNoMessage(LPCTSTR szTitle, LPCTSTR szMessage, BOOL bStop)
+{
+    UINT uType = MB_YESNO;
+    int rv;
+
+    if (bStop)
+        uType |= MB_DEFBUTTON2 | MB_ICONEXCLAMATION;
+    else
+        uType |= MB_DEFBUTTON1 | MB_ICONQUESTION;
+
+    rv = MessageBox(_st_sys_gui.hMainWnd, szMessage, szTitle, uType); 
+    
+    return (rv == IDYES);
+}
+
+LPWSTR apxGetDlgTextW(APXHANDLE hPool, HWND hDlg, int nIDDlgItem)
+{
+    DWORD l, n;
+    LPWSTR szT = NULL;
+
+    l = (DWORD)SendMessageW(GetDlgItem(hDlg, nIDDlgItem), WM_GETTEXTLENGTH, 0, 0);
+    if (l > 0) {
+        szT = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+        n = GetDlgItemTextW(hDlg, nIDDlgItem, szT, l + 1);
+        if (n == 0) {
+            apxFree(szT);
+            szT = NULL;
+        }
+    }
+    return szT;
+}
+
+LPSTR apxGetDlgTextA(APXHANDLE hPool, HWND hDlg, int nIDDlgItem)
+{
+    DWORD l, n;
+    LPSTR szT = NULL;
+
+    l = (DWORD)SendMessageA(GetDlgItem(hDlg, nIDDlgItem), WM_GETTEXTLENGTH, 0, 0);
+    if (l > 0) {
+        szT = apxPoolAlloc(hPool, (l + 1));
+        n = GetDlgItemTextA(hDlg, nIDDlgItem, szT, l + 1);
+        if (n == 0) {
+            apxFree(szT);
+            szT = NULL;
+        }
+    }
+    return szT;
+}
+
+/* Browse for folder dialog.
+ */
+LPSTR apxBrowseForFolderA(HWND hWnd, LPCSTR szTitle, LPCSTR szName)
+{
+    BROWSEINFOA  bi;
+    ITEMIDLIST   *il, *ir;
+    LPMALLOC     pMalloc;
+    CHAR         szPath[MAX_PATH+1];
+    LPSTR        rv = NULL;
+
+    AplZeroMemory(&bi, sizeof(BROWSEINFOW));
+    SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &il);
+    bi.lpszTitle      = szTitle;
+    bi.pszDisplayName = szPath;
+    bi.hwndOwner      = hWnd;
+    bi.ulFlags        = BIF_EDITBOX;
+    bi.lpfn           = NULL;
+    bi.lParam         = 0;
+    bi.iImage         = 0;
+    bi.pidlRoot       = il;
+    
+    if ((ir = SHBrowseForFolderA(&bi)) != NULL) {
+        if (SHGetPathFromIDListA(ir, szPath))
+            rv = apxStrdupA(szPath);
+    }
+    if (SHGetMalloc(&pMalloc)) {
+        pMalloc->lpVtbl->Free(pMalloc, il);
+        pMalloc->lpVtbl->Release(pMalloc);
+    }
+
+    return rv;    
+} 
+
+LPWSTR apxBrowseForFolderW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szName)
+{
+    BROWSEINFOW  bi;
+    ITEMIDLIST   *il, *ir;
+    LPMALLOC     pMalloc;
+    WCHAR        szPath[MAX_PATH+1];
+    LPWSTR       rv = NULL;
+
+    AplZeroMemory(&bi, sizeof(BROWSEINFOW));
+    SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &il);
+    bi.lpszTitle      = szTitle;
+    bi.pszDisplayName = szPath;
+    bi.hwndOwner      = hWnd;
+    bi.ulFlags        = BIF_EDITBOX;
+    bi.lpfn           = NULL;
+    bi.lParam         = 0;
+    bi.iImage         = 0;
+    bi.pidlRoot       = il;
+    
+    if ((ir = SHBrowseForFolderW(&bi)) != NULL) {
+        if (SHGetPathFromIDListW(ir, szPath))
+            rv = apxStrdupW(szPath);
+    }
+    if (SHGetMalloc(&pMalloc)) {
+        pMalloc->lpVtbl->Free(pMalloc, il);
+        pMalloc->lpVtbl->Release(pMalloc);
+    }
+
+    return rv;    
+} 
+
+LPSTR apxGetFileNameA(HWND hWnd, LPCSTR szTitle, LPCSTR szFilter,
+                      LPCSTR szDefExt, LPCSTR szDefPath, BOOL bOpenOrSave,
+                      LPDWORD lpdwFindex)
+{
+    OPENFILENAMEA lpOf;
+    CHAR    szFile[SIZ_BUFLEN];
+    BOOL    rv;
+
+    AplZeroMemory(&lpOf, sizeof(OPENFILENAMEA));
+    szFile[0] = '\0';
+    lpOf.lStructSize     = sizeof(OPENFILENAMEA); 
+    lpOf.hwndOwner       = hWnd;
+    lpOf.hInstance       = _st_sys_gui.hInstance;
+    lpOf.lpstrTitle      = szTitle;
+    lpOf.lpstrFilter     = szFilter;
+    lpOf.lpstrDefExt     = szDefExt;
+    lpOf.lpstrInitialDir = szDefPath;
+    lpOf.lpstrFile       = szFile;
+    lpOf.nMaxFile        = SIZ_BUFMAX;
+ 	lpOf.Flags = OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
+
+    if (bOpenOrSave)
+        rv = GetOpenFileNameA(&lpOf);
+    else
+        rv = GetSaveFileNameA(&lpOf);
+    
+    if (rv) {
+        if (lpdwFindex)
+            *lpdwFindex = lpOf.nFilterIndex;
+        return apxStrdupA(szFile);
+    }
+    else
+        return NULL;
+}
+
+LPWSTR apxGetFileNameW(HWND hWnd, LPCWSTR szTitle, LPCWSTR szFilter,
+                       LPCWSTR szDefExt, LPCWSTR szDefPath, BOOL bOpenOrSave,
+                       LPDWORD lpdwFindex)
+{
+    OPENFILENAMEW lpOf;
+    WCHAR    szFile[SIZ_BUFLEN];
+    BOOL    rv;
+
+    AplZeroMemory(&lpOf, sizeof(OPENFILENAMEW));
+    szFile[0] = L'\0';
+    lpOf.lStructSize     = sizeof(OPENFILENAMEW); 
+    lpOf.hwndOwner       = hWnd;
+    lpOf.hInstance       = _st_sys_gui.hInstance;
+    lpOf.lpstrTitle      = szTitle;
+    lpOf.lpstrFilter     = szFilter;
+    lpOf.lpstrDefExt     = szDefExt;
+    lpOf.lpstrInitialDir = szDefPath;
+    lpOf.lpstrFile       = szFile;
+    lpOf.nMaxFile        = SIZ_BUFMAX;
+ 	lpOf.Flags = OFN_LONGNAMES | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
+
+    if (bOpenOrSave)
+        rv = GetOpenFileNameW(&lpOf);
+    else
+        rv = GetSaveFileNameW(&lpOf);
+    
+    if (rv) {
+        if (lpdwFindex)
+            *lpdwFindex = lpOf.nFilterIndex;
+        return apxStrdupW(szFile);
+    }
+    else
+        return NULL;
+}
+
+static __apxSelectUserDlgResize(HWND hDlg, INT nWidth, INT nHeight)
+{
+    /* Combo box */
+    MoveWindow(GetDlgItem(hDlg, IDSU_COMBO),
+        70, 10, 
+        nWidth - 70,
+        120,
+        TRUE);
+    /* List Window */
+    MoveWindow(GetDlgItem(hDlg, IDSU_LIST),
+        0, 36, 
+        nWidth,
+        nHeight - 74,
+        TRUE);
+
+    /* Name label */
+    MoveWindow(GetDlgItem(hDlg, IDSU_SELNAME),
+        16,
+        nHeight - 30, 
+        50,
+        24,
+        TRUE);
+
+    /* Edit Box */
+    MoveWindow(GetDlgItem(hDlg, IDSU_SELECTED),
+        70, 
+        nHeight - 32, 
+        nWidth - 300,
+        24,
+        TRUE);
+
+    /* OK Button */
+    MoveWindow(GetDlgItem(hDlg, IDOK),
+        nWidth - 200,
+        nHeight - 32, 
+        80,
+        24,
+        TRUE);
+
+    /* Cancel Button */
+    MoveWindow(GetDlgItem(hDlg, IDCANCEL),
+        nWidth - 110,
+        nHeight - 32, 
+        80,
+        24,
+        TRUE);
+
+
+}
+
+static LRESULT CALLBACK
+__apxSelectUserCreateLvSubclass(HWND hWnd, UINT uMsg, WPARAM wParam,
+                                LPARAM lParam)
+{
+    static POINTS  mouseClick;
+    int iS;
+    LVHITTESTINFO iHit;
+    switch (uMsg) {
+        case WM_LBUTTONDBLCLK:
+            /* Call the original window proc */
+            CallWindowProc(_st_sel_users_lvm, hWnd, uMsg, wParam, lParam);
+            mouseClick = MAKEPOINTS(lParam);
+            iHit.pt.x = mouseClick.x;
+            iHit.pt.y = mouseClick.y;
+            iS = ListView_HitTest(hWnd, &iHit);
+            if (iS >= 0) {
+                DWORD    i;
+                WCHAR    szUser[SIZ_RESLEN] = L"";
+                LPWSTR   szP;
+                HWND     hCombo;
+                HWND     hDlg = GetParent(hWnd);
+                hCombo = GetDlgItem(hDlg, IDSU_COMBO);
+                if ((i = ComboBox_GetCurSel(hCombo)) == 0) {
+                    lstrcpyW(szUser, L".\\");
+                }
+                else {
+                    COMBOBOXEXITEMW cbEi;
+                    cbEi.mask  = CBEIF_TEXT;
+                    cbEi.iItem = i;
+                    cbEi.cchTextMax = SIZ_RESMAX;
+                    cbEi.pszText    = szUser;
+                    SendMessage(hCombo, CBEM_GETITEM, 0, (LPARAM)&cbEi);
+                    lstrcatW(szUser, L"\\");
+                }
+                szP = &szUser[lstrlenW(szUser)];
+                ListView_GetItemTextW(hWnd, iS, 0, szP, SIZ_RESMAX);
+                if (*szP) {
+                    SetDlgItemTextW(hDlg, IDSU_SELECTED, szUser);
+                }
+            }
+            return TRUE;
+       break;
+    }
+    return CallWindowProc(_st_sel_users_lvm, hWnd, uMsg, wParam, lParam);
+}
+
+#define SUMIN_WIDTH     600
+#define SUMIN_HEIGHT    200
+
+static void __apxSelectUserCreateLv(HWND hDlg)
+{
+    DWORD       i;
+    LV_COLUMN   lvC;
+    HBITMAP     hBmp;
+
+    HWND        hList = GetDlgItem(hDlg, IDSU_LIST);
+
+    lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+    for (i = 0; i < NUMLVUSERS; i++) {
+        lvC.iSubItem = i;
+        lvC.cx       = lvUsers[i].iWidth;
+        lvC.pszText  = lvUsers[i].szLabel;
+        lvC.fmt      = lvUsers[i].iFmt;
+        ListView_InsertColumn(hList, i, &lvC ); 
+    }
+#ifdef LVS_EX_FULLROWSELECT
+    ListView_SetExtendedListViewStyleEx(hList, 0,
+    LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);
+#endif 
+    _st_sel_users_il = ImageList_Create(16, 16, ILC_COLOR4, 0, 16);
+    hBmp = LoadImage(GetModuleHandleA(NULL), MAKEINTRESOURCE(IDB_SUSERS),
+                     IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
+
+    ImageList_Add(_st_sel_users_il, hBmp, NULL);
+    DeleteObject(hBmp);
+
+    ListView_SetImageList(hList, _st_sel_users_il, LVSIL_SMALL);
+    _st_sel_users_lvm = (WNDPROC)((SIZE_T)SetWindowLong(hList, GWL_WNDPROC, 
+                                                        (LONG)((SIZE_T)__apxSelectUserCreateLvSubclass))); 
+
+}
+
+static void __apxSelectUserPopulate(HWND hDlg, LPCWSTR szComputer)
+{
+    PNET_DISPLAY_USER   pBuff, p;
+    INT             row = 0x7FFFFFFF;
+    DWORD           res, dwRec, i = 0;
+
+    HWND        hList = GetDlgItem(hDlg, IDSU_LIST);
+   
+    ListView_DeleteAllItems(hList);
+
+    do { 
+        res = NetQueryDisplayInformation(szComputer, 1, i, 1000, MAX_PREFERRED_LENGTH,
+                                         &dwRec, &pBuff);
+        if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+            p = pBuff;
+            for (;dwRec > 0; dwRec--) {
+                LV_ITEMW        lvI;
+                AplZeroMemory(&lvI, sizeof(LV_ITEMW)); 
+                lvI.mask        = LVIF_IMAGE | LVIF_TEXT;
+                lvI.iItem       = 0x7FFFFFFF;
+                lvI.pszText     = p->usri1_name;
+                if (p->usri1_flags & UF_ACCOUNTDISABLE)
+                    lvI.iImage = 5;
+                else
+                    lvI.iImage = 4;
+                row = ListView_InsertItemW(hList, &lvI);
+                if (row != -1) {
+                    if (p->usri1_full_name) {
+                        ListView_SetItemTextW(hList, row, 1,
+                                              p->usri1_full_name);
+                    }
+                    if (p->usri1_comment) {
+                        ListView_SetItemTextW(hList, row, 2,
+                                              p->usri1_comment);
+                    }
+                }
+                i = p->usri1_next_index;
+                p++;
+            }
+            NetApiBufferFree(pBuff);
+        }
+    } while (res == ERROR_MORE_DATA);
+
+}
+
+static void __apxSelectUserCreateCbex(HWND hDlg)
+{
+    COMBOBOXEXITEMW     cbEi;
+    LPBYTE              lpNetBuf;
+    LPWKSTA_INFO_100    lpWksta;
+    DWORD               res;
+    HWND hCombo = GetDlgItem(hDlg, IDSU_COMBO);
+
+#ifndef _UNICODE
+    SendMessageW(hCombo, CBEM_SETUNICODEFORMAT, TRUE, 0);    
+#endif
+
+    cbEi.mask = CBEIF_TEXT | CBEIF_INDENT |
+                CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
+
+    res = NetWkstaGetInfo(NULL, 101, (LPBYTE *)&lpWksta);
+    if (res != ERROR_SUCCESS) {
+        EnableWindow(hCombo, FALSE);
+        return;
+    }
+    /* add localhost computer */
+    cbEi.iItem      = 0;
+    cbEi.pszText    = (LPWSTR)lpWksta->wki100_computername;
+    cbEi.iIndent    = 0;
+    cbEi.iImage         = 1;
+    cbEi.iSelectedImage = 1;
+    SendMessageW(hCombo, CBEM_INSERTITEMW, 0, (LPARAM)&cbEi);
+    NetApiBufferFree(lpWksta);
+
+    ComboBox_SetCurSel(hCombo, 0);
+    res = NetGetDCName(NULL, NULL, &lpNetBuf);
+    if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+
+        cbEi.iItem      = 1;
+        cbEi.pszText    = ((LPWSTR)lpNetBuf) + 2;
+        cbEi.iIndent    = 0;
+        cbEi.iImage         = 0;
+        cbEi.iSelectedImage = 0;
+        SendMessageW(hCombo, CBEM_INSERTITEMW, 0, (LPARAM)&cbEi);
+        EnableWindow(hCombo, TRUE);
+        NetApiBufferFree(lpNetBuf);
+    }
+    else
+        EnableWindow(hCombo, FALSE);
+    
+    SendMessageW(hCombo, CBEM_SETIMAGELIST, 0, (LPARAM)_st_sel_users_il);
+}
+
+static LRESULT CALLBACK __apxSelectUserDlgProc(HWND hDlg, UINT uMsg,
+                                               WPARAM wParam, LPARAM lParam)
+{
+    static HWND     hList;
+    static LPWSTR   lpUser;
+    RECT r, *l;
+
+    switch (uMsg) {
+        case WM_INITDIALOG:
+            /* Set the application icon */
+            SetClassLong(hDlg, GCL_HICON,
+                         (LONG)(SIZE_T)LoadIcon(_st_sys_gui.hInstance,
+                                        MAKEINTRESOURCE(IDI_MAINICON))); 
+            apxCenterWindow(hDlg, _st_sys_gui.hMainWnd);
+            hList = GetDlgItem(hDlg, IDSU_LIST); 
+            __apxSelectUserCreateLv(hDlg);
+            __apxSelectUserCreateCbex(hDlg);
+            GetClientRect(hDlg, &r);
+            /* Resize the controls */
+            __apxSelectUserDlgResize(hDlg, r.right - r.left,
+                                     r.bottom - r.top);
+            lpUser = (LPWSTR)lParam;
+            __apxSelectUserPopulate(hDlg, NULL);
+            return TRUE;
+        break;
+        case WM_SIZING:
+            l = (LPRECT)lParam;
+            /* limit the window size */
+            switch (wParam) {
+                case WMSZ_BOTTOM:
+                case WMSZ_BOTTOMRIGHT:
+                    if ((l->bottom - l->top) < SUMIN_HEIGHT)
+                        l->bottom = l->top + SUMIN_HEIGHT;
+                    if ((l->right - l->left) < SUMIN_WIDTH)
+                        l->right = l->left + SUMIN_WIDTH;
+                break;
+                case WMSZ_TOPLEFT:
+                    if ((l->bottom - l->top) < SUMIN_HEIGHT)
+                        l->top = l->bottom - SUMIN_HEIGHT;
+                    if ((l->right - l->left) < SUMIN_WIDTH)
+                        l->left = l->right - SUMIN_WIDTH;
+                break;
+                case WMSZ_TOP:
+                case WMSZ_RIGHT:
+                case WMSZ_TOPRIGHT:
+                    if ((l->bottom - l->top) < SUMIN_HEIGHT)
+                        l->top = l->bottom - SUMIN_HEIGHT;
+                    if ((l->right - l->left) < SUMIN_WIDTH)
+                        l->right = l->left + SUMIN_WIDTH;
+                break;
+                case WMSZ_BOTTOMLEFT:
+                case WMSZ_LEFT:
+                    if ((l->bottom - l->top) < SUMIN_HEIGHT)
+                        l->bottom = l->top + SUMIN_HEIGHT;
+                    if ((l->right - l->left) < SUMIN_WIDTH)
+                        l->left = l->right - SUMIN_WIDTH;
+                break;
+            }
+        break;
+        case WM_SIZE:
+            __apxSelectUserDlgResize(hDlg, LOWORD(lParam),
+                                     HIWORD(lParam));
+            GetClientRect(hDlg, &r);
+            InvalidateRect(hDlg, &r, FALSE);
+        break;
+        case WM_COMMAND:
+            switch (LOWORD(wParam)) {
+                case IDOK:
+                    EndDialog(hDlg, LOWORD(wParam));
+                    return TRUE;
+                case IDCANCEL:
+                    /* Clear the user name buffer */
+                    *lpUser = L'\0';
+                    EndDialog(hDlg, LOWORD(wParam));
+                    return TRUE;
+                break;
+               case IDSU_SELECTED:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        /* enable OK button if there is a user */
+                        GetDlgItemTextW(hDlg, IDSU_SELECTED, lpUser, SIZ_RESMAX);
+                        if (lstrlenW(lpUser))
+                            Button_Enable(GetDlgItem(hDlg, IDOK), TRUE);
+                        else
+                            Button_Enable(GetDlgItem(hDlg, IDOK), FALSE);
+                    }
+                break;
+                case IDSU_COMBO:
+                    if (HIWORD(wParam) == CBN_SELCHANGE) {
+                        COMBOBOXEXITEMW cbEi;
+                        DWORD i;
+                        WCHAR szServer[SIZ_RESLEN] = L"\\\\";
+                        HWND  hCombo = GetDlgItem(hDlg, IDSU_COMBO);
+                        if ((i = ComboBox_GetCurSel(hCombo)) >= 0) {
+                            cbEi.mask  = CBEIF_TEXT;
+                            cbEi.iItem = i;
+                            cbEi.cchTextMax = SIZ_RESMAX;
+                            cbEi.pszText    = &szServer[2];
+                            SendMessageW(hCombo, CBEM_GETITEM, 0, (LPARAM)&cbEi);
+                        }
+                        if (szServer[2])
+                            __apxSelectUserPopulate(hDlg, szServer);
+                    }
+                break;
+
+            }
+        break;
+        case WM_MOUSEWHEEL:
+            {
+                int nScroll;
+                if ((SHORT)HIWORD(wParam) < 0)
+                    nScroll = _st_sys_gui.nWhellScroll;
+                else
+                    nScroll = _st_sys_gui.nWhellScroll * (-1);
+            }
+        break;
+
+    }
+    return FALSE;
+} 
+
+
+LPCWSTR apxDlgSelectUser(HWND hWnd, LPWSTR szUser)
+{
+    szUser[0] = L'\0';
+
+    DialogBoxParam(_st_sys_gui.hInstance,
+                   MAKEINTRESOURCE(IDD_SELUSER),
+                   hWnd,
+                   (DLGPROC)__apxSelectUserDlgProc,
+                   (LPARAM)szUser);
+    if (_st_sel_users_il)
+        ImageList_Destroy(_st_sel_users_il);
+    _st_sel_users_il = NULL;
+    if (szUser[0] != '\0')
+        return szUser;
+    else
+        return NULL;
+}
diff --git a/src/native/nt/procrun/src/handles.c b/src/native/nt/procrun/src/handles.c
new file mode 100644
index 0000000..bae886c
--- /dev/null
+++ b/src/native/nt/procrun/src/handles.c
@@ -0,0 +1,685 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+#define ALLOCBLOCK_INVALID      0xdeadbeef
+
+typedef struct APXPOOL      APXPOOL;
+typedef APXPOOL*            LPAPXPOOL;
+
+typedef struct ALLOCBLOCK {
+    DWORD       dwSize;
+    APXHANDLE   lpPool;
+    APXMEMWORD  lpAlign;
+} ALLOCBLOCK, *LPALLOCBLOCK;
+
+struct APXPOOL {
+    TAILQ_HEAD(_lHandles, stAPXHANDLE) lHandles;
+    TAILQ_HEAD(_lPools, stAPXHANDLE)   lPools;
+};
+
+static SYSTEM_INFO      _st_sys_info;
+static APXHANDLE        _st_sys_pool  = NULL;
+static int              _st_sys_init  = 0;
+static LPVOID           _st_sys_page  = NULL;
+LPWSTR                  *_st_sys_argvw = NULL;
+int                     _st_sys_argc  = 0;
+
+#ifdef _DEBUG
+static INT  _heap_count = 0;
+static INT  _heap_alloc_count = 0;
+static INT  _heap_realloc_count = 0;
+
+HANDLE HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
+{
+    _heap_count++;
+    return HeapCreate(flOptions, dwInitialSize, dwMaximumSize);
+}
+
+BOOL HeapDESTROY(HANDLE hHeap)
+{
+    _heap_count--;
+    return HeapDestroy(hHeap);
+}
+
+
+LPVOID HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize)
+{
+    _heap_alloc_count++;
+    return HeapAlloc(hHeap, dwFlags, nSize);
+}
+
+BOOL HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
+{
+    _heap_alloc_count--;
+    return HeapFree(hHeap, dwFlags, lpMem);
+}
+
+LPVOID HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
+{
+
+    _heap_realloc_count++;
+    return HeapReAlloc(hHeap, dwFlags, lpMem, dwBytes);
+}
+#endif
+
+static LPVOID __apxPoolAllocCore(APXHANDLE hPool, 
+                                 DWORD dwSize, DWORD dwOptions)
+{
+    DWORD dwPhysicalSize;
+    LPALLOCBLOCK lpBlock;
+    
+    if (!hPool)
+        hPool = _st_sys_pool;
+    dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
+    lpBlock = HeapALLOC(hPool->hHeap, dwOptions, dwPhysicalSize);
+    lpBlock->dwSize = dwPhysicalSize;
+    lpBlock->lpPool = hPool;
+
+    return ((char *)lpBlock + sizeof(ALLOCBLOCK));
+}
+
+static LPVOID __apxPoolReallocCore(APXHANDLE hPool, LPVOID lpMem,
+                                   DWORD dwSize, DWORD dwOptions)
+{
+    DWORD dwPhysicalSize;
+    LPALLOCBLOCK lpBlock;
+    LPALLOCBLOCK lpOrg;
+    
+    if (!lpMem)
+        return __apxPoolAllocCore(hPool, dwSize, dwOptions);
+    lpOrg = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
+    if (!hPool)
+        hPool = _st_sys_pool;
+    /* Trying to realloc something that isn't valid */
+    if (lpOrg->lpPool == APXHANDLE_INVALID ||
+        lpOrg->lpPool != hPool)
+        return NULL;
+    dwPhysicalSize = APX_ALIGN_DEFAULT(dwSize + sizeof(ALLOCBLOCK));
+    lpBlock = HeapREALLOC(hPool->hHeap, dwOptions, lpOrg, dwPhysicalSize);
+    lpBlock->dwSize = dwPhysicalSize;
+    lpBlock->lpPool = hPool;
+
+    return ((char *)lpBlock + sizeof(ALLOCBLOCK));
+}
+
+static void __apxPoolFreeCore(LPVOID lpMem)
+{
+    APXHANDLE hPool;
+    LPALLOCBLOCK lpBlock = (LPALLOCBLOCK)((char *)lpMem - sizeof(ALLOCBLOCK));
+    
+    if (lpBlock->lpPool != APXHANDLE_INVALID) {
+        hPool = lpBlock->lpPool;
+        lpBlock->lpPool = APXHANDLE_INVALID;
+    }
+    else
+        return;
+    HeapFREE(hPool->hHeap, 0, lpBlock);
+}
+/*
+ *
+ */
+static DWORD WINAPI __apxHandleEventThread(LPVOID lpParameter)
+{
+    APXHANDLE hHandle = (APXHANDLE)lpParameter;
+    DWORD rv = 0;
+    while (hHandle->dwType != APXHANDLE_TYPE_INVALID) {
+        DWORD dwState;
+        dwState = WaitForSingleObject(hHandle->hEventHandle, INFINITE);
+        /* the flags can be changed to invalid meaning we are killing
+         * this event.
+         */
+        if (dwState == WAIT_OBJECT_0 &&
+            hHandle->dwType != APXHANDLE_TYPE_INVALID) {
+            if (hHandle->uMsg && (hHandle->wParam || hHandle->lParam)) {
+                APXCALLHOOK *lpCall;
+                rv = (*hHandle->fnCallback)(hHandle, hHandle->uMsg,
+                                            hHandle->wParam, hHandle->lParam);
+                TAILQ_FOREACH(lpCall, &hHandle->lCallbacks, queue) {
+                    (*lpCall->fnCallback)(hHandle, hHandle->uMsg,
+                                          hHandle->wParam, hHandle->lParam);
+                }
+                hHandle->uMsg = 0;
+                if (!rv)
+                    break;
+            }
+            ResetEvent(hHandle->hEventHandle);
+            SwitchToThread();
+        }
+        else
+            break;
+    }
+    ResetEvent(hHandle->hEventHandle);
+    /* This will rise the Thread waiting function */
+    return 0;
+}
+
+static BOOL __apxPoolCallback(APXHANDLE hObject, UINT uMsg,
+                              WPARAM wParam, LPARAM lParam)
+{
+    LPAPXPOOL  lpPool;
+    APXHANDLE   hCur;
+    if (hObject->dwType != APXHANDLE_TYPE_POOL)
+        return FALSE;
+    lpPool = APXHANDLE_DATA(hObject);
+
+    /* recurse the subpools */
+    TAILQ_FOREACH(hCur, &lpPool->lPools, queue) {
+        __apxPoolCallback(hCur, uMsg, 0, 0);
+    }
+    /* call the handles callback */        
+    for(hCur = TAILQ_FIRST(&lpPool->lHandles) ;
+        hCur != NULL ;
+        hCur = TAILQ_FIRST(&lpPool->lHandles)) {
+        apxCloseHandle(hCur);
+    }
+    /* if we are closing this pool destroy the private Heap */
+    if (uMsg == WM_CLOSE) {
+        if (hObject->dwFlags & APXHANDLE_HAS_HEAP)
+            HeapDESTROY(hObject->hHeap);
+        hObject->dwSize = 0;
+    }
+    else if (uMsg == WM_CLEAR)
+        hObject->dwSize = 0;
+
+    return TRUE;
+}
+
+static BOOL __apxHandleCallback(APXHANDLE hObject, UINT uMsg,
+                                WPARAM wParam, LPARAM lParam)
+{
+    BOOL rv = FALSE;
+    if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+        return FALSE;
+    /* Default handler handles only close event */
+    if (uMsg != WM_CLOSE)
+        return FALSE;
+    if (hObject->dwType == APXHANDLE_TYPE_WINHANDLE && 
+        !(IS_INVALID_HANDLE(hObject->uData.hWinHandle))) {
+        rv = CloseHandle(hObject->uData.hWinHandle);
+        hObject->uData.hWinHandle = NULL;
+    }
+    /* Invalidate the handle */
+    hObject->dwType = APXHANDLE_TYPE_INVALID;
+
+    if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+        DWORD dwState;
+        /* Signal the EventThread to exit */
+        SetEvent(hObject->hEventHandle);
+        /* Wait for EventThread to Exit */
+        dwState = WaitForSingleObject(hObject->hEventThread, 1000);
+        SAFE_CLOSE_HANDLE(hObject->hEventHandle);
+        if (dwState == WAIT_TIMEOUT)
+            TerminateThread(hObject->hEventThread, 0);
+        SAFE_CLOSE_HANDLE(hObject->hEventThread);
+        /* Reset the evant flag */
+        hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
+    }
+    return rv;
+}
+
+static BOOL __apxCreateSystemPool()
+{
+    LPAPXPOOL lpPool;
+    HANDLE    hHeap;
+
+    GetSystemInfo(&_st_sys_info);
+    apxGetOsLevel();
+    /* First create the shared data segment */
+    _st_sys_page = VirtualAlloc(NULL, _st_sys_info.dwAllocationGranularity,
+                                MEM_RESERVE, PAGE_NOACCESS);
+    if (!_st_sys_page)
+        return FALSE;
+    _st_sys_page = VirtualAlloc(_st_sys_page, _st_sys_info.dwAllocationGranularity,
+                                MEM_COMMIT, PAGE_READWRITE);     
+
+    /* Create the main Heap */
+    hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
+    _st_sys_pool = HeapALLOC(hHeap, HEAP_ZERO_MEMORY, 
+                             APX_ALIGN_DEFAULT(APXHANDLE_SZ + sizeof(APXPOOL)));
+    _st_sys_pool->hHeap = hHeap;
+    _st_sys_pool->dwType = APXHANDLE_TYPE_INVALID;
+    if (IS_INVALID_HANDLE(_st_sys_pool->hHeap))
+        return FALSE;
+    _st_sys_pool->fnCallback = __apxPoolCallback;
+    lpPool = APXHANDLE_DATA(_st_sys_pool);
+    /* Initialize the pool and object lists */
+    TAILQ_INIT(&lpPool->lHandles);
+    TAILQ_INIT(&lpPool->lPools);
+    _st_sys_pool->dwType  = APXHANDLE_TYPE_POOL;
+    
+    /** TODO: For each unsupported function make a surrogate */
+    _st_sys_argvw = CommandLineToArgvW(GetCommandLineW(), &_st_sys_argc);
+
+    return TRUE;
+}
+
+BOOL
+apxHandleManagerInitialize()
+{
+    BOOL rv;
+    if (_st_sys_init++)
+        return TRUE;
+    rv = __apxCreateSystemPool();
+
+    return rv;
+}
+
+BOOL
+apxHandleManagerDestroy()
+{
+    HANDLE hHeap;
+
+    if (--_st_sys_init == 0) {
+        hHeap = _st_sys_pool->hHeap;
+        apxCloseHandle(_st_sys_pool);
+        /* Destroy the main Heap */
+        HeapDESTROY(hHeap);
+        _st_sys_pool = NULL;
+        VirtualFree(_st_sys_page, 0, MEM_RELEASE);
+        GlobalFree(_st_sys_argvw);
+        _st_sys_argvw = NULL;
+        _st_sys_argc  = 0;
+#ifdef _DEBUG
+        apxLogWrite(APXLOG_MARK_DEBUG "Alloc   Count %d", _heap_alloc_count);
+        apxLogWrite(APXLOG_MARK_DEBUG "Realloc Count %d", _heap_realloc_count);
+        apxLogWrite(APXLOG_MARK_DEBUG "Heap    Count %d", _heap_count);
+#endif
+        return TRUE;
+    }
+    
+    return FALSE;
+}
+
+APXHANDLE
+apxPoolCreate(APXHANDLE hParent, DWORD dwOptions)
+{
+    APXHANDLE   hHandle; 
+    LPAPXPOOL   lpPool;
+    HANDLE      hHeap;
+
+    if (IS_INVALID_HANDLE(hParent))
+        hParent = _st_sys_pool;
+    if (hParent->dwType != APXHANDLE_TYPE_POOL) {
+        apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
+                    hParent->dwType);
+        return INVALID_HANDLE_VALUE;
+    }
+    /* Allocate the handle from the parent */
+    hHandle = __apxPoolAllocCore(hParent, APXHANDLE_SZ + sizeof(APXPOOL),
+                                 HEAP_ZERO_MEMORY);
+
+    if (dwOptions & APXHANDLE_HAS_HEAP) {
+        /* Create the private Heap */
+        hHeap = HeapCREATE(0, _st_sys_info.dwAllocationGranularity, 0);
+        hHandle->dwFlags |= APXHANDLE_HAS_HEAP;
+    }
+    else
+        hHeap = hParent->hHeap;
+    hHandle->hHeap = hHeap;
+    hHandle->dwType = APXHANDLE_TYPE_POOL;
+    hHandle->hPool  = hParent;
+    hHandle->fnCallback = __apxPoolCallback;
+    lpPool = APXHANDLE_DATA(hHandle);
+    TAILQ_INIT(&lpPool->lHandles);
+    TAILQ_INIT(&lpPool->lPools);
+
+    /* Insert the pool to the head of parent pool */
+    lpPool = APXHANDLE_DATA(hParent);
+    APXHANDLE_SPINLOCK(hParent);
+    TAILQ_INSERT_HEAD(&lpPool->lPools, hHandle, queue);
+    ++hParent->dwSize;
+    APXHANDLE_SPINUNLOCK(hParent);
+
+    return hHandle;
+}
+
+LPVOID
+apxPoolAlloc(APXHANDLE hPool, DWORD dwSize)
+{
+    if (IS_INVALID_HANDLE(hPool) ||
+        (hPool->dwType != APXHANDLE_TYPE_POOL))
+        hPool = _st_sys_pool;
+    return __apxPoolAllocCore(hPool, dwSize, 0);
+}
+
+LPVOID
+apxPoolCalloc(APXHANDLE hPool, DWORD dwSize)
+{
+    if (IS_INVALID_HANDLE(hPool) ||
+        (hPool->dwType != APXHANDLE_TYPE_POOL))
+        hPool = _st_sys_pool;
+    return __apxPoolAllocCore(hPool, dwSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxPoolRealloc(APXHANDLE hPool, LPVOID lpMem, DWORD dwNewSize)
+{
+    if (IS_INVALID_HANDLE(hPool) ||
+        (hPool->dwType != APXHANDLE_TYPE_POOL))
+        hPool = _st_sys_pool;
+    return __apxPoolReallocCore(hPool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxAlloc(DWORD dwSize)
+{
+    return __apxPoolAllocCore(_st_sys_pool, dwSize, 0);
+}
+
+LPVOID
+apxCalloc(DWORD dwSize)
+{
+    return __apxPoolAllocCore(_st_sys_pool, dwSize, HEAP_ZERO_MEMORY);
+}
+
+LPVOID
+apxRealloc(LPVOID lpMem, DWORD dwNewSize)
+{
+    return __apxPoolReallocCore(_st_sys_pool, lpMem, dwNewSize, HEAP_ZERO_MEMORY);
+}
+
+VOID
+apxFree(LPVOID lpMem)
+{
+    if (lpMem)
+        __apxPoolFreeCore(lpMem);
+
+}
+
+LPWSTR
+apxPoolWStrdupA(APXHANDLE hPool, LPCSTR szSource)
+{
+    if (szSource) {
+        LPWSTR szDest;
+        DWORD l = lstrlenA(szSource);
+        szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+        AsciiToWide(szSource, szDest);
+        return szDest;
+    }
+    else
+        return NULL;
+}
+
+LPWSTR apxWStrdupA(LPCTSTR szSource)
+{
+    return apxPoolWStrdup(_st_sys_pool, szSource);
+}
+
+LPSTR
+apxPoolStrdupA(APXHANDLE hPool, LPCSTR szSource)
+{
+    if (szSource) {
+        LPSTR szDest;
+        DWORD l = lstrlenA(szSource);
+        szDest = apxPoolAlloc(hPool, l + 1);
+        lstrcpyA(szDest, szSource);
+        return szDest;
+    }
+    else
+        return NULL;
+}
+
+LPWSTR
+apxPoolStrdupW(APXHANDLE hPool, LPCWSTR szSource)
+{
+    if (szSource) {
+        LPWSTR szDest;
+        DWORD l = lstrlenW(szSource);
+        szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
+        lstrcpyW(szDest, szSource);
+        return szDest;
+    }
+    else
+        return NULL;
+}
+
+LPSTR
+apxStrdupA(LPCSTR szSource)
+{
+    return apxPoolStrdupA(_st_sys_pool, szSource);
+}
+
+LPWSTR
+apxStrdupW(LPCWSTR szSource)
+{
+    return apxPoolStrdupW(_st_sys_pool, szSource);
+}
+
+APXHANDLE
+apxHandleCreate(APXHANDLE hPool, DWORD dwFlags, 
+                LPVOID lpData, DWORD  dwDataSize,
+                LPAPXFNCALLBACK fnCallback)
+{
+    APXHANDLE   hHandle; 
+    LPAPXPOOL   lpPool;
+    
+    if (IS_INVALID_HANDLE(hPool))
+        hPool = _st_sys_pool;
+    if (hPool->dwType != APXHANDLE_TYPE_POOL) {
+        apxLogWrite(APXLOG_MARK_ERROR "Parent Handle type is not POOL %d",
+                    hPool->dwType);
+        return INVALID_HANDLE_VALUE;
+    }
+    hHandle = __apxPoolAllocCore(hPool, APXHANDLE_SZ + dwDataSize,
+                                 HEAP_ZERO_MEMORY);
+    
+    hHandle->hPool             = hPool;
+    if (fnCallback)
+        hHandle->fnCallback = fnCallback;
+    else
+        hHandle->fnCallback = __apxHandleCallback;
+
+    if (dwFlags & APXHANDLE_TYPE_WINHANDLE) {
+        hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+        hHandle->dwFlags |= APXHANDLE_TYPE_WINHANDLE;
+        hHandle->uData.hWinHandle = lpData;
+    }
+    else if (dwFlags & APXHANDLE_TYPE_LPTR) {
+        hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+        hHandle->dwFlags |= APXHANDLE_TYPE_LPTR;
+        hHandle->uData.lpPtr = lpData;
+    }
+    else if (dwDataSize && lpData) {
+        hHandle->dwFlags |= APXHANDLE_HAS_USERDATA;
+        AplCopyMemory(APXHANDLE_DATA(hHandle), lpData, dwDataSize);
+        hHandle->dwSize = dwDataSize;
+    }
+
+    if (dwFlags & APXHANDLE_HAS_EVENT) {
+        /* Create the message event and message wathcing thread */
+        hHandle->hEventHandle = CreateEvent(NULL, TRUE, FALSE, NULL);
+        hHandle->hEventThread = CreateThread(NULL, 0, __apxHandleEventThread,
+                                            hHandle, 0,
+                                            &(hHandle->hEventThreadId));
+        if (IS_INVALID_HANDLE(hHandle->hEventThread)) {
+            SAFE_CLOSE_HANDLE(hHandle->hEventHandle);
+        }
+        else
+            hHandle->dwFlags |= APXHANDLE_HAS_EVENT;
+    }
+    TAILQ_INIT(&hHandle->lCallbacks);
+    /* Add the handle to the pool's object list */
+    lpPool = APXHANDLE_DATA(hPool);
+    APXHANDLE_SPINLOCK(hPool);
+    TAILQ_INSERT_HEAD(&lpPool->lHandles, hHandle, queue);
+    ++hPool->dwSize;
+    APXHANDLE_SPINUNLOCK(hPool);
+
+    return hHandle;
+}
+
+BOOL
+apxCloseHandle(APXHANDLE hObject)
+{
+    LPAPXPOOL   lpPool;
+    APXCALLHOOK *lpCall;
+    
+    if (IS_INVALID_HANDLE(hObject) || hObject->dwType == APXHANDLE_TYPE_INVALID)
+        return FALSE;
+    /* Call the user callback first */
+    (*hObject->fnCallback)(hObject, WM_CLOSE, 0, 0);
+    /* Now go through the callback chain */
+    TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
+        (*lpCall->fnCallback)(hObject, WM_CLOSE, 0, 0);
+        TAILQ_REMOVE(&hObject->lCallbacks, lpCall, queue);
+        __apxPoolFreeCore(lpCall);
+    }
+
+    hObject->dwType = APXHANDLE_TYPE_INVALID;
+    if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+        DWORD dwState;
+
+        SetEvent(hObject->hEventHandle);
+        dwState = WaitForSingleObject(hObject->hEventThread, 1000);
+        SAFE_CLOSE_HANDLE(hObject->hEventHandle);
+        if (dwState == WAIT_TIMEOUT)
+            TerminateThread(hObject->hEventThread, 0);
+        SAFE_CLOSE_HANDLE(hObject->hEventThread);
+
+        hObject->dwFlags &= ~APXHANDLE_HAS_EVENT;
+    }
+
+    /* finaly remove the object from the pool's object list */
+    if (!IS_INVALID_HANDLE(hObject->hPool)) {
+        lpPool = APXHANDLE_DATA(hObject->hPool);
+        APXHANDLE_SPINLOCK(hObject->hPool);
+        TAILQ_REMOVE(&lpPool->lHandles, hObject, queue);
+        hObject->hPool->dwSize--;
+        APXHANDLE_SPINUNLOCK(hObject->hPool);
+        __apxPoolFreeCore(hObject);
+    }
+    return TRUE;
+}
+
+LPVOID
+apxHandleGetUserData(APXHANDLE hObject)
+{
+    if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+        return NULL;
+    if (hObject->dwFlags & APXHANDLE_HAS_USERDATA)
+        return APXHANDLE_DATA(hObject);
+    else
+        return hObject->uData.lpPtr;
+}
+
+LPVOID      
+apxHandleSetUserData(APXHANDLE hObject, LPVOID lpData, DWORD dwDataSize)
+{
+    if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+        return NULL;
+    if (hObject->dwFlags & APXHANDLE_HAS_USERDATA && hObject->dwSize > 0) {
+        AplCopyMemory(APXHANDLE_DATA(hObject), lpData,
+                      MIN(hObject->dwSize, dwDataSize));
+        return APXHANDLE_DATA(hObject);
+    }
+    else { 
+        LPVOID lpOrg = hObject->uData.lpPtr;
+        hObject->uData.lpPtr = lpData;
+        return lpOrg;
+    }
+}
+
+BOOL apxHandleSendMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    BOOL rv = TRUE;
+    APXCALLHOOK *lpCall;
+    if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+        return FALSE;
+    /* Serialize requests to the callback */
+    APXHANDLE_SPINLOCK(hObject);
+    if (hObject->fnCallback)
+        rv = (*hObject->fnCallback)(hObject, uMsg, wParam, lParam);
+    TAILQ_FOREACH(lpCall, &hObject->lCallbacks, queue) {
+        (*lpCall->fnCallback)(hObject, uMsg, wParam, lParam);
+    }
+    APXHANDLE_SPINUNLOCK(hObject);
+
+    return rv;
+}
+
+BOOL apxHandlePostMessage(APXHANDLE hObject, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    if (hObject->dwType == APXHANDLE_TYPE_INVALID)
+        return FALSE;
+    if (hObject->dwFlags & APXHANDLE_HAS_EVENT) {
+        /* TODO: Create a thread message queue 
+         * Right now wait while the event gets nonsignaled
+         */
+        while (WaitForSingleObject(hObject->hEventHandle, 0) == WAIT_OBJECT_0)
+            SwitchToThread();
+        APXHANDLE_SPINLOCK(hObject);
+        SuspendThread(hObject->hEventThread);
+        hObject->uMsg   = uMsg;
+        hObject->wParam = wParam;
+        hObject->lParam = lParam;
+        /* Signal the event thread to call the user callback */
+        SetEvent(hObject->hEventHandle);
+        ResumeThread(hObject->hEventThread);
+        APXHANDLE_SPINUNLOCK(hObject);
+
+        return TRUE;
+    }
+    return FALSE;
+}
+
+BOOL apxHandleLock(APXHANDLE hObject, BOOL bLock)
+{
+    if (bLock)
+        APXHANDLE_SPINLOCK(hObject);
+    else
+        APXHANDLE_SPINUNLOCK(hObject);
+
+    return TRUE;
+}
+
+BOOL apxHandleAddHook(APXHANDLE hObject, DWORD dwWhere,
+                      LPAPXFNCALLBACK fnCallback)
+{
+    APXCALLHOOK *lpCall;
+
+    if (hObject->dwType == APXHANDLE_TYPE_INVALID || !fnCallback)
+        return FALSE;
+    lpCall = (APXCALLHOOK *)__apxPoolAllocCore(hObject->hPool, 
+                                               sizeof(APXCALLHOOK), 0);
+    if (!lpCall)
+        return FALSE;
+    lpCall->fnCallback = fnCallback;
+    APXHANDLE_SPINLOCK(hObject);
+    if (dwWhere == APXHANDLE_HOOK_FIRST) {
+        TAILQ_INSERT_HEAD(&hObject->lCallbacks, lpCall, queue);
+    }
+    else {
+        TAILQ_INSERT_TAIL(&hObject->lCallbacks, lpCall, queue);
+    }
+    APXHANDLE_SPINUNLOCK(hObject);
+    
+    return TRUE;
+}
+
+DWORD apxHandleWait(APXHANDLE hHandle, DWORD dwMilliseconds, BOOL bKill)
+{
+    if (IS_INVALID_HANDLE(hHandle))
+        return WAIT_ABANDONED;
+    if (hHandle->dwType == APXHANDLE_TYPE_JVM)
+        return apxJavaWait(hHandle, dwMilliseconds, bKill);
+    else if (hHandle->dwType == APXHANDLE_TYPE_PROCESS)
+        return apxProcessWait(hHandle, dwMilliseconds, bKill);
+    else
+        return WAIT_ABANDONED;
+}
+
diff --git a/src/native/nt/procrun/src/javajni.c b/src/native/nt/procrun/src/javajni.c
new file mode 100644
index 0000000..0d742fd
--- /dev/null
+++ b/src/native/nt/procrun/src/javajni.c
@@ -0,0 +1,807 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+#include <jni.h>
+
+#ifndef JNI_VERSION_1_2
+#error -------------------------------------------------------
+#error JAVA 1.1 IS NO LONGER SUPPORTED 
+#error -------------------------------------------------------
+#endif
+
+#ifdef JNI_VERSION_1_4
+#define JNI_VERSION_DEFAULT JNI_VERSION_1_4
+#else
+#define JNI_VERSION_DEFAULT JNI_VERSION_1_2
+#endif
+
+/* Standard jvm.dll prototypes 
+ * since only single jvm can exist per process
+ * make those global
+ */
+
+DYNOLAD_TYPE_DECLARE(JNI_GetDefaultJavaVMInitArgs, JNICALL, jint)(void *);
+static DYNLOAD_FPTR_DECLARE(JNI_GetDefaultJavaVMInitArgs) = NULL;
+
+DYNOLAD_TYPE_DECLARE(JNI_CreateJavaVM, JNICALL, jint)(JavaVM **, void **, void *);
+static DYNLOAD_FPTR_DECLARE(JNI_CreateJavaVM) = NULL;
+
+DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, jsize *);
+static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
+
+static HANDLE _st_sys_jvmDllHandle = NULL;
+
+#define JVM_DELETE_CLAZZ(jvm, cl)                                               \
+    APXMACRO_BEGIN                                                              \
+    if ((jvm)->lpEnv && (jvm)->##cl.jClazz) {                                   \
+        (*((jvm)->lpEnv))->DeleteGlobalRef((jvm)->lpEnv, (jvm)->##cl.jClazz);   \
+        (jvm)->##cl.jClazz = NULL;                                              \
+    } APXMACRO_END
+
+#define JVM_EXCEPTION_CHECK(jvm) \
+    ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv) != JNI_OK)
+
+#ifdef _DEBUG
+#define JVM_EXCEPTION_CLEAR(jvm) \
+    APXMACRO_BEGIN                                              \
+    if ((jvm)->lpEnv) {                                         \
+        if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) {  \
+            (*((jvm)->lpEnv))->ExceptionDescribe((jvm)->lpEnv); \
+            (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv);    \
+        }                                                       \
+    } APXMACRO_END
+#else
+#define JVM_EXCEPTION_CLEAR(jvm) \
+    APXMACRO_BEGIN                                              \
+    if ((jvm)->lpEnv) {                                         \
+        if ((*((jvm)->lpEnv))->ExceptionCheck((jvm)->lpEnv)) {  \
+            (*((jvm)->lpEnv))->ExceptionClear((jvm)->lpEnv);    \
+        }                                                       \
+    } APXMACRO_END
+#endif
+
+#define JNI_LOCAL_UNREF(obj) \
+        (*(lpJava->lpEnv))->DeleteLocalRef(lpJava->lpEnv, obj)    
+
+#define JNICALL_0(fName)  \
+        ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv))
+
+#define JNICALL_1(fName, a1)  \
+        ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1)))
+
+#define JNICALL_2(fName, a1, a2)  \
+        ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2)))
+
+#define JNICALL_3(fName, a1, a2, a3)  \
+        ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3)))
+
+#define JNICALL_4(fName, a1, a2, a3, a4)  \
+        ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
+
+typedef struct APXJAVASTDCLAZZ {
+    jclass      jClazz;
+    jmethodID   jMethod;
+    jobject     jObject;
+    jarray      jArgs;
+} APXJAVASTDCLAZZ, *LPAPXJAVASTDCLAZZ;
+ 
+typedef struct APXJAVAVM {
+    DWORD           dwOptions;
+    APXJAVASTDCLAZZ clString;
+    APXJAVASTDCLAZZ clWorker;
+    jint            iVersion; 
+    jsize           iVmCount;
+    JNIEnv          *lpEnv; 
+    JavaVM          *lpJvm; 
+    /* JVM worker thread info */
+    HANDLE          hWorkerThread;
+    DWORD           iWorkerThread;
+    DWORD           dwWorkerStatus;
+
+} APXJAVAVM, *LPAPXJAVAVM;
+
+#define JAVA_CLASSPATH      "-Djava.class.path="
+#define JAVA_CLASSSTRING    "java/lang/String"
+
+static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
+{
+    jint _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
+                                          (void **)&(lpJava->lpEnv),                                            
+                                          lpJava->iVersion);
+    if (_iStatus != JNI_OK) {
+        if (_iStatus == JNI_EDETACHED)
+            _iStatus = (*(lpJava->lpJvm))->AttachCurrentThread(lpJava->lpJvm,
+                                                (void **)&(lpJava->lpEnv), NULL);
+    }
+    if (_iStatus != JNI_OK) {
+        lpJava->lpEnv = NULL;
+        return FALSE;
+    }
+    else
+        return TRUE;
+}
+
+static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
+{
+    jint _iStatus = (*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm);
+    if (_iStatus != JNI_OK) {
+        lpJava->lpEnv = NULL;
+        return FALSE;
+    }
+    else
+        return TRUE;
+}
+
+static BOOL __apxLoadJvmDll(LPCWSTR szJvmDllPath)
+{
+    UINT errMode; 
+    LPWSTR dllJvmPath = (LPWSTR)szJvmDllPath;
+
+    if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+        return TRUE;    /* jvm.dll is already loaded */
+
+    if (!dllJvmPath || *dllJvmPath == L'\0')
+        dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
+    if (!dllJvmPath)
+        return FALSE;    
+    /* Suppress the not found system popup message */
+    errMode = SetErrorMode(SEM_FAILCRITICALERRORS); 
+    
+    _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);  
+    /* This shuldn't happen, but try to search in %PATH% */
+    if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+        _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
+                                              LOAD_WITH_ALTERED_SEARCH_PATH);  
+    /* Restore the error mode signalization */
+    SetErrorMode(errMode); 
+    if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return FALSE;
+    }
+    DYNLOAD_FPTR_LOAD(JNI_GetDefaultJavaVMInitArgs, _st_sys_jvmDllHandle);        
+    DYNLOAD_FPTR_LOAD(JNI_CreateJavaVM,             _st_sys_jvmDllHandle);        
+    DYNLOAD_FPTR_LOAD(JNI_GetCreatedJavaVMs,        _st_sys_jvmDllHandle);
+    
+    if (!DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs) ||
+        !DYNLOAD_FPTR(JNI_CreateJavaVM) ||
+        !DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        FreeLibrary(_st_sys_jvmDllHandle);
+        _st_sys_jvmDllHandle = NULL;
+        return FALSE;
+    }
+
+    /* Real voodo ... */
+    return TRUE;
+}
+
+static BOOL __apxJavaJniCallback(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam)
+{
+    LPAPXJAVAVM lpJava;
+    DWORD       dwJvmRet = 0;
+
+    lpJava = APXHANDLE_DATA(hObject);
+    switch (uMsg) {
+        case WM_CLOSE:
+            if (lpJava->lpJvm) {
+                if (!IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
+                    if (GetExitCodeThread(lpJava->hWorkerThread, &dwJvmRet) && 
+                        dwJvmRet == STILL_ACTIVE) {
+                        TerminateThread(lpJava->hWorkerThread, 5);
+                    }
+                }
+                SAFE_CLOSE_HANDLE(lpJava->hWorkerThread);
+                __apxJvmAttach(lpJava);
+                JVM_DELETE_CLAZZ(lpJava, clWorker);
+                JVM_DELETE_CLAZZ(lpJava, clString);
+                __apxJvmDetach(lpJava);
+                /* Check if this is the jvm loader */
+                if (!lpJava->iVmCount && _st_sys_jvmDllHandle) {
+#if 0
+                    /* Do not destroy if we terminated the worker thread */
+                    if (dwJvmRet != STILL_ACTIVE)
+                        (*(lpJava->lpJvm))->DestroyJavaVM(lpJava->lpJvm); 
+#endif
+                    /* Unload JVM dll */
+                    FreeLibrary(_st_sys_jvmDllHandle);
+                    _st_sys_jvmDllHandle = NULL;
+                }
+                lpJava->lpJvm = NULL;
+            }
+        break;
+        default:
+        break;
+    }
+    return TRUE;
+}
+
+APXHANDLE
+apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath)
+{
+
+    APXHANDLE    hJava;
+    LPAPXJAVAVM  lpJava;
+    jsize        iVmCount;
+    JavaVM       *lpJvm = NULL; 
+
+    if (!__apxLoadJvmDll(szJvmDllPath))
+        return NULL;    
+    /*
+     */
+    if (DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)(&lpJvm, 1, &iVmCount) != JNI_OK) {
+        return NULL;
+    } 
+    if (iVmCount && !lpJvm)
+        return NULL;
+
+    hJava = apxHandleCreate(hPool, 0,
+                            NULL, sizeof(APXJAVAVM),
+                            __apxJavaJniCallback);
+    if (IS_INVALID_HANDLE(hJava))
+        return NULL;
+    hJava->dwType = APXHANDLE_TYPE_JVM;
+    lpJava = APXHANDLE_DATA(hJava);
+    lpJava->lpJvm = lpJvm;
+    lpJava->iVmCount = iVmCount;
+    return hJava;
+}
+
+static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
+                                      LPCSTR lpString,
+                                      JavaVMOption **lppArray,
+                                      DWORD  nExtra)
+{
+    DWORD i, n = 0, l = 0;
+    char *buff;
+    LPSTR p;
+    
+    if (lpString) {
+        l = __apxGetMultiSzLengthA(lpString, &n);
+    }
+    n += nExtra;
+    if (IS_INVALID_HANDLE(hPool))
+        buff = apxPoolAlloc(hPool, (n + 1) * sizeof(JavaVMOption) + (l + 1));
+    else
+        buff = apxAlloc((n + 1) * sizeof(JavaVMOption) + (l + 1));
+
+    *lppArray = (JavaVMOption *)buff;
+    p = (LPSTR)(buff + (n + 1) * sizeof(JavaVMOption));
+    if (lpString)
+        AplCopyMemory(p, lpString, l + 1);
+    for (i = 0; i < (n - nExtra); i++) {
+        DWORD qr = apxStrUnQuoteInplaceA(p);
+        (*lppArray)[i].optionString = p;
+        while (*p)
+            p++;
+        p++;
+        p += qr;
+    }
+    
+    return n;
+}
+
+/* a hook for a function that redirects all VM messages. */
+static jint JNICALL __apxJniVfprintf(FILE *fp, const char *format, va_list args)
+{
+    jint rv;
+    CHAR sBuf[1024+16];
+    rv = wvsprintfA(sBuf, format, args);
+    apxLogWrite(APXLOG_MARK_INFO "%s", sBuf);
+    return rv;
+}
+ 
+
+/* ANSI version only */
+BOOL
+apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
+                  LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
+                  DWORD dwSs, BOOL bReduceSignals)
+{
+    LPAPXJAVAVM     lpJava;
+    JDK1_1InitArgs  vmArgs11;
+    JavaVMInitArgs  vmArgs; 
+    JavaVMOption    *lpJvmOptions;
+    DWORD           i, nOptions, sOptions = 2;
+    BOOL            rv = FALSE;
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return FALSE;
+
+    lpJava = APXHANDLE_DATA(hJava);
+    
+    if (lpJava->iVmCount) {
+        if (!lpJava->lpEnv && !__apxJvmAttach(lpJava)) {
+            if (lpJava->iVersion == JNI_VERSION_1_2) {
+                apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
+                return FALSE;
+            }
+            else
+                lpJava->iVersion = JNI_VERSION_1_2;
+            if (!__apxJvmAttach(lpJava)) {
+                apxLogWrite(APXLOG_MARK_ERROR "Unable To Attach the JVM");
+                return FALSE; 
+            }
+        }
+        lpJava->iVersion = JNICALL_0(GetVersion);
+        if (lpJava->iVersion < JNI_VERSION_1_2) {
+            apxLogWrite(APXLOG_MARK_ERROR "Unsuported JNI version %d", lpJava->iVersion);
+            return FALSE;
+        }
+        rv = TRUE;
+    }
+    else {
+        CHAR  iB[3][64];
+        LPSTR szCp;
+        vmArgs11.version = JNI_VERSION_DEFAULT;
+        if (DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs)(&vmArgs11) != JNI_OK) {
+            /* fall back to version 1.2 */
+            if (JNI_VERSION_DEFAULT != JNI_VERSION_1_2) {
+                vmArgs11.version = JNI_VERSION_1_2;
+                if (DYNLOAD_FPTR(JNI_GetDefaultJavaVMInitArgs)(&vmArgs11) != JNI_OK)
+                    return FALSE;
+            }
+            else
+                return FALSE;
+        }
+        /* we need at least 1.2 JNI */
+        if ((lpJava->iVersion = vmArgs11.version) < JNI_VERSION_1_2) {
+            apxLogWrite(APXLOG_MARK_ERROR "Unsuported JNI version %d", vmArgs11.version);
+            return FALSE; 
+        }
+        if (dwMs)
+            ++sOptions;
+        if (dwMx)
+            ++sOptions;
+        if (dwSs)
+            ++sOptions;
+        if (bReduceSignals)
+            ++sOptions;
+        nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
+                                            &lpJvmOptions, sOptions);
+        szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
+        lstrcpyA(szCp, JAVA_CLASSPATH);
+        lstrcatA(szCp, szClassPath);
+        if (bReduceSignals) {
+            /* reduce signals to skip registering console
+             * control handler
+             */
+            lpJvmOptions[nOptions - sOptions].optionString = "-Xrs";
+            --sOptions;
+        }
+        lpJvmOptions[nOptions - sOptions].optionString = szCp;
+        --sOptions;
+        /* default JNI error printer */
+        lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
+        lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniVfprintf;
+        --sOptions;
+        if (dwMs) {
+            wsprintfA(iB[0], "-Xms%dm", dwMs);
+            lpJvmOptions[nOptions - sOptions].optionString = iB[0];
+            --sOptions;
+        }
+        if (dwMx) {
+            wsprintfA(iB[1], "-Xmx%dm", dwMx);
+            lpJvmOptions[nOptions - sOptions].optionString = iB[1];
+            --sOptions;
+        }
+        if (dwSs) {
+            wsprintfA(iB[2], "-Xss%dk", dwSs);
+            lpJvmOptions[nOptions - sOptions].optionString = iB[2];
+            --sOptions;
+        }
+        for (i = 0; i < nOptions; i++) {
+            apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", i,
+                        lpJvmOptions[i].optionString);
+        }
+        vmArgs.options  = lpJvmOptions;
+        vmArgs.nOptions = nOptions;
+        vmArgs.version  = lpJava->iVersion;
+        vmArgs.ignoreUnrecognized = JNI_FALSE;
+        if (DYNLOAD_FPTR(JNI_CreateJavaVM)(&(lpJava->lpJvm),
+                                           (void **)&(lpJava->lpEnv),
+                                           &vmArgs) != JNI_OK) {
+            apxLogWrite(APXLOG_MARK_ERROR "CreateJavaVM Failed");
+            rv = FALSE; 
+        }
+        else
+            rv = TRUE;
+        apxFree(szCp);
+        apxFree(lpJvmOptions);
+    }    
+    /* Load standard classes */
+    if (rv) {
+        jclass jClazz = JNICALL_1(FindClass, JAVA_CLASSSTRING);
+        if (!jClazz) {
+            apxLogWrite(APXLOG_MARK_ERROR "FindClass "  JAVA_CLASSSTRING " failed");
+            goto cleanup; 
+        }
+        lpJava->clString.jClazz = JNICALL_1(NewGlobalRef, jClazz);
+        JNI_LOCAL_UNREF(jClazz);
+
+        return TRUE;
+    }
+    else
+        return FALSE;
+
+cleanup:
+    JVM_EXCEPTION_CLEAR(lpJava);
+    return FALSE;
+}
+
+BOOL
+apxJavaLoadMainClass(APXHANDLE hJava, LPCSTR szClassName,
+                     LPCSTR szMethodName,
+                     LPCVOID lpArguments)
+{
+    LPSTR       *lpArgs = NULL;
+    DWORD       nArgs;
+    LPAPXJAVAVM lpJava;
+    jclass      jClazz;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return FALSE;
+    lpJava = APXHANDLE_DATA(hJava);
+    if (!__apxJvmAttach(lpJava))
+        return FALSE;
+    
+    /* Find the class */
+    jClazz  = JNICALL_1(FindClass, szClassName);
+    if (!jClazz) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "FindClass %s failed", szClassName);
+        return FALSE; 
+    }
+    /* Make the class global so that worker thread can attach */
+    lpJava->clWorker.jClazz  = JNICALL_1(NewGlobalRef, jClazz);
+    JNI_LOCAL_UNREF(jClazz);
+
+    if (szMethodName)
+        lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+                                             lpJava->clWorker.jClazz,
+                                             szMethodName, "([Ljava/lang/String;)V"); 
+    else
+        lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+                                             lpJava->clWorker.jClazz,
+                                             "main", "([Ljava/lang/String;)V"); 
+    if (!lpJava->clWorker.jMethod) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Static method 'void main(String[])' in Class %s not found", szClassName);
+        return FALSE;
+    }
+    nArgs = apxMultiSzToArrayA(hJava->hPool, lpArguments, &lpArgs);
+    if (nArgs) {
+        DWORD i;
+        lpJava->clWorker.jArgs = JNICALL_3(NewObjectArray, nArgs,
+                                           lpJava->clString.jClazz, NULL);
+        for (i = 0; i < nArgs; i++) {
+            jstring arg = JNICALL_1(NewStringUTF, lpArgs[i]);
+            JNICALL_3(SetObjectArrayElement, lpJava->clWorker.jArgs, i, arg);
+            apxLogWrite(APXLOG_MARK_DEBUG "argv[%d] = %s", i, lpArgs[i]);
+        }
+    }
+    apxFree(lpArgs);
+    return TRUE;
+}
+
+
+/* Main java application worker thread 
+ * It will launch Java main and wait until
+ * it finishes.
+ */
+static DWORD WINAPI __apxJavaWorkerThread(LPVOID lpParameter)
+{
+#define WORKER_EXIT(x)  { rv = x; goto finished; }
+    DWORD rv = 0;
+    LPAPXJAVAVM lpJava;
+    APXHANDLE   hJava = (APXHANDLE)lpParameter;
+    /* This shouldn't happen */
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        WORKER_EXIT(0);
+    lpJava = APXHANDLE_DATA(hJava);
+    /* Check if we have a class and a method */
+    if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod)
+        WORKER_EXIT(2);
+    if (!__apxJvmAttach(lpJava))
+        WORKER_EXIT(3);
+    lpJava->dwWorkerStatus = 1;
+    JNICALL_3(CallStaticVoidMethod,
+              lpJava->clWorker.jClazz,
+              lpJava->clWorker.jMethod,
+              lpJava->clWorker.jArgs);
+
+    JVM_EXCEPTION_CLEAR(lpJava);
+    __apxJvmDetach(lpJava);
+finished:
+    lpJava->dwWorkerStatus = 0;
+    apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished");
+    ExitThread(rv);
+    /* never gets here but keep the compiler happy */
+    return 0;
+}
+
+
+BOOL
+apxJavaStart(APXHANDLE hJava)
+{
+
+    LPAPXJAVAVM lpJava;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return FALSE;
+    lpJava = APXHANDLE_DATA(hJava);
+    
+    lpJava->hWorkerThread = CreateThread(NULL, 0, __apxJavaWorkerThread,
+                                         hJava, CREATE_SUSPENDED,
+                                         &lpJava->iWorkerThread);     
+    if (IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return FALSE;
+    }
+    ResumeThread(lpJava->hWorkerThread);
+    /* Give some time to initialize the thread */
+    Sleep(1000);
+    return TRUE;
+}
+
+DWORD
+apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
+{
+    DWORD rv;
+    LPAPXJAVAVM lpJava;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return FALSE;
+    lpJava = APXHANDLE_DATA(hJava);
+    
+    if (!lpJava->dwWorkerStatus && lpJava->hWorkerThread)
+        return WAIT_OBJECT_0;
+    rv = WaitForSingleObject(lpJava->hWorkerThread, dwMilliseconds);
+    if (rv == WAIT_TIMEOUT && bKill) {
+        __apxJavaJniCallback(hJava, WM_CLOSE, 0, 0);
+    }
+    
+    return rv;
+}
+
+LPVOID
+apxJavaCreateClassV(APXHANDLE hJava, LPCSTR szClassName,
+                    LPCSTR szSignature, va_list lpArgs)
+{
+    LPAPXJAVAVM     lpJava;
+    jclass          clazz;
+    jmethodID       ccont;
+    jobject         cinst;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return NULL;
+    lpJava = APXHANDLE_DATA(hJava);
+    if (!__apxJvmAttach(lpJava))
+        return NULL;
+    
+    clazz = JNICALL_1(FindClass, szClassName);
+    if (clazz == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass %s", szClassName);
+        return NULL;
+    }
+    
+    ccont = JNICALL_3(GetMethodID, clazz, "<init>", szSignature);
+    if (ccont == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not find Constructor %s for %s",
+                    szSignature, szClassName);
+        return NULL;
+    }
+
+    cinst = JNICALL_3(NewObjectV, clazz, ccont, lpArgs);
+    if (cinst == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not create instance of %s",
+                    szClassName);
+        return NULL;
+    }
+
+    return cinst;
+}
+
+LPVOID
+apxJavaCreateClass(APXHANDLE hJava, LPCSTR szClassName,
+                   LPCSTR szSignature, ...)
+{
+    LPVOID rv;
+    va_list args;
+    
+    va_start(args, szSignature);
+    rv = apxJavaCreateClassV(hJava, szClassName, szSignature, args);
+    va_end(args);
+
+    return rv;
+}
+
+LPVOID
+apxJavaCreateStringA(APXHANDLE hJava, LPCSTR szString)
+{
+    LPAPXJAVAVM     lpJava;
+    jstring str;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return NULL;
+    lpJava = APXHANDLE_DATA(hJava);
+    
+    str = JNICALL_1(NewStringUTF, szString);
+    if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %s",
+                    szString);
+        return NULL;
+    }
+
+    return str;
+}
+
+LPVOID
+apxJavaCreateStringW(APXHANDLE hJava, LPCWSTR szString)
+{
+    LPAPXJAVAVM     lpJava;
+    jstring str;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return NULL;
+    lpJava = APXHANDLE_DATA(hJava);
+    
+    str = JNICALL_2(NewString, szString, lstrlenW(szString));
+    if (str == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not create string for %S",
+                    szString);
+        return NULL;
+    }
+
+    return str;
+}
+
+jvalue
+apxJavaCallStaticMethodV(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
+                         LPCSTR szSignature, va_list lpArgs)
+{
+    LPAPXJAVAVM     lpJava;
+    jmethodID       method;
+    jvalue          rv;
+    LPCSTR          s = szSignature;
+    rv.l = 0;
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return rv;
+    lpJava = APXHANDLE_DATA(hJava);
+    
+    while (*s && *s != ')')
+        ++s;
+    if (*s != ')') {
+        return rv;
+    }
+    else
+        ++s;
+    method = JNICALL_3(GetStaticMethodID, lpClass, szMethodName, szSignature);
+    if (method == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not find method %s with signature %s",
+                    szMethodName, szSignature);
+        return rv;
+    }
+    switch (*s) {
+        case 'V':
+            JNICALL_3(CallStaticVoidMethodV, lpClass, method, lpArgs);
+        break;
+        case 'L':
+        case '[':
+            rv.l = JNICALL_3(CallStaticObjectMethodV, lpClass, method, lpArgs);
+        break;
+        case 'Z':
+            rv.z = JNICALL_3(CallStaticBooleanMethodV, lpClass, method, lpArgs);
+        break;
+        case 'B':
+            rv.b = JNICALL_3(CallStaticByteMethodV, lpClass, method, lpArgs);
+        break;
+        case 'C':
+            rv.c = JNICALL_3(CallStaticCharMethodV, lpClass, method, lpArgs);
+        break;
+        case 'S':
+            rv.i = JNICALL_3(CallStaticShortMethodV, lpClass, method, lpArgs);
+        break;
+        case 'I':
+            rv.i = JNICALL_3(CallStaticIntMethodV, lpClass, method, lpArgs);
+        break;
+        case 'J':
+            rv.j = JNICALL_3(CallStaticLongMethodV, lpClass, method, lpArgs);
+        break;
+        case 'F':
+            rv.f = JNICALL_3(CallStaticFloatMethodV, lpClass, method, lpArgs);
+        break;
+        case 'D':
+            rv.d = JNICALL_3(CallStaticDoubleMethodV, lpClass, method, lpArgs);
+        break;        
+        default:
+            apxLogWrite(APXLOG_MARK_ERROR "Invalid signature %s for method %s",
+                        szSignature, szMethodName);
+            return rv;
+        break;
+    }
+
+    return rv;
+}
+
+jvalue
+apxJavaCallStaticMethod(APXHANDLE hJava, jclass lpClass, LPCSTR szMethodName,
+                        LPCSTR szSignature, ...)
+{
+    jvalue rv;
+    va_list args;
+    
+    va_start(args, szSignature);
+    rv = apxJavaCallStaticMethodV(hJava, lpClass, szMethodName, szSignature, args);
+    va_end(args);
+
+    return rv;
+}
+
+/* Call the Java:
+ * System.setOut(new PrintStream(new FileOutputStream(filename))); 
+ */
+BOOL
+apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut, LPCWSTR szFilename)
+{
+    LPAPXJAVAVM lpJava;
+    jobject     fs;
+    jobject     ps;
+    jstring     fn;
+    jclass      sys;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM || !szFilename)
+        return FALSE;
+    lpJava = APXHANDLE_DATA(hJava);
+    if (!__apxJvmAttach(lpJava))
+        return FALSE;
+
+    if ((fn = apxJavaCreateStringW(hJava, szFilename)) == NULL)
+        return FALSE;
+    if ((fs = apxJavaCreateClass(hJava, "java/io/FileOutputStream",
+                                 "(Ljava/lang/String;Z)V", fn, JNI_TRUE)) == NULL)
+        return FALSE;
+    if ((ps = apxJavaCreateClass(hJava, "java/io/PrintStream",
+                                 "(Ljava/io/OutputStream;)V", fs)) == NULL)
+        return FALSE;
+    sys = JNICALL_1(FindClass, "java/lang/System");
+    if (sys == NULL || (JVM_EXCEPTION_CHECK(lpJava))) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Could not FindClass java/lang/System");
+        return FALSE;
+    }
+
+    if (setErrorOrOut)
+        apxJavaCallStaticMethod(hJava, sys, "setErr", "(Ljava/io/PrintStream;)V", ps);
+    else
+        apxJavaCallStaticMethod(hJava, sys, "setOut", "(Ljava/io/PrintStream;)V", ps);
+
+    if (JVM_EXCEPTION_CHECK(lpJava)) {
+        JVM_EXCEPTION_CLEAR(lpJava);
+        apxLogWrite(APXLOG_MARK_ERROR "Error calling set method for java/lang/System");
+        return FALSE;
+    }
+    else
+        return TRUE;
+
+}
diff --git a/src/native/nt/procrun/src/log.c b/src/native/nt/procrun/src/log.c
new file mode 100644
index 0000000..3b100c4
--- /dev/null
+++ b/src/native/nt/procrun/src/log.c
@@ -0,0 +1,409 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */ 
+
+#include "apxwin.h"
+#include "private.h"
+
+#define LINE_SEP    "\n"
+
+static LPCSTR _log_level[] = {
+    "[debug] ",
+    "[info] ",
+    "[warn] ",
+    "[error] ",
+    NULL
+};
+
+typedef struct apx_logfile_st {
+    HANDLE      hFile;
+    DWORD       dwLogLevel;
+    BOOL        bRotate;
+    SYSTEMTIME  sysTime;
+    WCHAR       szPath[MAX_PATH + 1];
+    WCHAR       szPrefix[MAX_PATH];
+} apx_logfile_st;
+
+/* Per-application master log file */
+static apx_logfile_st *_st_sys_loghandle = NULL;
+
+static apx_logfile_st  _st_sys_errhandle = { NULL, APXLOG_LEVEL_WARN, FALSE};
+
+
+LPWSTR apxLogFile(
+    APXHANDLE hPool,
+    LPCWSTR szPath,
+    LPCWSTR szPrefix,
+    LPCWSTR szName)
+{
+    LPWSTR sRet;
+    WCHAR sPath[MAX_PATH+1];
+    WCHAR sName[MAX_PATH+1];
+    SYSTEMTIME sysTime;
+
+    GetLocalTime(&sysTime);
+    if (!szPath) {
+        if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
+            return INVALID_HANDLE_VALUE;
+        lstrcatW(sPath, L"\\LogFiles\\");
+        if (!szPrefix)
+            lstrcatW(sPath, L"Apache");
+        else
+            lstrcatW(sPath, szPrefix);
+        wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+                  szName,
+                  sysTime.wYear,
+                  sysTime.wMonth,
+                  sysTime.wDay);
+    }
+    else {
+        lstrcpyW(sPath, szPath);
+        if (szPrefix)
+            wsprintfW(sName, L"\\%s", szPrefix);
+        else
+            wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+                      szName,
+                      sysTime.wYear,
+                      sysTime.wMonth,
+                      sysTime.wDay);
+    }
+    sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
+    /* Set default level to info */
+    CreateDirectoryW(sPath, NULL);
+    
+    lstrcpyW(sRet, sPath);
+    lstrcatW(sRet, sName);
+
+    return sRet;
+}
+
+/* Open the log file 
+ * TODO: format like standard apache error.log
+ * Add the EventLogger
+ */
+HANDLE apxLogOpen(
+    APXHANDLE hPool,
+    LPCWSTR szPath,
+    LPCWSTR szPrefix)
+{
+
+    WCHAR sPath[MAX_PATH+1];
+    WCHAR sName[MAX_PATH+1];
+    SYSTEMTIME sysTime;
+    apx_logfile_st *h;
+
+    GetLocalTime(&sysTime);
+    if (!szPath) {
+        if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
+            return INVALID_HANDLE_VALUE;
+        lstrcatW(sPath, L"\\LogFiles\\");
+        if (!szPrefix)
+            lstrcatW(sPath, L"Apache");
+        else
+            lstrcatW(sPath, szPrefix);
+        wsprintfW(sName, L"\\%04d%02d%02d.log",
+                  sysTime.wYear,
+                  sysTime.wMonth,
+                  sysTime.wDay);
+    }
+    else {
+        lstrcpyW(sPath, szPath);
+        if (szPrefix)
+            wsprintfW(sName, L"\\%s", szPrefix);
+        else
+            wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log",
+                      sysTime.wYear,
+                      sysTime.wMonth,
+                      sysTime.wDay);
+    }
+    if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
+        return NULL;
+    /* Set default level to info */
+    h->dwLogLevel = APXLOG_LEVEL_INFO;
+    CreateDirectoryW(sPath, NULL);
+    
+    h->sysTime = sysTime;
+    lstrcpyW(h->szPath, sPath);
+    lstrcatW(sPath, sName);
+    if (szPrefix)
+        lstrcpyW(h->szPrefix, szPrefix);
+
+    h->hFile =  CreateFileW(sPath,
+                      GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+                      NULL,
+                      OPEN_ALWAYS,
+                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+                      NULL);
+    /* Set this file as system log file */
+    if (!_st_sys_loghandle)
+        _st_sys_loghandle = h;
+
+    return (HANDLE)h;
+}
+
+void apxLogLevelSet(HANDLE hFile, DWORD dwLevel)
+{
+    apx_logfile_st *lf = (apx_logfile_st *)hFile;
+    if (IS_INVALID_HANDLE(lf))
+        lf = _st_sys_loghandle;
+    if (IS_INVALID_HANDLE(lf))
+        return;
+    if (dwLevel < 4)
+        lf->dwLogLevel = dwLevel;
+}
+
+void apxLogRotateSet(HANDLE hFile, BOOL doRotate)
+{
+    apx_logfile_st *lf = (apx_logfile_st *)hFile;
+    if (IS_INVALID_HANDLE(lf))
+        lf = _st_sys_loghandle;
+    if (IS_INVALID_HANDLE(lf))
+        return;
+    lf->bRotate = doRotate;
+}
+
+void apxLogLevelSetW(HANDLE  hFile,
+                     LPCWSTR szLevel)
+{
+    apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+    if (IS_INVALID_HANDLE(lf))
+        lf = _st_sys_loghandle;
+    if (IS_INVALID_HANDLE(lf))
+        return;
+    if (szLevel) {
+        if (!lstrcmpiW(szLevel, L"error"))
+            lf->dwLogLevel = APXLOG_LEVEL_ERROR;
+        else if (!lstrcmpiW(szLevel, L"warn"))
+            lf->dwLogLevel = APXLOG_LEVEL_WARN;
+        else if (!lstrcmpiW(szLevel, L"info"))
+            lf->dwLogLevel = APXLOG_LEVEL_INFO;
+        else if (!lstrcmpiW(szLevel, L"debug"))
+            lf->dwLogLevel = APXLOG_LEVEL_DEBUG;
+    }
+}
+
+static BOOL apx_log_rotate(apx_logfile_st *l,
+                           LPSYSTEMTIME lpCtime)
+{
+    WCHAR sPath[MAX_PATH+1];
+    
+    /* rotate on daily basis */
+    if (l->sysTime.wDay == lpCtime->wDay)
+        return TRUE;
+    FlushFileBuffers(l->hFile);
+    CloseHandle(l->hFile);    
+    l->sysTime = *lpCtime;
+
+    wsprintfW(sPath, L"%s\\%s%04d%02d%02d.log",
+              l->szPath,
+              l->szPrefix,
+              l->sysTime.wYear,
+              l->sysTime.wMonth,
+              l->sysTime.wDay);
+    l->hFile =  CreateFileW(sPath,
+                      GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+                      NULL,
+                      OPEN_ALWAYS,
+                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+                      NULL);
+    if (IS_INVALID_HANDLE(l->hFile))
+        return FALSE;
+    else
+        return TRUE;
+}
+
+int
+apxLogWrite(
+    HANDLE  hFile,
+    DWORD   dwLevel,
+    BOOL    bTimeStamp,
+    LPCSTR  szFile,
+    DWORD   dwLine,
+    LPCSTR  szFormat,
+    ...)
+{
+    va_list args;
+    CHAR    buffer[1024+32];
+    LPSTR   szBp;
+    int     len = 0;
+    LPCSTR  f = szFile;
+    CHAR    sb[MAX_PATH+1];
+    DWORD   wr;
+    DWORD   err;
+    BOOL    dolock = TRUE;
+    apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+    if (IS_INVALID_HANDLE(lf))
+        lf = _st_sys_loghandle;
+    if (IS_INVALID_HANDLE(lf)) {
+        lf = &_st_sys_errhandle;
+        lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
+        dolock = FALSE;
+    }
+    if (dwLevel < lf->dwLogLevel)
+        return 0;
+    err = GetLastError(); /* save the last Error code */
+    if (f) {
+        f = (szFile + lstrlenA(szFile) - 1);    
+        while(f != szFile && '\\' != *f && '/' != *f)
+            f--;
+        if(f != szFile)
+            f++;
+    }
+    lstrcpyA(buffer, _log_level[dwLevel]);
+    if (!dolock)
+        lstrcatA(buffer, "\n");
+    szBp = &buffer[lstrlenA(buffer)];
+    if (!szFormat) {
+        FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
+                       FORMAT_MESSAGE_IGNORE_INSERTS,
+                       NULL,
+                       err,
+                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                       szBp,
+                       1000,
+                       NULL);
+    }
+    else {
+        va_start(args, szFormat);
+        wvsprintfA(szBp, szFormat, args);
+        va_end(args);
+    }
+    len = lstrlenA(buffer);
+    if (len > 0) {
+        /* Remove trailing line separator */
+        if (buffer[len - 1] == '\n') {
+            buffer[len - 1] = '\0';
+            --len;
+        }
+        if (!IS_INVALID_HANDLE(lf->hFile)) {
+            SYSTEMTIME t;
+            GetLocalTime(&t);
+            if (lf->bRotate) {
+                if (!apx_log_rotate(lf, &t))
+                    return 0;
+            }
+            if (dolock) {
+                APX_LOGLOCK(lf->hFile);
+            }
+            if (bTimeStamp) {
+                wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ", 
+                          t.wYear, t.wMonth, t.wDay,
+                          t.wHour, t.wMinute, t.wSecond);
+                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+            }
+            if (f) {
+                wsprintfA(sb, "[%-4d %s] ", dwLine, f);
+                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+            }
+
+            WriteFile(lf->hFile, buffer, len, &wr, NULL);
+            /* Terminate the line */            
+            WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
+#ifdef _DEBUG_FULL
+            FlushFileBuffers(lf->hFile);
+#endif
+            if (dolock) {
+                APX_LOGUNLOCK(lf->hFile);
+            }
+        }
+#ifdef _DEBUG_FULL
+        {
+            char tid[1024 + 16];
+            wsprintfA(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
+            OutputDebugStringA(tid);
+        }
+#endif
+    }
+    /* Restore the last Error code */
+    SetLastError(err);
+    return len;
+}
+
+void apxLogClose(
+    HANDLE hFile)
+{
+    apx_logfile_st *lf = (apx_logfile_st *)hFile;
+
+    if (IS_INVALID_HANDLE(lf))
+        lf = _st_sys_loghandle;
+    if (IS_INVALID_HANDLE(lf))
+        return;
+    
+    FlushFileBuffers(lf->hFile);
+    CloseHandle(lf->hFile);
+    if (lf == _st_sys_loghandle)
+        _st_sys_loghandle = NULL;
+    apxFree(lf);
+}
+
+int
+apxDisplayError(
+    BOOL    bDisplay,
+    LPCSTR  szFile,
+    DWORD   dwLine,
+    LPCSTR  szFormat,
+    ...)
+{
+    va_list args;
+    CHAR    buffer[1024+16];
+    CHAR    sysbuf[2048];
+    int     len = 0, nRet;
+    LPCSTR  f = szFile;
+    DWORD   err = GetLastError(); /* save the last Error code */
+    if (f) {
+        f = (szFile + lstrlenA(szFile) - 1);    
+        while(f != szFile && '\\' != *f && '/' != *f)
+            f--;
+        if(f != szFile)
+            f++;
+    }
+    sysbuf[0] = '\0';
+    if (err != ERROR_SUCCESS) {
+        len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
+                             FORMAT_MESSAGE_IGNORE_INSERTS,
+                             NULL,
+                             err,
+                             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                             sysbuf,
+                             1000,
+                             NULL);
+        sysbuf[len] = 0;
+    }
+    if (szFormat) {
+        va_start(args, szFormat);
+        wvsprintfA(buffer, szFormat, args);
+        va_end(args);
+        if (f) {
+            CHAR sb[MAX_PATH+1];
+            wsprintfA(sb, "\n%s (%d)", f, dwLine);
+            lstrcatA(sysbuf, sb);
+        }
+        lstrcatA(sysbuf, "\n");
+        lstrcatA(sysbuf, buffer);
+    }
+    len = lstrlenA(sysbuf);
+#ifdef _DEBUG_FULL
+    OutputDebugStringA(sysbuf);
+#endif
+    if (len > 0 && bDisplay) {
+        nRet = MessageBoxA(NULL, sysbuf, 
+                           "Application System Error",
+                           MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
+    }
+    /* Restore the last Error code */
+    SetLastError(err);
+    return len;
+}
diff --git a/src/native/nt/procrun/src/mclib.c b/src/native/nt/procrun/src/mclib.c
new file mode 100644
index 0000000..e94692f
--- /dev/null
+++ b/src/native/nt/procrun/src/mclib.c
@@ -0,0 +1,285 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+/*
+ * Copyright (c) 1994
+ *  The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Andrew Hume of AT&T Bell Laboratories.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+typedef UINT    word;       /* "word" used for optimal copy speed */
+#define wsize   sizeof(UINT)
+#define wmask   (wsize - 1)
+
+LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill)
+{ 
+
+    SIZE_T t;
+    UINT   c;
+    LPBYTE dst;
+
+    dst = Destination;
+    /*
+     * If not enough words, just fill bytes.  A length >= 2 words
+     * guarantees that at least one of them is `complete' after
+     * any necessary alignment.  For instance:
+     *
+     *  |-----------|-----------|-----------|
+     *  |00|01|02|03|04|05|06|07|08|09|0A|00|
+     *            ^---------------------^
+     *       dst         dst+length-1
+     *
+     * but we use a minimum of 3 here since the overhead of the code
+     * to do word writes is substantial.
+     */
+    if (Length < 3 * wsize) {
+        while (Length != 0) {
+            *dst++ = Fill;
+            --Length;
+        }
+        return (Destination);
+    }
+
+    if ((c = Fill) != 0) {  /* Fill the word. */
+        c = (c << 8) | c;   /* u_int is 16 bits. */
+        c = (c << 16) | c;  /* u_int is 32 bits. */
+#ifdef WIN64
+        c = (c << 32) | c;  /* u_int is 64 bits. */
+#endif
+    }
+    /* Align destination by filling in bytes. */
+    if ((t = (SIZE_T)dst & wmask) != 0) {
+        t = wsize - t;
+        Length -= t;
+        do {
+            *dst++ = Fill;
+        } while (--t != 0);
+    }
+
+    /* Fill words.  Length was >= 2*words so we know t >= 1 here. */
+    t = Length / wsize;
+    do {
+        *(UINT *)dst = c;
+        dst += wsize;
+    } while (--t != 0);
+
+    /* Mop up trailing bytes, if any. */
+    t = Length & wmask;
+    if (t != 0)
+        do {
+            *dst++ = Fill;
+        } while (--t != 0);
+    return (Destination); 
+}
+
+void AplZeroMemory(PVOID Destination, SIZE_T Length)
+{ 
+
+    SIZE_T t;
+    LPBYTE dst;
+
+    dst = Destination;
+    /*
+     * If not enough words, just fill bytes.  A length >= 2 words
+     * guarantees that at least one of them is `complete' after
+     * any necessary alignment.  For instance:
+     *
+     *  |-----------|-----------|-----------|
+     *  |00|01|02|03|04|05|06|07|08|09|0A|00|
+     *            ^---------------------^
+     *       dst         dst+length-1
+     *
+     * but we use a minimum of 3 here since the overhead of the code
+     * to do word writes is substantial.
+     */
+    if (Length < 3 * wsize) {
+        while (Length != 0) {
+            *dst++ = 0;
+            --Length;
+        }
+        return;
+    }
+
+    /* Align destination by filling in bytes. */
+    if ((t = (SIZE_T)dst & wmask) != 0) {
+        t = wsize - t;
+        Length -= t;
+        do {
+            *dst++ = 0;
+        } while (--t != 0);
+    }
+
+    /* Fill words.  Length was >= 2*words so we know t >= 1 here. */
+    t = Length / wsize;
+    do {
+        *(UINT *)dst = 0;
+        dst += wsize;
+    } while (--t != 0);
+
+    /* Mop up trailing bytes, if any. */
+    t = Length & wmask;
+    if (t != 0)
+        do {
+            *dst++ = 0;
+        } while (--t != 0);
+}
+
+LPVOID AplCopyMemory(PVOID Destination, const VOID* Source, SIZE_T Length)
+{
+    char *dst = Destination;
+    const char *src = Source;
+    SIZE_T t;
+
+    if (Length == 0 || dst == src)      /* nothing to do */
+        goto done;
+
+    /*
+     * Macros: loop-t-times; and loop-t-times, t>0
+     */
+#define TLOOP(s) if (t) TLOOP1(s)
+#define TLOOP1(s) do { s; } while (--t)
+
+    if ((SIZE_T)dst < (SIZE_T)src) {
+        /*
+         * Copy forward.
+         */
+        t = (int)(SIZE_T)src;   /* only need low bits */
+        if ((t | (int)(SIZE_T)dst) & wmask) {
+            /*
+             * Try to align operands.  This cannot be done
+             * unless the low bits match.
+             */
+            if ((t ^ (int)(SIZE_T)dst) & wmask || Length < wsize)
+                t = Length;
+            else
+                t = wsize - (t & wmask);
+            Length -= t;
+            TLOOP1(*dst++ = *src++);
+        }
+        /*
+         * Copy whole words, then mop up any trailing bytes.
+         */
+        t = Length / wsize;
+        TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
+        t = Length & wmask;
+        TLOOP(*dst++ = *src++);
+    } else {
+        /*
+         * Copy backwards.  Otherwise essentially the same.
+         * Alignment works as before, except that it takes
+         * (t&wmask) bytes to align, not wsize-(t&wmask).
+         */
+        src += Length;
+        dst += Length;
+        t = (int)(SIZE_T)src;
+        if ((t | (int)(SIZE_T)dst) & wmask) {
+            if ((t ^ (int)(SIZE_T)dst) & wmask || Length <= wsize)
+                t = Length;
+            else
+                t &= wmask;
+            Length -= t;
+            TLOOP1(*--dst = *--src);
+        }
+        t = Length / wsize;
+        TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
+        t = Length & wmask;
+        TLOOP(*--dst = *--src);
+    }
+done:
+    return (Destination);
+} 
+
+
+INT
+AplMemCmp(LPCVOID lpA, LPCVOID lpB, SIZE_T nBytes)
+{
+    if (nBytes != 0) {
+        const BYTE *p1 = lpA, *p2 = lpB;
+
+        do {
+            if (*p1++ != *p2++)
+                return (*--p1 - *--p2);
+        } while (--nBytes != 0);
+    }
+    return 0;
+} 
+
+/*
+ * Find the first occurrence of lpFind in lpMem.
+ * dwLen:   The length of lpFind
+ * dwSize:  The length of lpMem
+ */
+LPBYTE
+ApcMemSearch(LPCVOID lpMem, LPCVOID lpFind, SIZE_T dwLen, SIZE_T dwSize)
+{
+    BYTE   c, sc;
+    SIZE_T cnt = 0;
+    const BYTE *s = lpMem, *find = lpFind;
+
+    if ((c = *find++) != 0) {
+        do {
+            do {
+                sc = *s++;
+                if (cnt++ > dwSize)
+                    return NULL;
+            } while (sc != c);
+        } while (AplMemCmp(s, find, dwLen - 1) != 0);
+        s--;
+    }
+    return (LPBYTE)s;
+} 
+
+LPSTR
+AplRindexA(LPCSTR lpStr, int ch)
+{
+    LPSTR save;
+
+    for (save = NULL;; ++lpStr) {
+        if (*lpStr == ch)
+            save = (LPSTR)lpStr;
+        if (!*lpStr)
+            return save;
+    } 
+    /* NOTREACHED */
+} 
diff --git a/src/native/nt/procrun/src/mclib.h b/src/native/nt/procrun/src/mclib.h
new file mode 100644
index 0000000..33fd310
--- /dev/null
+++ b/src/native/nt/procrun/src/mclib.h
@@ -0,0 +1,26 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+#ifndef _MCLIB_H_INCLUDED_
+#define _MCLIB_H_INCLUDED_
+
+#ifndef  MIN
+#define  MIN(a,b)    (((a)<(b)) ? (a) : (b))
+#endif
+#ifndef  MAX
+#define  MAX(a,b)    (((a)>(b)) ? (a) : (b))
+#endif
+
+#endif /* _MCLIB_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/src/private.h b/src/native/nt/procrun/src/private.h
new file mode 100644
index 0000000..9a9a016
--- /dev/null
+++ b/src/native/nt/procrun/src/private.h
@@ -0,0 +1,273 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#ifndef _PRIVATE_H_INCLUDED_
+#define _PRIVATE_H_INCLUDED_
+
+#include "mclib.h"
+
+#ifdef _DEBUG
+
+HANDLE  HeapCREATE(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
+BOOL    HeapDESTROY(HANDLE hHeap);
+
+LPVOID  HeapALLOC(HANDLE hHeap, DWORD dwFlags, SIZE_T nSize);
+BOOL    HeapFREE(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
+LPVOID  HeapREALLOC(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
+
+#else
+
+#define HeapCREATE  HeapCreate
+#define HeapDESTROY HeapDestroy
+#define HeapALLOC   HeapAlloc
+#define HeapFREE    HeapFree
+#define HeapREALLOC HeapReAlloc
+
+#endif
+
+/*
+ * Tail queue declarations.
+ */
+#define TAILQ_HEAD(name, type)                                          \
+struct name {                                                           \
+        struct type *tqh_first; /* first element */                     \
+        struct type **tqh_last; /* addr of last next element */         \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head)                                    \
+        { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type)                                               \
+struct {                                                                \
+        struct type *tqe_next;  /* next element */                      \
+        struct type **tqe_prev; /* address of previous next element */  \
+}
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_CONCAT(head1, head2, field) do {                          \
+        if (!TAILQ_EMPTY(head2)) {                                      \
+                *(head1)->tqh_last = (head2)->tqh_first;                \
+                (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
+                (head1)->tqh_last = (head2)->tqh_last;                  \
+                TAILQ_INIT((head2));                                    \
+        }                                                               \
+} while (0)
+
+#define TAILQ_EMPTY(head)       ((head)->tqh_first == NULL)
+
+#define TAILQ_FIRST(head)       ((head)->tqh_first)
+
+#define TAILQ_FOREACH(var, head, field)                                 \
+        for ((var) = TAILQ_FIRST((head));                               \
+            (var);                                                      \
+            (var) = TAILQ_NEXT((var), field))
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field)               \
+        for ((var) = TAILQ_LAST((head), headname);                      \
+            (var);                                                      \
+            (var) = TAILQ_PREV((var), headname, field))
+
+#define TAILQ_INIT(head) do {                                           \
+        TAILQ_FIRST((head)) = NULL;                                     \
+        (head)->tqh_last = &TAILQ_FIRST((head));                        \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do {              \
+        if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\
+                TAILQ_NEXT((elm), field)->field.tqe_prev =              \
+                    &TAILQ_NEXT((elm), field);                          \
+        else {                                                          \
+                (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
+        }                                                               \
+        TAILQ_NEXT((listelm), field) = (elm);                           \
+        (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field);          \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
+        (elm)->field.tqe_prev = (listelm)->field.tqe_prev;              \
+        TAILQ_NEXT((elm), field) = (listelm);                           \
+        *(listelm)->field.tqe_prev = (elm);                             \
+        (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field);          \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do {                        \
+        if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL)   \
+                TAILQ_FIRST((head))->field.tqe_prev =                   \
+                    &TAILQ_NEXT((elm), field);                          \
+        else                                                            \
+                (head)->tqh_last = &TAILQ_NEXT((elm), field);           \
+        TAILQ_FIRST((head)) = (elm);                                    \
+        (elm)->field.tqe_prev = &TAILQ_FIRST((head));                   \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do {                        \
+        TAILQ_NEXT((elm), field) = NULL;                                \
+        (elm)->field.tqe_prev = (head)->tqh_last;                       \
+        *(head)->tqh_last = (elm);                                      \
+        (head)->tqh_last = &TAILQ_NEXT((elm), field);                   \
+} while (0)
+
+#define TAILQ_LAST(head, headname)                                      \
+        (*(((struct headname *)((head)->tqh_last))->tqh_last))
+
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+
+#define TAILQ_PREV(elm, headname, field)                                \
+        (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+
+#define TAILQ_REMOVE(head, elm, field) do {                             \
+        if ((TAILQ_NEXT((elm), field)) != NULL)                         \
+                TAILQ_NEXT((elm), field)->field.tqe_prev =              \
+                    (elm)->field.tqe_prev;                              \
+        else {                                                          \
+                (head)->tqh_last = (elm)->field.tqe_prev;               \
+        }                                                               \
+        *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field);              \
+} while (0)
+  
+/** Some usefull macros */
+
+#define APXHANDLE_SPINLOCK(h)               \
+    APXMACRO_BEGIN                          \
+    while (InterlockedCompareExchange(&((h)->lvSpin), 1, 0) != 0) { \
+        Sleep(10);                          \
+        SwitchToThread();                   \
+    }                                       \
+    APXMACRO_END
+
+#define APXHANDLE_SPINUNLOCK(h)             \
+    APXMACRO_BEGIN                          \
+    InterlockedExchange(&((h)->lvSpin), 0); \
+    APXMACRO_END
+
+#define APX_SPINLOCK(lock)                  \
+    APXMACRO_BEGIN                          \
+    while (InterlockedCompareExchange(&(lock), 1, 0) != 0) \
+        SwitchToThread();                   \
+    APXMACRO_END
+
+#define APX_SPINUNLOCK(lock)                \
+    APXMACRO_BEGIN                          \
+    InterlockedExchange(&(lock), 0);        \
+    APXMACRO_END
+
+/*
+ * Define a union with types which are likely to have the longest
+ * *relevant* CPU-specific memory word alignment restrictions...
+ */ 
+typedef union APXMEMWORD {
+    void  *vp;
+    void (*fp)(void);
+    char  *cp;
+    long   l;
+    double d;
+} APXMEMWORD;
+
+typedef struct APXCALLHOOK APXCALLHOOK;
+
+struct APXCALLHOOK {
+
+    LPAPXFNCALLBACK     fnCallback;
+    TAILQ_ENTRY(APXCALLHOOK)  queue;
+};
+
+struct stAPXHANDLE {
+    /** The type of the handle */ 
+    DWORD               dwType;         
+    /** Handle Flags */ 
+    DWORD               dwFlags;
+    /** Handle user data size */ 
+    DWORD               dwSize;
+    /** parameters for event callback */ 
+    WPARAM              wParam;
+    LPARAM              lParam;
+    UINT                uMsg;
+    /** main callback function (using default if not specified) */ 
+    LPAPXFNCALLBACK     fnCallback;
+    /** callback functions hook list */
+    TAILQ_HEAD(_lCallbacks, APXCALLHOOK) lCallbacks;
+    /** allocation pool  */
+    APXHANDLE           hPool;
+    /** interlocking value */ 
+    LONG volatile       lvSpin;
+
+    /** message event handle  */ 
+    HANDLE              hEventHandle;
+    /** message event thread  */ 
+    HANDLE              hEventThread;
+    /** message event thread id  */ 
+    DWORD               hEventThreadId;
+    /** private local heap */
+    HANDLE              hHeap;
+    /** list enty for pool  */ 
+    TAILQ_ENTRY(stAPXHANDLE)  queue;
+    /** small userdata pointer  */ 
+    union   {
+        LPVOID          lpPtr;
+        HANDLE          hWinHandle;
+        double          dValue;
+        void            (*fpValue)();
+    } uData;
+
+    APXMEMWORD          stAlign;
+};
+
+#define APXHANDLE_DATA(h)       ((void *)((char*)(h) + sizeof(stAPXHANDLE)))
+#define APXHANDLE_SZ            sizeof(stAPXHANDLE)
+
+extern APX_OSLEVEL  _st_apx_oslevel;
+
+#define APX_GET_OSLEVEL()   ((_st_apx_oslevel == APX_WINVER_UNK) ? apxGetOsLevel() : _st_apx_oslevel)
+
+#ifdef _DEBUG
+void    ErrorMessage(LPCTSTR szError, BOOL bFatal);
+#else
+#define ErrorMessage(szError, bFatal) ((void)0)
+#endif
+/* zero separated, double zero terminated string */
+struct APXMULTISZ {
+    DWORD   dwAllocated;  /* length including terminators */
+    DWORD   dwInsert;     /* next insert position */
+};
+
+typedef struct APXREGENUM {
+    HKEY     hServicesKey;
+    DWORD    dwIndex;                   /* current enum index           */
+    DWORD    cSubKeys;                  /* number of subkeys            */
+    DWORD    cbMaxSubKey;               /* longest subkey size          */
+    DWORD    cchMaxClass;               /* longest class string         */
+    DWORD    cValues;                   /* number of values for key     */
+    DWORD    cchMaxValue;               /* longest value name           */
+    DWORD    cbMaxValueData;            /* longest value data           */
+
+} APXREGENUM, *LPAPXREGENUM;
+
+BOOL    apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry);
+
+BOOL    apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription);
+BOOL    apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
+                                  DWORD dwDescriptionLength);
+BOOL    apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
+                           DWORD dwUserLength);
+
+DWORD   __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount);
+DWORD   __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount);
+LPSTR   __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName);
+LPWSTR  __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName);
+
+
+#endif /* _PRIVATE_H_INCLUDED_ */
diff --git a/src/native/nt/procrun/src/registry.c b/src/native/nt/procrun/src/registry.c
new file mode 100644
index 0000000..bd07ffd
--- /dev/null
+++ b/src/native/nt/procrun/src/registry.c
@@ -0,0 +1,1084 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+static LPCWSTR REGSERVICE_ROOT  = L"SYSTEM\\CurrentControlSet\\Services\\";
+static LPCWSTR REGSOFTWARE_ROOT = L"SOFTWARE\\";
+static LPCWSTR REGSERVICE_START = L"Start";
+static LPCWSTR REGSERVICE_USER  = L"ObjectName";
+static LPCWSTR REGPARAMS        = L"Parameters";
+static LPCWSTR REGDESCRIPTION   = L"Description";
+static LPCWSTR REGSEPARATOR     = L"\\";
+static LPCWSTR REGAPACHE_ROOT   = L"Apache Software Foundation";
+/* predefined java keys */
+static LPCWSTR JRE_REGKEY       = L"SOFTWARE\\JavaSoft\\Java Runtime Environment\\";
+static LPCWSTR JDK_REGKEY       = L"SOFTWARE\\JavaSoft\\Java Development Kit\\";
+static LPCWSTR JAVA_CURRENT     = L"CurrentVersion";
+static LPCWSTR JAVA_RUNTIME     = L"RuntimeLib";
+static LPCWSTR JAVA_HOME        = L"JAVA_HOME";
+static LPCWSTR JAVAHOME         = L"JavaHome";
+
+#define REG_CAN_CREATE(r)   \
+    ((r)->samOptions & KEY_CREATE_SUB_KEY)  
+
+#define REG_CAN_WRITE(r)   \
+    ((r)->samOptions & KEY_SET_VALUE)  
+
+
+#define REG_GET_KEY(r, w, k)    \
+    APXMACRO_BEGIN              \
+    switch(w) {                                                     \
+        case APXREG_SOFTWARE:       k = (r)->hRootKey;      break;  \
+        case APXREG_PARAMSOFTWARE:  k = (r)->hRparamKey;    break;  \
+        case APXREG_SERVICE:        k = (r)->hServKey;      break;  \
+        case APXREG_PARAMSERVICE:   k = (r)->hSparamKey;    break;  \
+        case APXREG_USER:           k = (r)->hUserKey;      break;  \
+        case APXREG_PARAMUSER:      k = (r)->hUparamKey;    break;  \
+        default: k = NULL; break;                                   \
+    } APXMACRO_END
+
+
+typedef struct APXREGISTRY  APXREGISTRY;
+typedef APXREGISTRY*        LPAPXREGISTRY;
+typedef struct APXREGSUBKEY APXREGSUBKEY;
+
+struct APXREGSUBKEY {
+    APXHANDLE   hRegistry;    
+    HKEY        hKey;
+    LPCTSTR     syKeyName;
+    TAILQ_ENTRY(APXREGSUBKEY);
+};
+
+struct APXREGISTRY {
+    HKEY    hRootKey;   /* root key */
+    HKEY    hServKey;   /* service key */
+    HKEY    hUserKey;   /* user key */
+    HKEY    hCurrKey;   /* Current opened key */
+    LPVOID  pCurrVal;   /* Current value, overwitten on a next call */
+    HKEY    hRparamKey; /* root\\Parameters */
+    HKEY    hSparamKey; /* service\\Parameters */
+    HKEY    hUparamKey; /* service\\Parameters */
+    REGSAM  samOptions;
+    /** list enty for opened subkeys  */ 
+    TAILQ_HEAD(_lSubkeys, APXREGSUBKEY) lSubkeys;
+
+};
+
+#define SAFE_CLOSE_KEY(k) \
+    if ((k) != NULL && (k) != INVALID_HANDLE_VALUE) {   \
+        RegCloseKey((k));                               \
+        (k) = NULL;                                     \
+    }
+
+static BOOL __apxRegistryCallback(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam)
+{
+    LPAPXREGISTRY lpReg;
+
+    lpReg = APXHANDLE_DATA(hObject);
+    switch (uMsg) {
+        case WM_CLOSE:
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);    
+        SAFE_CLOSE_KEY(lpReg->hRparamKey);
+        SAFE_CLOSE_KEY(lpReg->hSparamKey);
+        SAFE_CLOSE_KEY(lpReg->hUparamKey);
+        SAFE_CLOSE_KEY(lpReg->hRootKey);    
+        SAFE_CLOSE_KEY(lpReg->hServKey);
+        SAFE_CLOSE_KEY(lpReg->hUserKey);
+        break;
+        default:
+        break;
+    }
+    return TRUE;
+}
+
+LPSTR __apxGetRegistrySzA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName)
+{
+    LPSTR  szRet;
+    DWORD  rc;
+    DWORD  dwType;
+    DWORD  dwSize;
+
+    rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+        return NULL;
+    }
+    if (!(szRet = apxPoolAlloc(hPool, dwSize)))
+        return NULL;
+    RegQueryValueExA(hKey, szValueName, NULL, &dwType, (LPBYTE)szRet, &dwSize);
+
+    return szRet;
+}
+
+LPWSTR __apxGetRegistrySzW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
+{
+    LPWSTR wsRet;
+    DWORD  rc;
+    DWORD  dwType;
+    DWORD  dwSize;
+
+    rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+        return NULL;
+    }
+    if (!(wsRet = apxPoolAlloc(hPool, dwSize * sizeof(WCHAR))))
+        return NULL;
+    RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)wsRet, &dwSize);
+
+    return wsRet;
+}
+
+BOOL __apxGetRegistryStrW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
+                          LPWSTR lpRetval, DWORD dwMaxLen)
+{
+    DWORD  rc;
+    DWORD  dwType;
+    DWORD  dwSize = dwMaxLen;
+
+    rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)lpRetval, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_SZ) {
+        lpRetval = L'\0';
+        return FALSE;
+    }
+    else
+        return TRUE;
+}
+
+LPBYTE __apxGetRegistryBinaryA(APXHANDLE hPool, HKEY hKey, LPCSTR szValueName,
+                               LPDWORD lpdwLength)
+{
+    LPBYTE lpRet;
+    DWORD  rc;
+    DWORD  dwType;
+    DWORD  dwSize;
+
+    rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, NULL, &dwSize);
+    if (rc != ERROR_SUCCESS || dwSize == 0) {
+        return NULL;
+    }
+    if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
+        return NULL;
+    RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpRet, &dwSize);
+    if (lpdwLength)
+        *lpdwLength = dwSize;
+    return lpRet;
+}
+
+LPBYTE __apxGetRegistryBinaryW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName,
+                               LPDWORD lpdwLength)
+{
+    LPBYTE lpRet;
+    DWORD  rc;
+    DWORD  dwType;
+    DWORD  dwSize;
+
+    rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, NULL, &dwSize);
+    if (rc != ERROR_SUCCESS || dwSize == 0) {
+        return NULL;
+    }
+    if (!(lpRet = apxPoolAlloc(hPool, dwSize)))
+        return NULL;
+    RegQueryValueExW(hKey, wsValueName, NULL, &dwType, lpRet, &dwSize);
+    if (lpdwLength)
+        *lpdwLength = dwSize;
+
+    return lpRet;
+}
+
+DWORD __apxGetRegistryDwordW(APXHANDLE hPool, HKEY hKey, LPCWSTR wsValueName)
+{
+    DWORD  dwRet;
+    DWORD  rc;
+    DWORD  dwType;
+    DWORD  dwSize = sizeof(DWORD);
+
+    rc = RegQueryValueExW(hKey, wsValueName, NULL, &dwType, (LPBYTE)&dwRet, &dwSize);
+    if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
+        return 0xFFFFFFFF;
+    }
+
+    return dwRet;
+}
+
+
+APXHANDLE
+apxCreateRegistryW(APXHANDLE hPool, REGSAM samDesired,
+                   LPCWSTR szRoot,
+                   LPCWSTR szKeyName,
+                   DWORD dwOptions)
+{
+    APXHANDLE hRegistry;
+    LPAPXREGISTRY lpReg;
+     /* maximum key length is 512 characters. */
+    WCHAR     buff[SIZ_BUFLEN];
+    LONG      rc = ERROR_SUCCESS;
+    HKEY      hRootKey   = NULL;
+    HKEY      hUserKey   = NULL;
+    HKEY      hServKey   = NULL;
+    HKEY      hRparamKey = NULL;
+    HKEY      hSparamKey = NULL;
+    HKEY      hUparamKey = NULL;
+
+    if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
+        return NULL;
+    if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
+        return NULL;
+
+    /* make the HKLM\\SOFTWARE key */
+    lstrcpyW(buff, REGSOFTWARE_ROOT); 
+    if (szRoot)
+        lstrcatW(buff, szRoot);
+    else
+        lstrcatW(buff, REGAPACHE_ROOT);       
+    lstrcatW(buff, REGSEPARATOR);
+    lstrcatW(buff, szKeyName);
+    /* Open or create the root key */
+    if (dwOptions & APXREG_SOFTWARE) {
+        if (samDesired & KEY_CREATE_SUB_KEY)
+            rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, buff, 0, NULL, 0, 
+                                 samDesired, NULL,
+                                 &hRootKey, NULL);
+        else
+            rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
+                               samDesired, &hRootKey);
+        if (rc != ERROR_SUCCESS) {
+            hRootKey = NULL;
+            goto cleanup;
+        }
+        /* Open or create the root parameters key */
+        if (samDesired & KEY_CREATE_SUB_KEY)
+            rc = RegCreateKeyExW(hRootKey, REGPARAMS, 0, NULL, 0, 
+                                 samDesired, NULL,
+                                 &hRparamKey, NULL);
+        else
+            rc = RegOpenKeyExW(hRootKey, REGPARAMS, 0,
+                               samDesired, &hRparamKey);
+        if (rc != ERROR_SUCCESS) {
+            hRparamKey = NULL;
+            goto cleanup;
+        }
+    }
+
+    if (dwOptions & APXREG_USER) {
+        /* Open or create the users root key */
+        if (samDesired & KEY_CREATE_SUB_KEY)
+            rc = RegCreateKeyExW(HKEY_CURRENT_USER, buff, 0, NULL, 0, 
+                                 samDesired, NULL,
+                                 &hUserKey, NULL);
+        else
+            rc = RegOpenKeyExW(HKEY_CURRENT_USER, buff, 0,
+                               samDesired, &hUserKey);
+        if (rc != ERROR_SUCCESS) {
+            hUserKey = NULL;
+            goto cleanup;
+        }
+        /* Open or create the users parameters key */
+        if (samDesired & KEY_CREATE_SUB_KEY)
+            rc = RegCreateKeyExW(hUserKey, REGPARAMS, 0, NULL, 0, 
+                                 samDesired, NULL,
+                             &hUparamKey, NULL);
+        else
+            rc = RegOpenKeyExW(hUserKey, REGPARAMS, 0,
+                               samDesired, &hUparamKey);
+        if (rc != ERROR_SUCCESS) {
+            hUparamKey = NULL;
+            goto cleanup;
+        }
+    }
+    /* Check if we need a service key */
+    if (dwOptions & APXREG_SERVICE) {
+        lstrcpyW(buff, REGSERVICE_ROOT); 
+        lstrcatW(buff, szKeyName);
+        /* Service has to be created allready */
+        rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buff, 0,
+                           samDesired, &hServKey);
+        if (rc != ERROR_SUCCESS) {
+            hServKey = NULL;
+            goto cleanup;
+        }
+        /* Open or create the root parameters key */
+        if (samDesired & KEY_CREATE_SUB_KEY)
+            rc = RegCreateKeyExW(hServKey, REGPARAMS, 0, NULL, 0, 
+                                 samDesired, NULL,
+                                 &hSparamKey, NULL);
+        else
+            rc = RegOpenKeyExW(hServKey, REGPARAMS, 0,
+                               samDesired, &hSparamKey);
+        if (rc != ERROR_SUCCESS) {
+            hSparamKey = NULL;
+            goto cleanup;
+        }
+    }
+    hRegistry = apxHandleCreate(hPool, 0,
+                                NULL, sizeof(APXREGISTRY),
+                                __apxRegistryCallback);
+    if (IS_INVALID_HANDLE(hRegistry))
+        return NULL;
+    hRegistry->dwType = APXHANDLE_TYPE_REGISTRY;
+    lpReg = APXHANDLE_DATA(hRegistry);
+    lpReg->samOptions = samDesired;
+    lpReg->hRootKey   = hRootKey;
+    lpReg->hUserKey   = hUserKey;
+    lpReg->hServKey   = hServKey;
+    lpReg->hRparamKey = hRparamKey;
+    lpReg->hUparamKey = hUparamKey;
+    lpReg->hSparamKey = hSparamKey;
+    TAILQ_INIT(&lpReg->lSubkeys);
+
+    SetLastError(rc);
+    return hRegistry;
+
+cleanup:
+    SAFE_CLOSE_KEY(hRparamKey);
+    SAFE_CLOSE_KEY(hSparamKey);
+    SAFE_CLOSE_KEY(hUparamKey);
+    SAFE_CLOSE_KEY(hRootKey);
+    SAFE_CLOSE_KEY(hServKey);
+    SAFE_CLOSE_KEY(hUserKey);
+    
+    SetLastError(rc);
+    return NULL;
+}
+
+APXHANDLE
+apxCreateRegistryA(APXHANDLE hPool, REGSAM samDesired,
+                   LPCSTR szRoot,
+                   LPCSTR szKeyName,
+                   DWORD dwOptions)
+{
+    WCHAR    wcRoot[SIZ_RESLEN];
+    WCHAR    wcKey[SIZ_RESLEN];
+    LPWSTR   wsRoot = NULL;
+    if (szRoot) {
+        AsciiToWide(szRoot, wcRoot);
+        wsRoot = wcRoot;
+    }
+    AsciiToWide(szKeyName, wcKey);
+    return apxCreateRegistryW(hPool, samDesired, wsRoot, wcKey, dwOptions);
+}
+
+LPSTR
+apxRegistryGetStringA(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCSTR szSubkey, LPCSTR szValueName)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return NULL;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return NULL;
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExA(hKey, szSubkey, 0,
+                         lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return NULL;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    lpReg->pCurrVal = __apxGetRegistrySzA(hRegistry->hPool, hKey, szValueName);
+
+    return lpReg->pCurrVal;
+}
+
+LPWSTR
+apxRegistryGetStringW(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return NULL;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return NULL;
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExW(hKey, szSubkey, 0,
+                         lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return NULL;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    lpReg->pCurrVal = __apxGetRegistrySzW(hRegistry->hPool, hKey, szValueName);
+
+    return lpReg->pCurrVal;
+}
+
+LPBYTE
+apxRegistryGetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCSTR szSubkey, LPCSTR szValueName,
+                      LPBYTE lpData, LPDWORD lpdwLength)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return NULL;
+    lpReg = APXHANDLE_DATA(hRegistry);
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return NULL;
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExA(hKey, szSubkey, 0,
+                         lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return NULL;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (lpData && lpdwLength && *lpdwLength) {
+        DWORD rc, dwType = REG_BINARY;
+        rc = RegQueryValueExA(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
+        if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
+            ErrorMessage(NULL, FALSE);
+            return NULL;
+        }
+        lpReg->pCurrVal = lpData;
+    }
+    else {
+        lpReg->pCurrVal = __apxGetRegistryBinaryA(hRegistry->hPool, hKey, szValueName, lpdwLength);
+    }
+
+    return lpReg->pCurrVal;
+}
+
+LPBYTE
+apxRegistryGetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCWSTR szSubkey, LPCWSTR szValueName,
+                      LPBYTE lpData, LPDWORD lpdwLength)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return NULL;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return NULL;
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExW(hKey, szSubkey, 0,
+                          lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return NULL;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (lpData && lpdwLength && *lpdwLength) {
+        DWORD rc, dwType = REG_BINARY;
+        rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, lpData, lpdwLength);
+        if (rc != ERROR_SUCCESS || dwType != REG_BINARY) {
+            return NULL;
+        }
+        lpReg->pCurrVal = lpData;
+    }
+    else {
+        lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
+    }
+    return lpReg->pCurrVal;
+}
+
+DWORD
+apxRegistryGetNumberW(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwRval, rl;
+    DWORD rc, dwType = REG_DWORD;
+
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return 0;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return 0;
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExW(hKey, szSubkey, 0,
+                          lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return 0;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    rl = sizeof(DWORD);
+    rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (LPBYTE)&dwRval, &rl);
+    if (rc != ERROR_SUCCESS || dwType != REG_DWORD)
+        return 0;
+    else
+        return dwRval;
+}
+
+LPWSTR
+apxRegistryGetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+                     LPCWSTR szSubkey, LPCWSTR szValueName,
+                     LPWSTR lpData, LPDWORD lpdwLength)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return NULL;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return NULL;
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExW(hKey, szSubkey, 0,
+                          lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return NULL;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (lpData && lpdwLength && *lpdwLength) {
+        DWORD rc, dwType = REG_MULTI_SZ;
+        rc = RegQueryValueExW(hKey, szValueName, NULL, &dwType, (BYTE *)lpData, lpdwLength);
+        if (rc != ERROR_SUCCESS || dwType != REG_MULTI_SZ) {
+            return NULL;
+        }
+        lpReg->pCurrVal = lpData;
+    }
+    else {
+        lpReg->pCurrVal = __apxGetRegistryBinaryW(hRegistry->hPool, hKey, szValueName, lpdwLength);
+        if (lpReg->pCurrVal && lpdwLength)
+            *lpdwLength = *lpdwLength * sizeof(WCHAR);
+    }
+    return lpReg->pCurrVal;
+}
+
+BOOL
+apxRegistrySetBinaryA(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCSTR szSubkey, LPCSTR szValueName,
+                      const LPBYTE lpData, DWORD dwLength)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_BINARY;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegCreateKeyExA(hKey, szSubkey, 0,
+                            NULL, 0, lpReg->samOptions,
+                            NULL, &hSub, NULL) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (RegSetValueExA(hKey, szValueName, 0, dwType,
+                      lpData, dwLength) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+BOOL
+apxRegistrySetBinaryW(APXHANDLE hRegistry, DWORD dwFrom,
+                      LPCWSTR szSubkey, LPCWSTR szValueName,
+                      const LPBYTE lpData, DWORD dwLength)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_BINARY;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegCreateKeyExW(hKey, szSubkey, 0,
+                            NULL, 0, lpReg->samOptions,
+                            NULL, &hSub, NULL) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (RegSetValueExW(hKey, szValueName, 0, dwType,
+                      lpData, dwLength) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+BOOL
+apxRegistrySetMzStrW(APXHANDLE hRegistry, DWORD dwFrom,
+                     LPCWSTR szSubkey, LPCWSTR szValueName,
+                     LPCWSTR lpData, DWORD dwLength)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_MULTI_SZ;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegCreateKeyExW(hKey, szSubkey, 0,
+                            NULL, 0, lpReg->samOptions,
+                            NULL, &hSub, NULL) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (RegSetValueExW(hKey, szValueName, 0, dwType,
+                       (const BYTE *)lpData, dwLength) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+BOOL
+apxRegistrySetStrA(APXHANDLE hRegistry, DWORD dwFrom,
+                   LPCSTR szSubkey, LPCSTR szValueName,
+                   LPCSTR szValue)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_SZ;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegCreateKeyExA(hKey, szSubkey, 0,
+                            NULL, 0, lpReg->samOptions,
+                            NULL, &hSub, NULL) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (!szValue || !lstrlenA(szValue)) {
+        if (RegDeleteValueA(hKey, szValueName) != ERROR_SUCCESS)
+            return FALSE;        
+    }
+    else if (RegSetValueExA(hKey, szValueName, 0, dwType,
+                       (LPBYTE)szValue, lstrlenA(szValue)) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+BOOL
+apxRegistrySetStrW(APXHANDLE hRegistry, DWORD dwFrom,
+                   LPCWSTR szSubkey, LPCWSTR szValueName,
+                   LPCWSTR szValue)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_SZ;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegCreateKeyExW(hKey, szSubkey, 0,
+                            NULL, 0, lpReg->samOptions,
+                            NULL, &hSub, NULL) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (!szValue || !lstrlenW(szValue)) {
+        if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
+            return FALSE;        
+    }
+    else if (RegSetValueExW(hKey, szValueName, 0, dwType,
+                       (LPBYTE)szValue,
+                       lstrlenW(szValue) * sizeof(WCHAR)) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+BOOL
+apxRegistrySetNumW(APXHANDLE hRegistry, DWORD dwFrom,
+                   LPCWSTR szSubkey, LPCWSTR szValueName,
+                   DWORD dwValue)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_DWORD;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegCreateKeyExW(hKey, szSubkey, 0,
+                            NULL, 0, lpReg->samOptions,
+                            NULL, &hSub, NULL) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (RegSetValueExW(hKey, szValueName, 0, dwType,
+                       (LPBYTE)&dwValue,
+                       sizeof(DWORD)) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+
+BOOL
+apxRegistryDeleteW(APXHANDLE hRegistry, DWORD dwFrom,
+                   LPCWSTR szSubkey, LPCWSTR szValueName)
+{
+    LPAPXREGISTRY lpReg;
+    HKEY          hKey, hSub = NULL;
+    DWORD         dwType = REG_SZ;
+    if (IS_INVALID_HANDLE(hRegistry) || 
+        hRegistry->dwType != APXHANDLE_TYPE_REGISTRY)
+        return FALSE;
+    lpReg = APXHANDLE_DATA(hRegistry);
+
+    REG_GET_KEY(lpReg, dwFrom, hKey);
+    if (!hKey)
+        return FALSE;
+
+    if (szSubkey) {
+        SAFE_CLOSE_KEY(lpReg->hCurrKey);
+        if (RegOpenKeyExW(hKey, szSubkey, 0,
+                          lpReg->samOptions, &hSub) != ERROR_SUCCESS)
+            return FALSE;
+        lpReg->hCurrKey = hSub;
+        hKey = hSub;
+    }
+    if (RegDeleteValueW(hKey, szValueName) != ERROR_SUCCESS)
+        return FALSE;
+
+    return TRUE;
+}
+
+
+BOOL
+apxDeleteRegistryW(LPCWSTR szRoot,
+                   LPCWSTR szKeyName,
+                   BOOL bDeleteEmpty)
+{
+    WCHAR     buff[SIZ_BUFLEN];
+    BOOL      rv;
+
+    if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
+        return FALSE;
+    if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
+        return FALSE;
+
+    lstrcpyW(buff, REGSOFTWARE_ROOT); 
+    if (szRoot)
+        lstrcatW(buff, szRoot);
+    else
+        lstrcatW(buff, REGAPACHE_ROOT);       
+    lstrcatW(buff, REGSEPARATOR);
+    lstrcatW(buff, szKeyName);
+    
+    rv = SHDeleteKeyW(HKEY_LOCAL_MACHINE, buff);
+    rv += SHDeleteKeyW(HKEY_CURRENT_USER, buff);
+
+    if (bDeleteEmpty) {
+        lstrcpyW(buff, REGSOFTWARE_ROOT); 
+        if (szRoot)
+            lstrcatW(buff, szRoot);
+        else
+            lstrcatW(buff, REGAPACHE_ROOT); 
+
+        SHDeleteEmptyKeyW(HKEY_LOCAL_MACHINE, buff);
+        SHDeleteEmptyKeyW(HKEY_CURRENT_USER, buff);
+    }
+    return rv;
+}
+
+BOOL
+apxDeleteRegistryA(LPCSTR szRoot,
+                   LPCSTR szKeyName,
+                   BOOL bDeleteEmpty)
+{
+    WCHAR    wcRoot[SIZ_RESLEN];
+    WCHAR    wcKey[SIZ_RESLEN];
+    LPWSTR   wsRoot = NULL;
+    if (szRoot) {
+        AsciiToWide(szRoot, wcRoot);
+        wsRoot = wcRoot;
+    }
+    AsciiToWide(szKeyName, wcKey);
+
+    return apxDeleteRegistryW(wsRoot, wcKey, bDeleteEmpty);
+}
+
+
+LPWSTR apxGetJavaSoftHome(APXHANDLE hPool, BOOL bPreferJre)
+{
+    LPWSTR  wsJhome, off;
+    DWORD   err, dwLen;
+    HKEY    hKey;
+    WCHAR   wsBuf[SIZ_BUFLEN];
+    WCHAR   wsKey[SIZ_RESLEN];
+#if 1 /* XXX: Add that customizable using function call arg */
+    if (!bPreferJre && (wsJhome = __apxGetEnvironmentVariableW(hPool, JAVA_HOME)))
+        return wsJhome;
+#endif
+    lstrcpyW(wsKey, JAVA_CURRENT);
+    if (bPreferJre)
+        lstrcpyW(wsBuf, JRE_REGKEY);
+    else
+        lstrcpyW(wsBuf, JDK_REGKEY);
+    dwLen = lstrlenW(wsBuf);
+    off = &wsBuf[dwLen];
+    dwLen = SIZ_RESMAX;
+    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+        return NULL;
+    }
+    if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL, 
+                                (LPBYTE)off,
+                                &dwLen)) != ERROR_SUCCESS) {
+        RegCloseKey(hKey);
+        return NULL;
+    } 
+    RegCloseKey(hKey);
+    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+        return NULL;
+    }
+    wsJhome = __apxGetRegistrySzW(hPool, hKey, JAVAHOME);
+    if (wsJhome)
+        SetEnvironmentVariableW(JAVA_HOME, wsJhome);
+    RegCloseKey(hKey);
+
+    return wsJhome;
+}
+
+LPWSTR apxGetJavaSoftRuntimeLib(APXHANDLE hPool)
+{
+    LPWSTR  wsRtlib, off;
+    DWORD   err, dwLen = SIZ_RESLEN;
+    HKEY    hKey;
+    WCHAR   wsBuf[SIZ_BUFLEN];
+
+    lstrcpyW(wsBuf, JRE_REGKEY);
+
+    dwLen = lstrlenW(wsBuf);
+    off = &wsBuf[dwLen];
+    dwLen = SIZ_RESLEN;
+    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+        return NULL;
+    }
+    if ((err = RegQueryValueExW(hKey, JAVA_CURRENT, NULL, NULL, 
+                                (LPBYTE)off,
+                                &dwLen)) != ERROR_SUCCESS) {
+        RegCloseKey(hKey);
+        return NULL;
+    } 
+    RegCloseKey(hKey);
+    if ((err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wsBuf,
+                             0, KEY_READ, &hKey)) != ERROR_SUCCESS) {
+        return NULL;
+    }
+    wsRtlib = __apxGetRegistrySzW(hPool, hKey, JAVA_RUNTIME);
+    RegCloseKey(hKey);
+
+    return wsRtlib;
+}
+
+/* Service Registry helper functions */
+
+BOOL apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry)
+{
+    DWORD rc, dwLength = SIZ_RESLEN;
+        
+    if (IS_INVALID_HANDLE(lpEnum->hServicesKey)) {    
+        rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, REGSERVICE_ROOT, 0,
+                       KEY_READ, &(lpEnum->hServicesKey));
+        if (rc != ERROR_SUCCESS) {
+            return FALSE;
+        }
+        rc = RegQueryInfoKeyW(lpEnum->hServicesKey,
+                              NULL,
+                              NULL,
+                              NULL,
+                              &lpEnum->cSubKeys,
+                              &lpEnum->cbMaxSubKey,
+                              &lpEnum->cchMaxClass,
+                              &lpEnum->cValues,
+                              &lpEnum->cchMaxValue,
+                              &lpEnum->cbMaxValueData,
+                              NULL,
+                              NULL);
+        /* TODO: add dynamic maxsubkey length */
+        if (rc != ERROR_SUCCESS || lpEnum->cbMaxSubKey > SIZ_RESLEN) {
+            SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+            return FALSE;
+        }
+    }
+    if (lpEnum->dwIndex >= lpEnum->cSubKeys) {
+        SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+        return FALSE;
+    }
+    rc = RegEnumKeyExW(lpEnum->hServicesKey,
+                       lpEnum->dwIndex++,
+                       lpEntry->szServiceName,
+                       &dwLength,
+                       NULL,
+                       NULL,
+                       NULL,
+                       NULL);
+    if (rc != ERROR_SUCCESS) {
+        SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+        return FALSE;
+    }
+    else {
+        HKEY hKey;
+        rc = RegOpenKeyExW(lpEnum->hServicesKey, lpEntry->szServiceName,
+                           0, KEY_READ, &hKey);
+        if (rc != ERROR_SUCCESS) {
+            SAFE_CLOSE_KEY(lpEnum->hServicesKey);
+            return FALSE;
+        }
+        __apxGetRegistryStrW(NULL, hKey, REGDESCRIPTION,
+                            lpEntry->szServiceDescription, SIZ_DESLEN);
+        __apxGetRegistryStrW(NULL, hKey, REGSERVICE_USER,
+                            lpEntry->szObjectName, SIZ_RESLEN);
+        lpEntry->dwStart = __apxGetRegistryDwordW(NULL, hKey, REGSERVICE_START);
+        RegCloseKey(hKey);
+
+    }
+    return TRUE;
+}
+
+/* We could use the ChangeServiceConfig2 on WIN2K+ 
+ * For now use the registry.
+ */
+BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription)
+{
+    HKEY  hKey;
+    WCHAR wcName[SIZ_RESLEN];
+    DWORD rc;
+
+    if (lstrlenW(szServiceName) > SIZ_RESMAX)
+        return FALSE;
+    lstrcpyW(wcName, REGSERVICE_ROOT);
+    lstrcatW(wcName, szServiceName);
+ 
+    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_WRITE, &hKey);
+    if (rc != ERROR_SUCCESS) {
+        return FALSE;
+    }
+    
+    rc = RegSetValueExW(hKey, REGDESCRIPTION, 0, REG_SZ, (CONST BYTE *)szDescription,
+                        lstrlenW(szDescription) * sizeof(WCHAR));
+    SAFE_CLOSE_KEY(hKey);
+
+    return rc = ERROR_SUCCESS;
+}
+
+BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
+                               DWORD dwDescriptionLength)
+{
+    HKEY  hKey;
+    WCHAR wcName[SIZ_RESLEN];
+    DWORD rc, l = dwDescriptionLength * sizeof(WCHAR);
+    DWORD t = REG_SZ;
+    if (lstrlenW(szServiceName) > SIZ_RESMAX)
+        return FALSE;
+    lstrcpyW(wcName, REGSERVICE_ROOT);
+    lstrcatW(wcName, szServiceName);
+ 
+    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
+    if (rc != ERROR_SUCCESS) {
+        return FALSE;
+    }
+    rc = RegQueryValueExW(hKey, REGDESCRIPTION, NULL, &t, (BYTE *)szDescription,
+                          &l);
+    SAFE_CLOSE_KEY(hKey);
+    if (rc == ERROR_SUCCESS && t == REG_SZ)
+        return TRUE;
+    else
+        return FALSE;
+}
+
+BOOL apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,
+                        DWORD dwUserLength)
+{
+    HKEY  hKey;
+    WCHAR wcName[SIZ_RESLEN];
+    DWORD rc, l = dwUserLength * sizeof(WCHAR);
+    DWORD t = REG_SZ;
+    if (lstrlenW(szServiceName) > SIZ_RESMAX)
+        return FALSE;
+    lstrcpyW(wcName, REGSERVICE_ROOT);
+    lstrcatW(wcName, szServiceName);
+ 
+    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_READ, &hKey);
+    if (rc != ERROR_SUCCESS) {
+        return FALSE;
+    }
+    rc = RegQueryValueExW(hKey, REGSERVICE_USER, NULL, &t, (BYTE *)szUser,
+                          &l);
+    SAFE_CLOSE_KEY(hKey);
+    if (rc == ERROR_SUCCESS && t == REG_SZ)
+        return TRUE;
+    else
+        return FALSE;
+}
diff --git a/src/native/nt/procrun/src/rprocess.c b/src/native/nt/procrun/src/rprocess.c
new file mode 100644
index 0000000..2955aba
--- /dev/null
+++ b/src/native/nt/procrun/src/rprocess.c
@@ -0,0 +1,938 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+#define CHILD_RUNNING               0x0001
+#define CHILD_INITIALIZED           0x0002
+#define CHILD_MAINTREAD_FINISHED    0x0004
+#define PROC_INITIALIZED            0x0008
+#define CHILD_TERMINATE_CODE        19640323 /* Could be any value like my birthday ;-)*/
+
+DYNOLAD_TYPE_DECLARE(CreateRemoteThread,
+                     __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES, 
+                                        DWORD, LPTHREAD_START_ROUTINE,
+                                        LPVOID, DWORD, LPDWORD);
+
+DYNOLAD_TYPE_DECLARE(ExitProcess, __stdcall, void)(UINT);
+
+#define CHECK_IF_ACTIVE(proc) \
+    APXMACRO_BEGIN                                                      \
+        DWORD __st;                                                     \
+        if (!GetExitCodeProcess((proc)->stProcInfo.hProcess, &__st) ||  \
+                                (__st != STILL_ACTIVE))                 \
+            goto cleanup;                                               \
+    APXMACRO_END
+
+#define SAVE_STD_HANDLES(p) \
+    APXMACRO_BEGIN                                                      \
+    if ((p)->bSaveHandles) {                                            \
+    (p)->hParentStdSave[0] = GetStdHandle(STD_INPUT_HANDLE);            \
+    (p)->hParentStdSave[1] = GetStdHandle(STD_OUTPUT_HANDLE);           \
+    (p)->hParentStdSave[2] = GetStdHandle(STD_ERROR_HANDLE);            \
+    } APXMACRO_END
+
+#define RESTORE_STD_HANDLES(p) \
+    APXMACRO_BEGIN                                                      \
+    if ((p)->bSaveHandles) {                                            \
+    SetStdHandle(STD_INPUT_HANDLE,  (p)->hParentStdSave[0]);            \
+    SetStdHandle(STD_OUTPUT_HANDLE, (p)->hParentStdSave[1]);            \
+    SetStdHandle(STD_ERROR_HANDLE,  (p)->hParentStdSave[2]);            \
+    } APXMACRO_END
+
+#define REDIRECT_STD_HANDLES(p) \
+    APXMACRO_BEGIN                                                      \
+    if ((p)->bSaveHandles) {                                            \
+    SetStdHandle(STD_INPUT_HANDLE,  (p)->hChildStdInp);                 \
+    SetStdHandle(STD_OUTPUT_HANDLE, (p)->hChildStdOut);                 \
+    SetStdHandle(STD_ERROR_HANDLE,  (p)->hChildStdErr);                 \
+    } APXMACRO_END
+
+typedef struct APXPROCESS {
+    DWORD                   dwChildStatus;
+    DWORD                   dwOptions;
+    PROCESS_INFORMATION     stProcInfo;
+    /* Size of chars for ANSI/Unicode programs */
+    DWORD                   chSize;
+    /* application working path */
+    LPWSTR                  szWorkingPath;
+    /* executable name */
+    LPWSTR                  szApplicationExec;
+    /* command line (first arg is program name for argv[0]) */
+    LPWSTR                  szCommandLine;
+    LPWSTR                  lpEnvironment;
+    /* set of child inherited pipes */
+    HANDLE                  hChildStdInp;
+    HANDLE                  hChildStdOut;
+    HANDLE                  hChildStdErr;
+    /* parent ends of child pipes */
+    HANDLE                  hChildInpWr;
+    HANDLE                  hChildOutRd;
+    HANDLE                  hChildErrRd;
+    /* Saved console pipes */    
+    HANDLE                  hParentStdSave[3];
+    HANDLE                  hWorkerThreads[3];
+    HANDLE                  hUserToken;
+    HANDLE                  hCurrentProcess;
+    BOOL                    bSaveHandles;
+    /** callback function */ 
+    LPAPXFNCALLBACK         fnUserCallback;
+    LPSECURITY_ATTRIBUTES   lpSA;
+    LPVOID                  lpSD;
+    BYTE                    bSD[SECURITY_DESCRIPTOR_MIN_LENGTH];
+    BYTE                    bSA[sizeof(SECURITY_ATTRIBUTES)];
+
+} APXPROCESS, *LPAPXPROCESS;
+
+/** Process worker thread
+ * Monitors the process thread
+ */
+static DWORD WINAPI __apxProcWorkerThread(LPVOID lpParameter)
+{
+    APXHANDLE hProcess = (APXHANDLE)lpParameter;
+    LPAPXPROCESS lpProc;
+    DWORD dwExitCode = 0;
+
+    lpProc = APXHANDLE_DATA(hProcess);
+    /* Wait util a process has finished its initialization.
+     */
+    WaitForInputIdle(lpProc->stProcInfo.hProcess, INFINITE);
+    lpProc->dwChildStatus |= CHILD_INITIALIZED;
+    /* Wait until the child process exits */
+    if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
+                            INFINITE) == WAIT_OBJECT_0) {
+        lpProc->dwChildStatus |= CHILD_MAINTREAD_FINISHED;
+#if 0
+        if (hProcess->fnCallback)
+            (*hProcess->fnCallback)(hProcess, WM_QUIT, (WPARAM)dwExitCode, 0);
+        lpProc->dwChildStatus &= ~CHILD_RUNNING;
+        GetExitCodeProcess(lpProc->stProcInfo.hProcess, &dwExitCode);
+
+        /* Close that handle */
+#endif
+    }
+    ExitThread(0);
+    return 0;
+}
+
+static DWORD WINAPI __apxProcStdoutThread(LPVOID lpParameter)
+{
+    APXHANDLE hProcess = (APXHANDLE)lpParameter;
+    LPAPXPROCESS lpProc;
+    APXCALLHOOK *lpCall;
+    INT ch;
+    DWORD dwReaded; 
+    lpProc = APXHANDLE_DATA(hProcess);
+    while (lpProc->dwChildStatus & CHILD_RUNNING) {
+        ch = 0;
+        if (!ReadFile(lpProc->hChildOutRd, &ch, lpProc->chSize,
+                      &dwReaded, NULL) || !dwReaded) {
+            
+            break;
+        }
+        if (lpProc->fnUserCallback)
+            (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
+        TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
+            (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)0);
+        }
+        dwReaded = 0;
+        SwitchToThread();
+    }
+    ExitThread(0);
+    return 0;
+}
+
+static DWORD WINAPI __apxProcStderrThread(LPVOID lpParameter)
+{
+    APXHANDLE hProcess = (APXHANDLE)lpParameter;
+    LPAPXPROCESS lpProc;
+    APXCALLHOOK *lpCall;
+    INT ch;
+    DWORD dwReaded; 
+    lpProc = APXHANDLE_DATA(hProcess);
+    while (lpProc->dwChildStatus & CHILD_RUNNING) {
+        if (!ReadFile(lpProc->hChildErrRd, &ch, lpProc->chSize,
+                      &dwReaded, NULL) || !dwReaded) {
+
+            break;
+        }
+        if (lpProc->fnUserCallback)
+            (*lpProc->fnUserCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
+        TAILQ_FOREACH(lpCall, &hProcess->lCallbacks, queue) {
+            (*lpCall->fnCallback)(hProcess, WM_CHAR, (WPARAM)ch, (LPARAM)1);
+        }
+
+        dwReaded = 0;
+        SwitchToThread();
+    }
+
+    ExitThread(0);
+    return 0;
+}
+
+static DWORD __apxProcessPutc(LPAPXPROCESS lpProc, INT ch, DWORD dwSize)
+{
+    if (lpProc->dwChildStatus & CHILD_RUNNING) {
+        DWORD wr = 0;
+        if (WriteFile(lpProc->hChildInpWr, &ch, dwSize, &wr, NULL) &&
+                      wr == dwSize) {
+            return 1;
+        }
+    }
+    
+    return 0;
+}
+
+static DWORD __apxProcessPuts(LPAPXPROCESS lpProc, LPCTSTR szString)
+{
+    DWORD l, n = 0;
+    l = lstrlen(szString) * lpProc->chSize;
+    if (lpProc->dwChildStatus & CHILD_RUNNING && l) {
+        DWORD wr = 0;
+        while (TRUE) {
+            if (WriteFile(lpProc->hChildInpWr, szString, l,
+                          &wr, NULL)) {
+                n += wr;
+                if (wr < l) {
+                    l -= wr;
+                    szString += wr;
+                }
+                else {
+                    /* Flush the buffer */
+                    FlushFileBuffers(lpProc->hChildInpWr);
+                    break;
+                }
+            }
+            else
+                break;
+        }
+    }
+    
+    return n;
+}
+
+static DWORD __apxProcessWrite(LPAPXPROCESS lpProc, LPCVOID lpData, DWORD dwLen)
+{
+    LPBYTE buf = (LPBYTE)lpData;
+    DWORD  n = 0;
+    if (!lpData || !dwLen)
+        return 0;
+    
+    if (lpProc->dwChildStatus & CHILD_RUNNING) {
+        DWORD wr = 0;
+        while (lpProc->dwChildStatus & CHILD_RUNNING) {
+            if (WriteFile(lpProc->hChildInpWr, buf, dwLen,
+                          &wr, NULL)) {
+                n += wr;
+                if (wr < dwLen) {
+                    dwLen -= wr;
+                    buf += wr;
+                }
+                else
+                    break;
+            }
+            else
+                break;
+        }
+    }
+    
+    return n;
+}
+
+/** Helper functions */
+static BOOL __apxProcCreateChildPipes(LPAPXPROCESS lpProc)
+{
+    BOOL   rv = FALSE;
+
+    if (!CreatePipe(&(lpProc->hChildStdInp),
+                    &(lpProc->hChildInpWr),
+                    lpProc->lpSA, 0)) {
+        ErrorMessage(NULL, FALSE);
+        goto cleanup;
+    }
+    if (!SetHandleInformation(lpProc->hChildInpWr,
+                              HANDLE_FLAG_INHERIT, 0)) {
+        ErrorMessage(NULL, FALSE);
+        goto cleanup;
+    }
+
+    if (!CreatePipe(&(lpProc->hChildOutRd),
+                    &(lpProc->hChildStdOut),
+                    lpProc->lpSA, 0)) {
+        ErrorMessage(NULL, FALSE);
+        goto cleanup;
+    }
+
+    if (!SetHandleInformation(lpProc->hChildOutRd,
+                              HANDLE_FLAG_INHERIT, 0)) {
+        ErrorMessage(NULL, FALSE);
+        goto cleanup;
+    }
+
+    if (!CreatePipe(&(lpProc->hChildErrRd),
+                    &(lpProc->hChildStdErr),
+                    lpProc->lpSA, 0)) {
+        ErrorMessage(NULL, FALSE);
+        goto cleanup;
+    }
+
+    if (!SetHandleInformation(lpProc->hChildErrRd,
+                              HANDLE_FLAG_INHERIT, 0)) {
+        ErrorMessage(NULL, FALSE);
+        goto cleanup;
+    }
+    rv = TRUE;
+cleanup:
+
+    return rv;
+}
+
+/* Close the process.
+ * Create the remote thread and call the ExitProcess
+ * Terminate the process, if all of the above fails.
+ */
+static BOOL __apxProcessClose(APXHANDLE hProcess)
+{
+    LPAPXPROCESS lpProc;
+    DYNLOAD_FPTR_DECLARE(CreateRemoteThread);
+    DYNLOAD_FPTR_DECLARE(ExitProcess);
+
+    UINT    uExitCode = CHILD_TERMINATE_CODE; /* Could be any value like my birthday ;-)*/
+    HANDLE  hDup, hRemote;
+
+    lpProc = APXHANDLE_DATA(hProcess);
+    CHECK_IF_ACTIVE(lpProc);
+    
+    /* Try to close the child's stdin first */
+    SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+    /* Wait 1 sec for child process to 
+     * recognize that the stdin has been closed.
+     */
+    if (WaitForSingleObject(lpProc->stProcInfo.hProcess, 1000) == WAIT_OBJECT_0)
+        goto cleanup;
+
+    CHECK_IF_ACTIVE(lpProc);
+    
+    /* Try to create the remote thread in the child address space */
+    DYNLOAD_FPTR_ADDRESS(CreateRemoteThread, KERNEL32);
+    if (DuplicateHandle(lpProc->hCurrentProcess, 
+                        lpProc->stProcInfo.hProcess, 
+                        lpProc->hCurrentProcess, 
+                        &hDup, 
+                        PROCESS_ALL_ACCESS, 
+                        FALSE, 0)) {
+        DYNLOAD_FPTR_ADDRESS(ExitProcess, KERNEL32);
+        /* Now call the ExitProcess from inside the client
+         * This will safely unload all the dll's.
+         */
+        hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup, 
+                                NULL, 0, 
+                                (LPTHREAD_START_ROUTINE)DYNLOAD_FPTR(ExitProcess),
+                                (PVOID)&uExitCode, 0, NULL); 
+        if (!IS_INVALID_HANDLE(hRemote)) {
+            if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
+                    2000) == WAIT_OBJECT_0) {
+
+            }
+            else {
+                TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
+            }
+            CloseHandle(hRemote);
+        }
+        CloseHandle(hDup);
+        goto cleanup;
+    }
+  
+    TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
+    
+cleanup:
+     /* Close the process handle */
+    SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
+    lpProc->dwChildStatus &= ~CHILD_RUNNING;
+    return TRUE;
+}
+
+static BOOL __apxProcessCallback(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam)
+{
+    LPAPXPROCESS lpProc;
+
+    lpProc = APXHANDLE_DATA(hObject);
+    /* Call the user supplied callback first */
+    if (lpProc->fnUserCallback)
+        (*lpProc->fnUserCallback)(hObject, uMsg, wParam, lParam);
+    switch (uMsg) {
+        case WM_CLOSE:
+            if (lpProc->dwChildStatus & CHILD_RUNNING) {
+                __apxProcessClose(hObject);
+                /* Wait for all worker threads to exit */
+                WaitForMultipleObjects(3, lpProc->hWorkerThreads, TRUE, INFINITE);
+            }
+            SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
+
+            /* Close parent side of the pipes */    
+            SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);  
+            SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
+            SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
+
+            SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[0]);
+            SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[1]);
+            SAFE_CLOSE_HANDLE(lpProc->hWorkerThreads[2]);
+            SAFE_CLOSE_HANDLE(lpProc->hUserToken);
+            apxFree(lpProc->szApplicationExec);
+            apxFree(lpProc->szCommandLine);
+            apxFree(lpProc->szWorkingPath);
+            RESTORE_STD_HANDLES(lpProc);
+            SAFE_CLOSE_HANDLE(lpProc->hCurrentProcess);
+            if (lpProc->lpEnvironment)
+                FreeEnvironmentStringsW(lpProc->lpEnvironment);
+
+        case WM_QUIT: 
+            /* The process has finished
+             * This is a WorkerThread message
+             */
+            lpProc->dwChildStatus &= ~CHILD_RUNNING;
+        break;
+        case WM_CHAR:
+            __apxProcessPutc(lpProc, (INT)lParam, lpProc->chSize);
+        break;
+        case WM_SETTEXT:
+            if (wParam)
+                __apxProcessWrite(lpProc, (LPCVOID)lParam, (DWORD)wParam);
+            else
+                __apxProcessPuts(lpProc, (LPCTSTR)lParam);            
+        break;
+        default:
+        break;
+    }
+
+    return TRUE;
+}
+
+/** Create the process but don't start it
+ *
+ APXHANDLE
+apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+                  LPAPXFNCALLBACK fnCallback,
+                  LPCWSTR szUsername, LPCWSTR szPassword,
+                  BOOL bLogonAsService)
+{
+    APXHANDLE hProcess;
+    LPAPXPROCESS lpProc;
+    HANDLE hUserToken = NULL;
+    if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
+        HANDLE hUser;
+#ifndef _UNICODE
+        WCHAR wsUsername[256];
+        WCHAR wsPassword[256];
+        AsciiToWide(szUsername, wsUsername); 
+        AsciiToWide(szPassword, wsPassword); 
+#else
+        LPCWSTR wsUsername = szUsername;
+        LPCWSTR wsPassword = szPassword;
+#endif
+
+ */
+
+
+ APXHANDLE
+apxCreateProcessA(APXHANDLE hPool, DWORD dwOptions,
+                  LPAPXFNCALLBACK fnCallback,
+                  LPCSTR szUsername, LPCSTR szPassword,
+                  BOOL bLogonAsService)
+{
+
+    if (szUsername && szPassword) {
+        WCHAR wsUsername[256];
+        WCHAR wsPassword[256];
+        AsciiToWide(szUsername, wsUsername); 
+        AsciiToWide(szPassword, wsPassword); 
+        return apxCreateProcessW(hPool, dwOptions, fnCallback,
+                                 wsUsername, wsPassword, bLogonAsService);
+    }
+    else
+        return apxCreateProcessW(hPool, dwOptions, fnCallback,
+                                 NULL, NULL, bLogonAsService);
+}
+
+APXHANDLE
+apxCreateProcessW(APXHANDLE hPool, DWORD dwOptions,
+                  LPAPXFNCALLBACK fnCallback,
+                  LPCWSTR szUsername, LPCWSTR szPassword,
+                  BOOL bLogonAsService)
+{
+    APXHANDLE hProcess;
+    LPAPXPROCESS lpProc;
+    HANDLE hUserToken = NULL;
+    /* CreateProcessAsUser is supported only on NT */
+    if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
+        HANDLE hUser;
+        if (!LogonUserW(szUsername, 
+                        NULL, 
+                        szPassword, 
+                        bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
+                        LOGON32_PROVIDER_DEFAULT,
+                        &hUser)) {
+            /* Logon Failed */
+            ErrorMessage(NULL, TRUE);
+            return NULL;
+        }
+        if (!DuplicateTokenEx(hUser, 
+                              TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY, 
+                              NULL,
+                              SecurityImpersonation,
+                              TokenPrimary,
+                              &hUserToken)) {
+            CloseHandle(hUser);
+            /* Failed to duplicate the user token */
+                ErrorMessage(NULL, TRUE);
+            return NULL;
+        }
+        if (!ImpersonateLoggedOnUser(hUserToken)) {
+            CloseHandle(hUser);
+            CloseHandle(hUserToken);
+            /* failed to impersonate the logged user */
+                ErrorMessage(NULL, TRUE);
+            return NULL;
+        }
+        CloseHandle(hUser);
+    }
+
+    hProcess = apxHandleCreate(hPool, APXHANDLE_HAS_EVENT,
+                               NULL, sizeof(APXPROCESS),
+                               __apxProcessCallback);
+    if (IS_INVALID_HANDLE(hProcess))
+        return NULL;
+    hProcess->dwType = APXHANDLE_TYPE_PROCESS;
+    lpProc = APXHANDLE_DATA(hProcess);
+    lpProc->dwOptions = dwOptions;
+    lpProc->fnUserCallback = fnCallback;
+    lpProc->hUserToken  = hUserToken;
+    /* set the CHAR length */
+    if (dwOptions & CREATE_UNICODE_ENVIRONMENT)
+        lpProc->chSize = sizeof(WCHAR);
+    else
+        lpProc->chSize = sizeof(CHAR);
+#if 1
+    DuplicateHandle(GetCurrentProcess(),
+                    GetCurrentProcess(),
+                    GetCurrentProcess(),
+                    &lpProc->hCurrentProcess,
+                    PROCESS_ALL_ACCESS,
+                    FALSE,
+                    0); 
+#else
+    lpProc->hCurrentProcess = GetCurrentProcess();
+#endif
+    lpProc->lpSD = &lpProc->bSD;
+
+    InitializeSecurityDescriptor(lpProc->lpSD, SECURITY_DESCRIPTOR_REVISION);
+    SetSecurityDescriptorDacl(lpProc->lpSD, -1, 0, 0);
+
+    lpProc->lpSA = (LPSECURITY_ATTRIBUTES)&lpProc->bSA[0];
+    lpProc->lpSA->nLength = sizeof (SECURITY_ATTRIBUTES);
+    lpProc->lpSA->lpSecurityDescriptor = lpProc->lpSD;
+    lpProc->lpSA->bInheritHandle = TRUE;
+
+    return hProcess;
+}
+
+static WCHAR _desktop_name[] = 
+    {'W', 'i', 'n', 's', 't', 'a', '0', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', 0};
+
+BOOL
+apxProcessExecute(APXHANDLE hProcess)
+{
+    LPAPXPROCESS lpProc;
+    STARTUPINFOW si;
+    DWORD id;
+    BOOL  bS = FALSE;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    /* don't allow multiple execute calls on the same object */
+    if (lpProc->dwChildStatus & PROC_INITIALIZED)
+        return FALSE;
+    lpProc->bSaveHandles = TRUE;
+    SAVE_STD_HANDLES(lpProc);
+    if (!__apxProcCreateChildPipes(lpProc))
+        goto cleanup;
+    REDIRECT_STD_HANDLES(lpProc);
+    AplZeroMemory(&si, sizeof(STARTUPINFO));
+
+    si.cb = sizeof(STARTUPINFO);
+    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+    si.wShowWindow = SW_HIDE;
+    /* Set the redirected handles */
+    si.hStdOutput = lpProc->hChildStdOut;
+    si.hStdError  = lpProc->hChildStdErr;
+    si.hStdInput  = lpProc->hChildStdInp;  
+
+    if (lpProc->lpEnvironment)
+        FreeEnvironmentStringsW(lpProc->lpEnvironment);
+    lpProc->lpEnvironment = GetEnvironmentStringsW();
+
+    if (!IS_INVALID_HANDLE(lpProc->hUserToken)) {
+        si.lpDesktop = _desktop_name;
+        bS = CreateProcessAsUserW(lpProc->hUserToken,
+                                  lpProc->szApplicationExec,
+                                  lpProc->szCommandLine,
+                                  lpProc->lpSA,
+                                  NULL,
+                                  TRUE,
+                                  CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
+                                  lpProc->lpEnvironment,
+                                  lpProc->szWorkingPath,
+                                  &si,
+                                  &(lpProc->stProcInfo));
+    }
+    else {
+        OutputDebugStringW(lpProc->szApplicationExec);
+        OutputDebugStringW(lpProc->szCommandLine);
+
+        bS = CreateProcessW(lpProc->szApplicationExec,
+                            lpProc->szCommandLine,
+                            lpProc->lpSA,
+                            NULL,
+                            TRUE,
+                            CREATE_SUSPENDED  | CREATE_UNICODE_ENVIRONMENT | lpProc->dwOptions,
+                            lpProc->lpEnvironment,
+                            lpProc->szWorkingPath,
+                            &si,
+                            &(lpProc->stProcInfo));
+    }
+    /* Close unused sides of pipes */
+    SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);  
+    SAFE_CLOSE_HANDLE(lpProc->hChildStdOut);
+    SAFE_CLOSE_HANDLE(lpProc->hChildStdErr);
+    if (!bS)
+        goto cleanup;
+    /* Set the running flag */
+    lpProc->dwChildStatus |= (CHILD_RUNNING | PROC_INITIALIZED);
+
+    lpProc->hWorkerThreads[0] = CreateThread(NULL, 0, __apxProcStdoutThread,
+                                             hProcess, 0, &id);     
+    lpProc->hWorkerThreads[1] = CreateThread(NULL, 0, __apxProcStderrThread,
+                                             hProcess, 0, &id);     
+    ResumeThread(lpProc->stProcInfo.hThread);    
+    lpProc->hWorkerThreads[2] = CreateThread(NULL, 0, __apxProcWorkerThread,
+                                            hProcess, 0, &id);
+
+    SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hThread);
+    /* Close child handles first */
+    return TRUE;
+cleanup:
+    /* Close parent side of the pipes */    
+    SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);  
+    SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
+    SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
+
+    return FALSE;
+}
+
+BOOL
+apxProcessSetExecutableA(APXHANDLE hProcess, LPCSTR szName)
+{
+    LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szApplicationExec);
+    lpProc->szApplicationExec = apxPoolWStrdupA(hProcess->hPool, szName);
+    OutputDebugStringW(lpProc->szApplicationExec);
+    return lpProc->szApplicationExec != NULL;
+}
+
+BOOL
+apxProcessSetExecutableW(APXHANDLE hProcess, LPCWSTR szName)
+{
+    LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szApplicationExec);
+    lpProc->szApplicationExec = apxPoolStrdupW(hProcess->hPool, szName);
+    OutputDebugStringW(lpProc->szApplicationExec);
+    return lpProc->szApplicationExec != NULL;
+}
+
+BOOL
+apxProcessSetCommandLineA(APXHANDLE hProcess, LPCSTR szCmdline)
+{
+    LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szCommandLine);
+    lpProc->szCommandLine = apxPoolWStrdupA(hProcess->hPool, szCmdline);
+    
+    return lpProc->szCommandLine != NULL;
+}
+
+BOOL
+apxProcessSetCommandLineW(APXHANDLE hProcess, LPCWSTR szCmdline)
+{
+    LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szCommandLine);
+    lpProc->szCommandLine = apxPoolStrdupW(hProcess->hPool, szCmdline);
+    
+    return lpProc->szCommandLine != NULL;
+}
+
+BOOL
+apxProcessSetWorkingPathA(APXHANDLE hProcess, LPCSTR szPath)
+{
+    LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szWorkingPath);
+    lpProc->szWorkingPath = apxPoolWStrdupA(hProcess->hPool, szPath);
+    
+    return lpProc->szWorkingPath != NULL;
+}
+
+BOOL
+apxProcessSetWorkingPathW(APXHANDLE hProcess, LPCWSTR szPath)
+{
+    LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szWorkingPath);
+    if (!szPath) {
+        /* Clear the WorkingPath */
+        lpProc->szWorkingPath = NULL;
+        return TRUE;
+    }
+    lpProc->szWorkingPath = apxPoolWStrdupW(hProcess->hPool, szPath);
+    
+    return lpProc->szWorkingPath != NULL;
+}
+
+DWORD
+apxProcessPutcA(APXHANDLE hProcess, INT ch)
+{
+   LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return 0;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    return __apxProcessPutc(lpProc, ch, sizeof(CHAR));
+}
+
+DWORD
+apxProcessPutcW(APXHANDLE hProcess, INT ch)
+{
+   LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return 0;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    return __apxProcessPutc(lpProc, ch, sizeof(WCHAR));
+}
+
+DWORD
+apxProcessPutsA(APXHANDLE hProcess, LPCSTR szString)
+{
+    LPAPXPROCESS lpProc;
+    DWORD len;
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
+        return 0;
+    lpProc = APXHANDLE_DATA(hProcess);
+    len = lstrlenA(szString);
+    len = __apxProcessWrite(lpProc, szString, len);
+    if (len) {
+        FlushFileBuffers(lpProc->hChildInpWr);
+        return len;
+    }
+    else
+        return 0;
+}
+
+DWORD
+apxProcessPutsW(APXHANDLE hProcess, LPCWSTR szString)
+{
+    LPAPXPROCESS lpProc;
+    DWORD len;
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS || !szString)
+        return 0;
+    lpProc = APXHANDLE_DATA(hProcess);
+    len = lstrlenW(szString);
+    len = __apxProcessWrite(lpProc, szString, len * 2);
+    if (len) {
+        FlushFileBuffers(lpProc->hChildInpWr);
+        return (len / sizeof(WCHAR));
+    }
+    else
+        return 0;
+}
+
+DWORD
+apxProcessWrite(APXHANDLE hProcess, LPCVOID lpData, DWORD dwLen)
+{
+    LPAPXPROCESS lpProc;
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return 0;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+
+    return __apxProcessWrite(lpProc, lpData, dwLen);
+}
+
+BOOL
+apxProcessFlushStdin(APXHANDLE hProcess)
+{
+   LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    
+    if (lpProc->dwChildStatus & CHILD_RUNNING) {
+        return FlushFileBuffers(lpProc->hChildInpWr);
+    }
+    
+    return FALSE;
+}
+
+VOID
+apxProcessCloseInputStream(APXHANDLE hProcess)
+{
+   if (hProcess->dwType == APXHANDLE_TYPE_PROCESS) {
+       LPAPXPROCESS lpProc = APXHANDLE_DATA(hProcess);
+       if (lpProc->dwChildStatus & CHILD_RUNNING)
+           SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
+   }
+}
+
+DWORD
+apxProcessWait(APXHANDLE hProcess, DWORD dwMilliseconds, BOOL bKill)
+{
+   LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return WAIT_ABANDONED;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    
+    if (lpProc->dwChildStatus & CHILD_RUNNING) {
+        DWORD rv = WaitForMultipleObjects(3, lpProc->hWorkerThreads,
+                                          TRUE, dwMilliseconds);
+        if (rv == WAIT_TIMEOUT && bKill) {
+            __apxProcessCallback(hProcess, WM_CLOSE, 0, 0);
+        }
+        return rv;
+    }
+    else
+        return WAIT_OBJECT_0;
+}
+
+BOOL
+apxProcessRunning(APXHANDLE hProcess)
+{
+   LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    
+    return (lpProc->dwChildStatus & CHILD_RUNNING);    
+}
+
+static LPWSTR __apxStrQuote(LPWSTR lpDest, LPCWSTR szSrc)
+{
+    LPWSTR p;
+    BOOL   q = FALSE;
+
+    /* Find if string has embeded spaces 
+     */
+    for (p = (LPWSTR)szSrc; *p; p++) {
+        if (*p == L' ' || *p == '\t' ||
+            *p == '"' || *p == '\\') {
+            q = TRUE;
+            break;
+        }
+    }
+    p = lpDest;
+    if (q) *p++ = L'"';
+    while (*szSrc) {
+        if (*szSrc == '"' || *szSrc == '\\')
+            *p++ = L'\\';
+        *p++ = *szSrc++;
+    }
+    if (q) *p++ = L'"';
+    return p;
+}
+
+BOOL
+apxProcessSetCommandArgsW(APXHANDLE hProcess, LPCWSTR szTitle,
+                          DWORD dwArgc, LPCWSTR *lpArgs)
+{
+    LPAPXPROCESS lpProc;
+    DWORD  i, l = 0;
+    LPWSTR p;
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return FALSE;
+    
+    lpProc = APXHANDLE_DATA(hProcess);
+    apxFree(lpProc->szCommandLine);
+    
+    l = lstrlenW(szTitle) + 3;
+    for (i = 0; i < (DWORD)lstrlenW(szTitle); i++) {
+        if (szTitle[i] == L'"')
+            ++l;
+    }
+    for (i = 0; i < dwArgc; i++) {
+        int x, q = 0;
+        l += (lstrlenW(lpArgs[i]) + 3);
+        for (x = 0; x < lstrlenW(lpArgs[i]); x++) {
+            if (lpArgs[i][x] == L'"')
+                ++q;
+        }
+        l += q;
+    }
+    p = lpProc->szCommandLine = apxPoolAlloc(hProcess->hPool, l * sizeof(WCHAR));
+    p = __apxStrQuote(p, szTitle);
+    for (i = 0; i < dwArgc; i++) {
+        *p++ = L' ';
+        p = __apxStrQuote(p, lpArgs[i]);
+    }
+    *p = L'\0';
+    OutputDebugStringW(lpProc->szCommandLine);
+    return lpProc->szCommandLine != NULL;
+}
diff --git a/src/native/nt/procrun/src/service.c b/src/native/nt/procrun/src/service.c
new file mode 100644
index 0000000..3c4b3ab
--- /dev/null
+++ b/src/native/nt/procrun/src/service.c
@@ -0,0 +1,562 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+ 
+#include "apxwin.h"
+#include "private.h"
+
+#define SAFE_CLOSE_SCH(h) \
+    if ((h) != NULL && (h) != INVALID_HANDLE_VALUE) {   \
+        CloseServiceHandle((h));                        \
+        (h) = NULL;                                     \
+    }
+
+#define CHANGE_SERVICE(h, b, u, p, d)   \
+    ChangeServiceConfigW(h, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE,   \
+                         SERVICE_NO_CHANGE,b,NULL,NULL,NULL,        \
+                         u,p,d)
+
+typedef struct APXSERVICE {
+    /* Are we a service manager or we are the service itself */
+    BOOL            bManagerMode;
+    /* Handle to the current service */
+    SC_HANDLE       hService;
+    /* Handle of the Service manager */
+    SC_HANDLE       hManager;     
+    APXSERVENTRY    stServiceEntry;
+
+} APXSERVICE, *LPAPXSERVICE;
+
+static BOOL __apxIsValidServiceName(LPCWSTR szServiceName)
+{
+    do {
+        if (!IsCharAlphaNumericW(*szServiceName)) {
+            apxDisplayError(TRUE, NULL, 0, "NonAlpha %d", *szServiceName);
+            return FALSE;
+        }
+    } while( *(++szServiceName));
+    return TRUE;
+}
+
+static BOOL __apxServiceCallback(APXHANDLE hObject, UINT uMsg,
+                                 WPARAM wParam, LPARAM lParam)
+{
+    LPAPXSERVICE lpService;
+
+    lpService = APXHANDLE_DATA(hObject);
+    switch (uMsg) {
+        case WM_CLOSE:
+            apxFree(lpService->stServiceEntry.lpConfig);
+            lpService->stServiceEntry.lpConfig = NULL;
+            SAFE_CLOSE_SCH(lpService->hService);
+            SAFE_CLOSE_SCH(lpService->hManager);
+        break;
+        default:
+        break;
+    }
+    return TRUE;
+}
+
+APXHANDLE
+apxCreateService(APXHANDLE hPool, DWORD dwOptions, BOOL bManagerMode)
+{
+    APXHANDLE    hService;
+    LPAPXSERVICE lpService;
+    SC_HANDLE    hManager; 
+
+    if (!(hManager = OpenSCManager(NULL, NULL, dwOptions))) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return NULL;
+    }
+    hService = apxHandleCreate(hPool, 0,
+                               NULL, sizeof(APXSERVICE),
+                               __apxServiceCallback);
+    if (IS_INVALID_HANDLE(hService)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Failed to Create Handle for Service");
+        return NULL;
+    }
+    hService->dwType = APXHANDLE_TYPE_SERVICE;
+    lpService = APXHANDLE_DATA(hService);
+    lpService->hManager     = hManager;
+    lpService->bManagerMode = bManagerMode;
+
+    return hService;
+}
+
+BOOL
+apxServiceOpen(APXHANDLE hService, LPCWSTR szServiceName, DWORD dwOptions)
+{
+    LPAPXSERVICE lpService;
+    DWORD dwNeeded;
+
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return FALSE;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return FALSE;
+
+    /* Close any previous instance
+     * Same handle can manage multiple services
+     */
+    SAFE_CLOSE_SCH(lpService->hService);
+    *lpService->stServiceEntry.szServiceDescription = L'\0';
+    *lpService->stServiceEntry.szObjectName = L'\0';
+    apxFree(lpService->stServiceEntry.lpConfig);
+    lpService->stServiceEntry.lpConfig = NULL;
+    /* Open the service */
+    lpService->hService = OpenServiceW(lpService->hManager,
+                                       szServiceName,
+                                       dwOptions);
+
+    if (IS_INVALID_HANDLE(lpService->hService)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return FALSE;
+    }
+    lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
+    if (!apxGetServiceDescriptionW(szServiceName,
+                                   lpService->stServiceEntry.szServiceDescription,
+                                   SIZ_DESLEN)) {
+        apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service description");
+        lpService->stServiceEntry.szServiceDescription[0] = L'\0';
+    }
+    if (!apxGetServiceUserW(szServiceName,
+                            lpService->stServiceEntry.szObjectName,
+                            SIZ_RESLEN)) {
+        apxLogWrite(APXLOG_MARK_WARN "Failed obtaing service user name");
+        lpService->stServiceEntry.szObjectName[0] = L'\0';
+    }
+    if (!QueryServiceConfigW(lpService->hService, NULL, 0, &dwNeeded)) {
+        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+            apxLogWrite(APXLOG_MARK_SYSERR);
+    }
+    /* TODO: Check GetLastError  ERROR_INSUFFICIENT_BUFFER */
+    lpService->stServiceEntry.lpConfig =  (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+                                                                                dwNeeded);
+    return QueryServiceConfigW(lpService->hService,
+                               lpService->stServiceEntry.lpConfig,
+                               dwNeeded, &dwNeeded);
+}
+
+LPAPXSERVENTRY
+apxServiceEntry(APXHANDLE hService, BOOL bRequeryStatus)
+{
+    LPAPXSERVICE lpService;
+
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return NULL;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return NULL;
+
+    if (bRequeryStatus && !QueryServiceStatus(lpService->hService,
+                            &(lpService->stServiceEntry.stServiceStatus))) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return NULL;
+    }
+
+    return &lpService->stServiceEntry;
+}
+
+/* Set the service names etc... 
+ * If the ImagePath contains a space, it must be quoted
+ */
+BOOL
+apxServiceSetNames(APXHANDLE hService,
+                   LPCWSTR szImagePath,
+                   LPCWSTR szDisplayName,
+                   LPCWSTR szDescription,
+                   LPCWSTR szUsername,
+                   LPCWSTR szPassword)
+{
+    LPAPXSERVICE lpService;
+
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return FALSE;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return FALSE;
+    /* Check if the ServiceOpen has been called */
+    if (IS_INVALID_HANDLE(lpService->hService))
+        return FALSE;
+    if (szDisplayName &&!CHANGE_SERVICE(lpService->hService,
+                                        szImagePath,
+                                        szUsername,
+                                        szPassword,
+                                        szDisplayName))
+        return FALSE;
+    if (szDescription) {
+        return apxSetServiceDescriptionW(lpService->stServiceEntry.szServiceName,
+                                         szDescription);
+    }
+    return TRUE;
+}
+
+BOOL
+apxServiceSetOptions(APXHANDLE hService,
+                     DWORD dwServiceType,
+                     DWORD dwStartType,
+                     DWORD dwErrorControl)
+{
+    LPAPXSERVICE lpService;
+
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return FALSE;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return FALSE;
+    /* Check if the ServixeOpen has been called */
+    if (IS_INVALID_HANDLE(lpService->hService))
+        return FALSE;
+    return ChangeServiceConfig(lpService->hService, dwServiceType,
+                               dwStartType, dwErrorControl,
+                               NULL, NULL, NULL, NULL, NULL,
+                               NULL, NULL);
+}
+
+BOOL
+apxServiceControl(APXHANDLE hService, DWORD dwControl, UINT uMsg,
+                  LPAPXFNCALLBACK fnControlCallback,
+                  LPVOID lpCbData)
+{
+    LPAPXSERVICE   lpService;
+    SERVICE_STATUS stStatus;
+    DWORD          dwPending = 0;
+    DWORD          dwState = 0;
+    DWORD          dwTick  = 0;
+    DWORD          dwWait, dwCheck, dwStart;
+    BOOL           bStatus;
+
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return FALSE;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return FALSE;
+    /* Check if the ServixeOpen has been called */
+    if (IS_INVALID_HANDLE(lpService->hService))
+        return FALSE;
+    switch (dwControl) {
+        case SERVICE_CONTROL_CONTINUE:
+            dwPending = SERVICE_START_PENDING;
+            dwState   = SERVICE_RUNNING;
+            break;
+        case SERVICE_CONTROL_STOP:
+            dwPending = SERVICE_STOP_PENDING;
+            dwState   = SERVICE_STOPPED;
+            break;
+        case SERVICE_CONTROL_PAUSE:
+            dwPending = SERVICE_PAUSE_PENDING;
+            dwState   = SERVICE_PAUSED;
+            break;
+        default:
+            break;
+    }
+    /* user defined controls */
+    if (dwControl > 127 && dwControl < 224) {
+        /* 128 ... 159  start signals
+         * 160 ... 191  stop signals
+         * 192 ... 223  pause signals
+         */
+        switch (dwControl & 0xE0) {
+            case 0x80:
+            case 0x90:
+                dwPending = SERVICE_START_PENDING;
+                dwState   = SERVICE_RUNNING;
+                break;
+            case 0xA0:
+            case 0xB0:
+                dwPending = SERVICE_STOP_PENDING;
+                dwState   = SERVICE_STOPPED;
+                break;
+            case 0xC0:
+            case 0xD0:
+                dwPending = SERVICE_PAUSE_PENDING;
+                dwState   = SERVICE_PAUSED;
+                break;
+            default:
+                break;
+        }     
+    }
+    if (!dwPending && !dwState)
+        return FALSE;
+    /* Now lets control */
+    if (!QueryServiceStatus(lpService->hService, &stStatus)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+        return FALSE;
+    }
+    /* signal that we are about to control the service */
+    if (fnControlCallback)
+        (*fnControlCallback)(lpCbData, uMsg, (WPARAM)1, (LPARAM)dwState);
+    if (dwControl == SERVICE_CONTROL_CONTINUE && 
+        stStatus.dwCurrentState != SERVICE_PAUSED)
+        bStatus = StartService(lpService->hService, 0, NULL);
+    else
+        bStatus = ControlService(lpService->hService, dwControl, &stStatus);
+    dwStart = GetTickCount();
+    dwCheck = stStatus.dwCheckPoint;
+    if (bStatus) {
+        Sleep(100); /* Initial Sleep period */
+        while (QueryServiceStatus(lpService->hService, &stStatus)) {
+            if (stStatus.dwCurrentState == dwPending) {
+                /* Do not wait longer than the wait hint. A good interval is 
+                 * one tenth the wait hint, but no less than 1 second and no 
+                 * more than 10 seconds. 
+                 */
+                dwWait = stStatus.dwWaitHint / 10;
+
+                if( dwWait < 1000 )
+                    dwWait = 1000;
+                else if ( dwWait > 10000 )
+                    dwWait = 10000;
+                /* Signal to the callback that we are pending
+                 * break if callback returns false.
+                 */
+                if (fnControlCallback) {
+                    if (!(*fnControlCallback)(lpCbData, uMsg, (WPARAM)2,
+                                              (LPARAM)dwTick++))
+                        break;
+                }
+                Sleep(dwWait);
+                if (stStatus.dwCheckPoint > dwCheck) {
+                    /* The service is making progress. */
+                    dwStart = GetTickCount();
+                    dwCheck = stStatus.dwCheckPoint;
+                }
+                else {
+                    if(GetTickCount() - dwStart > stStatus.dwWaitHint) {
+                        /* No progress made within the wait hint */
+                        break;
+                    }
+                }
+            }
+            else
+                break;
+        }         
+    }
+    /* signal that we are done with controling the service */
+    if (fnControlCallback)
+        (*fnControlCallback)(lpCbData, uMsg, (WPARAM)3, (LPARAM)0);
+    /* Check if we are in the desired state */
+    Sleep(1000);
+
+    if (QueryServiceStatus(lpService->hService, &stStatus)) {
+        if (fnControlCallback)
+            (*fnControlCallback)(lpCbData, uMsg, (WPARAM)4,
+                                 (LPARAM)&stStatus);
+        if (stStatus.dwCurrentState == dwState)
+            return TRUE;
+
+    }
+
+    return FALSE;
+}
+
+BOOL
+apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
+                  LPCWSTR szDisplayName, LPCWSTR szImagePath,
+                  LPCWSTR lpDependencies, DWORD dwServiceType,
+                  DWORD dwStartType)
+{
+    LPAPXSERVICE   lpService;
+
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return FALSE;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return FALSE;
+    if (IS_INVALID_HANDLE(lpService->hManager))
+        return FALSE;
+    if (!__apxIsValidServiceName(szServiceName))
+        return FALSE;
+    /* Close any previous instance
+     * Same handle can install multiple services
+     */
+    SAFE_CLOSE_SCH(lpService->hService);
+
+    apxFree(lpService->stServiceEntry.lpConfig);
+    lpService->stServiceEntry.lpConfig = NULL;
+    AplZeroMemory(&lpService->stServiceEntry, sizeof(APXSERVENTRY));
+
+    lpService->hService = CreateServiceW(lpService->hManager,
+                                         szServiceName,
+                                         szDisplayName,
+                                         SERVICE_ALL_ACCESS,
+                                         dwServiceType,
+                                         dwStartType,
+                                         SERVICE_ERROR_NORMAL,
+                                         szImagePath,
+                                         NULL,
+                                         NULL,
+                                         lpDependencies,
+                                         NULL,
+                                         NULL);
+
+    if (IS_INVALID_HANDLE(lpService->hService)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+
+        ErrorMessage(NULL, FALSE);
+        return FALSE;
+    }
+    else {
+        lstrcpyW(lpService->stServiceEntry.szServiceName, szServiceName);
+        lpService->stServiceEntry.dwStart = dwStartType;
+        return TRUE;
+    }
+}
+
+BOOL
+apxServiceDelete(APXHANDLE hService)
+{
+    LPAPXSERVICE   lpService;
+    SERVICE_STATUS stStatus;
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE)
+        return FALSE;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Manager mode cannot handle services */
+    if (lpService->bManagerMode)
+        return FALSE;
+    /* Check if the ServiceOpen has been called */
+    if (IS_INVALID_HANDLE(lpService->hService))
+        return FALSE;
+    if (QueryServiceStatus(lpService->hService, &stStatus)) {
+        BOOL rv;
+        if (stStatus.dwCurrentState != SERVICE_STOPPED)
+            apxServiceControl(hService, SERVICE_CONTROL_STOP, 0, NULL, NULL);
+        rv = DeleteService(lpService->hService);
+        SAFE_CLOSE_SCH(lpService->hService);
+        SAFE_CLOSE_SCH(lpService->hManager);
+     
+        return rv;
+    }
+    return FALSE;
+}
+
+/* Browse the services */
+DWORD
+apxServiceBrowse(APXHANDLE hService, 
+                 LPCWSTR szIncludeNamePattern,
+                 LPCWSTR szIncludeImagePattern,
+                 LPCWSTR szExcludeNamePattern,
+                 LPCWSTR szExcludeImagePattern,
+                 UINT uMsg,
+                 LPAPXFNCALLBACK fnDisplayCallback,
+                 LPVOID lpCbData)
+{
+    DWORD        nFound = 0;
+    APXREGENUM   stEnum;
+    LPAPXSERVICE lpService;
+    SC_LOCK      hLock;
+    if (hService->dwType != APXHANDLE_TYPE_SERVICE || !fnDisplayCallback)
+        return 0;
+
+    lpService = APXHANDLE_DATA(hService);
+    /* Only the manager mode can browse services */
+    if (!lpService->bManagerMode ||
+        IS_INVALID_HANDLE(lpService->hManager))
+        return 0;
+    hLock = LockServiceDatabase(lpService->hManager);
+    if (IS_INVALID_HANDLE(hLock)) {
+        apxLogWrite(APXLOG_MARK_SYSERR);
+
+        ErrorMessage(NULL, FALSE);
+        return 0;
+    }
+    AplZeroMemory(&stEnum, sizeof(APXREGENUM));
+
+    while (TRUE) {
+        APXSERVENTRY stEntry;
+        BOOL rv;
+        AplZeroMemory(&stEntry, sizeof(APXSERVENTRY));
+        rv = apxRegistryEnumServices(&stEnum, &stEntry);
+
+        if (rv) {
+            INT fm = -1;
+            SC_HANDLE hSrv = NULL;
+            DWORD dwNeeded = 0;
+            hSrv = OpenServiceW(lpService->hManager,
+                                stEntry.szServiceName,
+                                GENERIC_READ);
+            if (!IS_INVALID_HANDLE(hSrv)) {
+                QueryServiceConfigW(hSrv, NULL, 0, &dwNeeded);
+                stEntry.lpConfig = (LPQUERY_SERVICE_CONFIGW)apxPoolAlloc(hService->hPool,
+                                                                         dwNeeded);
+                /* Call the QueryServiceConfig againg with allocated config */
+                if (QueryServiceConfigW(hSrv, stEntry.lpConfig, dwNeeded, &dwNeeded)) {
+                    /* Make that customizable so that kernel mode drivers can be
+                     * displayed and maintained. For now skip the
+                     * filesystem and device drivers.
+                     * XXX: Do we need that customizable after all?
+                     */
+                    if ((stEntry.lpConfig->dwServiceType &
+                         ~SERVICE_INTERACTIVE_PROCESS) & SERVICE_WIN32)
+                        fm = 0;
+
+                    if (!fm && szIncludeNamePattern) {
+                        fm = apxMultiStrMatchW(stEntry.szServiceName,
+                                               szIncludeNamePattern, L';', TRUE);
+                    }
+                    if (!fm && szExcludeNamePattern) {
+                        fm = !apxMultiStrMatchW(stEntry.szServiceName,
+                                                szExcludeNamePattern, L';', TRUE);
+                    }
+                    if (!fm && szIncludeImagePattern) {
+                        fm = apxMultiStrMatchW(stEntry.lpConfig->lpBinaryPathName,
+                                               szIncludeImagePattern, L';', TRUE);
+                    }
+                    if (!fm && szExcludeImagePattern) {
+                        fm = !apxMultiStrMatchW(stEntry.szServiceName,
+                                                szExcludeImagePattern, L';', TRUE);
+                    }
+                    if (!fm) {
+                        QueryServiceStatus(hSrv, &(stEntry.stServiceStatus));
+                        /* WIN2K + extended service info */
+                        if (_st_apx_oslevel >= 4) {
+                            DWORD dwNeed;
+                            QueryServiceStatusEx(hSrv, SC_STATUS_PROCESS_INFO,
+                                                 (LPBYTE)(&(stEntry.stStatusProcess)), 
+                                                 sizeof(SERVICE_STATUS_PROCESS),
+                                                 &dwNeed);
+                        }
+                        /* finaly call the provided callback */
+                        rv = (*fnDisplayCallback)(lpCbData, uMsg,
+                                                  (WPARAM)&stEntry,
+                                                  (LPARAM)nFound++);
+                    }
+                }
+                /* release the skipped service config */
+                if (fm) {
+                    apxFree(stEntry.lpConfig);
+                }
+            }
+            SAFE_CLOSE_SCH(hSrv);
+        }
+        if (!rv)
+            break;
+    }
+
+    UnlockServiceDatabase(hLock);
+    return nFound;
+}
diff --git a/src/native/nt/procrun/src/utils.c b/src/native/nt/procrun/src/utils.c
new file mode 100644
index 0000000..7692261
--- /dev/null
+++ b/src/native/nt/procrun/src/utils.c
@@ -0,0 +1,946 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+#include "apxwin.h"
+#include "private.h"
+
+APX_OSLEVEL _st_apx_oslevel = APX_WINVER_UNK;
+
+/* Apache's APR stripped Os level detection */
+APX_OSLEVEL apxGetOsLevel()
+{
+    if (_st_apx_oslevel == APX_WINVER_UNK) {
+        static OSVERSIONINFO oslev;
+        oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+        GetVersionEx(&oslev);
+
+        if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+            if (oslev.dwMajorVersion < 4)
+                _st_apx_oslevel = APX_WINVER_UNSUP;
+            else if (oslev.dwMajorVersion == 4)
+               _st_apx_oslevel = APX_WINVER_NT_4;
+            else if (oslev.dwMajorVersion == 5) {
+                if (oslev.dwMinorVersion == 0)
+                    _st_apx_oslevel = APX_WINVER_2000;
+                else
+                    _st_apx_oslevel = APX_WINVER_XP;
+            }
+            else
+                _st_apx_oslevel = APX_WINVER_XP;
+        }
+#ifndef WINNT
+        else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+            if (oslev.dwMinorVersion < 10)
+                _st_apx_oslevel = APX_WINVER_95;
+            else if (oslev.dwMinorVersion < 90)
+                _st_apx_oslevel = APX_WINVER_98;
+            else
+                _st_apx_oslevel = APX_WINVER_ME;
+        }
+#endif
+#ifdef _WIN32_WCE
+        else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE) {
+            if (oslev.dwMajorVersion < 3)
+                _st_apx_oslevel = APX_WINVER_UNSUP;
+            else
+                _st_apx_oslevel = APX_WINVER_CE_3;
+        }
+#endif
+        else
+            _st_apx_oslevel = APX_WINVER_UNSUP;
+    }
+
+    if (_st_apx_oslevel < APX_WINVER_UNSUP)
+        return APX_WINVER_UNK;
+    else
+        return _st_apx_oslevel;
+}
+
+LPWSTR __apxGetEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName)
+{
+    LPWSTR wsRet;
+    DWORD  rc;
+
+    rc = GetEnvironmentVariableW(wsName, NULL, 0);
+    if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+        return NULL;
+    
+    if (!(wsRet = apxPoolAlloc(hPool, (rc + 1) * sizeof(WCHAR))))
+        return NULL;
+    if (!GetEnvironmentVariableW(wsName, wsRet, rc)) {
+        apxFree(wsRet);
+        ErrorMessage(NULL, FALSE);
+        return NULL;
+    }
+    return wsRet;
+}
+
+LPSTR __apxGetEnvironmentVariableA(APXHANDLE hPool, LPCSTR szName)
+{
+    LPSTR szRet;
+    DWORD rc;
+
+    rc = GetEnvironmentVariableA(szName, NULL, 0);
+    if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+        return NULL;
+    
+    if (!(szRet = apxPoolAlloc(hPool, rc + 1)))
+        return NULL;
+    if (!GetEnvironmentVariableA(szName, szRet, rc)) {
+        apxFree(szRet);
+        ErrorMessage(NULL, FALSE);
+        return NULL;
+    }
+    return szRet;
+}
+
+
+LPWSTR AsciiToWide(LPCSTR s, LPWSTR ws)
+{
+    LPWSTR pszSave = ws;
+
+    if (!s) {
+        *ws = L'\0';
+        return pszSave;
+    }
+    do {
+        *ws++ = (WCHAR)*s;
+    } while (*s++);
+    return pszSave;
+}
+
+LPSTR WideToAscii(LPCWSTR ws, LPSTR s)
+{
+    LPSTR pszSave = s;
+
+    if (!ws) {
+        *s = '\0';
+        return pszSave;
+    }
+    do {
+        *s++ = (CHAR)*ws;
+    } while( *ws++);
+    return pszSave;
+}
+
+LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s)
+{
+    LPSTR pszSave = s;
+
+    if (ws) {
+        do {
+            *s++ = (CHAR)*ws;
+            ws++;
+        } while( *ws || *(ws + 1));
+    }
+    /* double terminate */
+    *s++ = '\0';
+    *s   = '\0';
+    return pszSave;
+}
+
+#ifdef _DEBUG
+
+void ErrorMessage(LPCTSTR szError, BOOL bFatal)
+{
+    LPVOID lpMsgBuf = NULL;
+    UINT   nType;
+    int    nRet;
+    DWORD  dwErr = GetLastError();
+    if (bFatal)
+        nType = MB_ICONERROR | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL;
+    else
+        nType = MB_ICONEXCLAMATION | MB_OK;
+    if (szError) {
+        nRet = MessageBox(NULL, szError, TEXT("Application Error"), nType);
+    }
+    else {
+        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                      FORMAT_MESSAGE_FROM_SYSTEM |
+                      FORMAT_MESSAGE_IGNORE_INSERTS,
+                      NULL, 
+                      dwErr, 
+                      MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
+                      (LPTSTR) &lpMsgBuf, 0, NULL);
+        nRet = MessageBox(NULL, (LPCTSTR)lpMsgBuf, 
+                          TEXT("Application System Error"), nType);
+        LocalFree(lpMsgBuf);
+    }
+    if (bFatal && (nRet == IDCANCEL || nRet == IDABORT)) {
+        ExitProcess(dwErr);
+    }
+} 
+#endif /* _DEBUG */
+
+DWORD __apxGetMultiSzLengthA(LPCSTR lpStr, LPDWORD lpdwCount)
+{
+    LPCSTR p = lpStr;
+    if (lpdwCount)
+        *lpdwCount = 0;
+    for ( ; p && *p; p++) {
+        if (lpdwCount)
+            *lpdwCount += 1;
+        while (*p)
+            p++;
+    }
+    return (DWORD)(p - lpStr);
+}
+
+DWORD __apxGetMultiSzLengthW(LPCWSTR lpStr, LPDWORD lpdwCount)
+{
+    LPCWSTR p = lpStr;
+    if (lpdwCount)
+        *lpdwCount = 0;
+    for ( ; p && *p; p++) {
+        if (lpdwCount)
+            *lpdwCount += 1;
+        while (*p)
+            p++;
+    }
+    return (DWORD)((p - lpStr));
+}
+
+LPWSTR apxMultiSzCombine(APXHANDLE hPool, LPCWSTR lpStrA, LPCWSTR lpStrB,
+                         LPDWORD lpdwLength)
+{
+    LPWSTR rv;
+    DWORD  la = 0, lb = 0;
+    if (!lpStrA && !lpStrB)
+        return NULL;    /* Nothing to do if both are NULL */
+    
+    la = __apxGetMultiSzLengthW(lpStrA, NULL);
+    lb = __apxGetMultiSzLengthW(lpStrB, NULL);
+    
+    rv = apxPoolCalloc(hPool, (la + lb + 1) * sizeof(WCHAR));
+    if (la) {
+        AplMoveMemory(rv, lpStrA, la * sizeof(WCHAR));
+    }
+    if (lb) {
+        AplMoveMemory(&rv[la], lpStrB, lb * sizeof(WCHAR));
+    }
+    if (*lpdwLength)
+        *lpdwLength = (la + lb + 1) * sizeof(WCHAR);
+    return rv;
+}
+
+BOOL
+apxSetEnvironmentVariable(APXHANDLE hPool, LPCTSTR szName, LPCTSTR szValue,
+                          BOOL bAppend)
+{
+    LPTSTR szNew = (LPTSTR)szValue;
+
+    if (bAppend) {
+        DWORD l = GetEnvironmentVariable(szName, NULL, 0);
+        if (l > 0) {
+            BOOL rv;
+            if (IS_INVALID_HANDLE(hPool))
+                szNew = apxAlloc(l + lstrlen(szValue) + 3);
+            else
+                szNew = apxPoolAlloc(hPool, l + lstrlen(szValue) + 3);
+            GetEnvironmentVariable(szName, szNew, l + 1);
+            lstrcat(szNew, TEXT(";"));
+            lstrcat(szNew, szValue);
+            rv = SetEnvironmentVariable(szName, szNew);
+            apxFree(szNew);
+            return rv;
+        }
+    }
+    return SetEnvironmentVariable(szName, szNew);
+}
+
+
+/** Convert null separated double null terimated string to LPTSTR array)
+ * returns array size
+ */
+DWORD
+apxMultiSzToArrayW(APXHANDLE hPool, LPCWSTR lpString, LPWSTR **lppArray)
+{
+    DWORD i, n, l;
+    char *buff;
+    LPWSTR p;
+
+    l = __apxGetMultiSzLengthW(lpString, &n);
+    if (!n || !l)
+        return 0;
+    if (IS_INVALID_HANDLE(hPool))
+        buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
+    else
+        buff = apxAlloc((n + 2) * sizeof(LPWSTR) + (l + 1) * sizeof(WCHAR));
+
+    *lppArray = (LPWSTR *)buff;
+    p = (LPWSTR)(buff + (n + 2) * sizeof(LPWSTR));
+    AplCopyMemory(p, lpString, (l + 1) * sizeof(WCHAR) + sizeof(WCHAR));
+    for (i = 0; i < n; i++) {
+        (*lppArray)[i] = p;
+        while (*p)
+            p++;
+        p++;
+    }
+    (*lppArray)[++i] = NULL;
+    
+    return n;
+}
+
+DWORD
+apxMultiSzToArrayA(APXHANDLE hPool, LPCSTR lpString, LPSTR **lppArray)
+{
+    DWORD i, n, l;
+    char *buff;
+    LPSTR p;
+
+    l = __apxGetMultiSzLengthA(lpString, &n);
+    if (!n || !l)
+        return 0;
+    if (IS_INVALID_HANDLE(hPool))
+        buff = apxPoolAlloc(hPool, (n + 2) * sizeof(LPTSTR) + (l + 1));
+    else
+        buff = apxAlloc((n + 2) * sizeof(LPSTR) + (l + 1) * sizeof(CHAR));
+
+    *lppArray = (LPSTR *)buff;
+    p = (LPSTR)(buff + (n + 2) * sizeof(LPSTR));
+    AplCopyMemory(p, lpString, (l + 1) * sizeof(CHAR) + sizeof(CHAR));
+    for (i = 0; i < n; i++) {
+        (*lppArray)[i] = p;
+        while (*p)
+            p++;
+        p++;
+    }
+    (*lppArray)[++i] = NULL;
+    
+    return n;
+}
+
+#define QSTR_BOUNDARY 127
+#define QSTR_ALIGN(size) \
+    (((size) + QSTR_BOUNDARY + sizeof(APXMULTISZ) + 2) & ~(QSTR_BOUNDARY))
+
+#define QSTR_SIZE(size) \
+    ((QSTR_ALIGN(size)) - sizeof(APXMULTISZ))
+
+#define QSTR_DATA(q)    ((char *)(q) + sizeof(APXMULTISZ))
+
+#if 0
+LPAPXMULTISZ apxMultiSzStrdup(LPCTSTR szSrc)
+{
+    LPAPXMULTISZ q;
+
+    if (szSrc) {
+        DWORD l = lstrlen(szSrc);
+        q = (LPAPXMULTISZ)apxAlloc(QSTR_ALIGN(l));
+        q->dwAllocated = QSTR_SIZE(l);
+        q->dwInsert    = l + 1;
+        AplMoveMemory(QSTR_DATA(q), szSrc, l);
+        RtlZeroMemory(QSTR_DATA(q) + l, q->dwAllocated - l);
+    }
+    else {
+        q = (LPAPXMULTISZ)apxCalloc(QSTR_ALIGN(0));
+        q->dwAllocated = QSTR_SIZE(0);
+    }
+
+    return q;
+}
+
+LPTSTR  apxMultiSzStrcat(LPAPXMULTISZ lpmSz, LPCTSTR szSrc)
+{
+    DWORD l = lstrlen(szSrc);
+    LPTSTR p;
+    
+    if (lpmSz->dwInsert + l + 2 > lpmSz->dwAllocated) {
+        if ((lpmSz = (LPAPXMULTISZ )apxRealloc(lpmSz, QSTR_ALIGN(lpmSz->dwInsert + l))) == NULL)
+            return NULL;
+
+        lpmSz->dwAllocated = QSTR_SIZE(lpmSz->dwInsert + l);
+        AplZeroMemory(QSTR_DATA(lpmSz) + lpmSz->dwInsert + l,
+                   lpmSz->dwAllocated - (lpmSz->dwInsert + l));
+    }
+    p = (LPTSTR)QSTR_DATA(lpmSz) + lpmSz->dwInsert;
+    AplMoveMemory(p, szSrc, l);
+
+    lpmSz->dwInsert += (l + 1);
+    return p;
+}
+
+DWORD apxMultiSzLen(LPAPXMULTISZ lpmSz)
+{
+    if (lpmSz->dwInsert)
+        return lpmSz->dwInsert - 1;
+    else
+        return 0;
+}
+
+LPCTSTR apxMultiSzGet(LPAPXMULTISZ lpmSz)
+{
+    return (LPCTSTR)QSTR_DATA(lpmSz);
+}
+#endif
+
+LPTSTR apxStrCharRemove(LPTSTR szString, TCHAR chSkip) 
+{
+  LPTSTR p = szString;
+  LPTSTR q = szString;
+  while (*p) {
+    if(*p != chSkip)
+      *q++ = *p;
+    ++p;
+  }
+  *q = TEXT('\0');
+
+  return szString;
+} 
+
+DWORD apxStrCharRemoveA(LPSTR szString, CHAR chSkip) 
+{
+  LPSTR p = szString;
+  LPSTR q = szString;
+  DWORD c = 0;
+  while (*p) {
+    if(*p != chSkip)
+      *q++ = *p;
+    else
+        ++c;
+    ++p;
+  }
+  *q = '\0';
+
+  return c;
+} 
+
+DWORD apxStrCharRemoveW(LPWSTR szString, WCHAR chSkip) 
+{
+  LPWSTR p = szString;
+  LPWSTR q = szString;
+  DWORD  c = 0;
+  while (*p) {
+    if(*p != chSkip)
+      *q++ = *p;
+    else
+        ++c;
+    ++p;
+  }
+  *q = L'\0';
+
+  return c;
+} 
+
+void
+apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith) 
+{
+  LPSTR p = szString;
+  LPSTR q = szString;
+  while (*p) {
+    if(*p == chReplace)
+      *q++ = chReplaceWith;
+    else 
+      *q++ = *p;
+    ++p;
+  }
+  *q = '\0';
+} 
+
+void
+apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith) 
+{
+  LPWSTR p = szString;
+  LPWSTR q = szString;
+  while (*p) {
+    if(*p == chReplace)
+      *q++ = chReplaceWith;
+    else 
+      *q++ = *p;
+    ++p;
+  }
+  *q = L'\0';
+} 
+
+static const LPCTSTR _st_hex = TEXT("0123456789abcdef");
+#define XTOABUFFER_SIZE (sizeof(ULONG) * 2 + 2)
+#define UTOABUFFER_SIZE (sizeof(ULONG_PTR) * 2 + 2)
+#define LO_NIBLE(x)     ((BYTE)((x) & 0x0000000F))
+
+BOOL apxUltohex(ULONG n, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+    LPTSTR p;
+    DWORD  i;
+    *lpBuff = 0;
+    if (dwBuffLength < XTOABUFFER_SIZE)
+        return FALSE;
+    p = lpBuff + XTOABUFFER_SIZE;
+    *p-- = 0;
+    for (i = 0; i < sizeof(ULONG) * 2; i++) {
+        *p-- = _st_hex[LO_NIBLE(n)];
+        n = n >> 4;
+    }
+    *p-- = TEXT('x');
+    *p = TEXT('0');
+    return TRUE;
+}
+
+BOOL apxUptohex(ULONG_PTR n, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+    LPTSTR p;
+    DWORD  i;
+    *lpBuff = 0;
+    if (dwBuffLength < UTOABUFFER_SIZE)
+        return FALSE;
+    p = lpBuff + UTOABUFFER_SIZE;
+    *p-- = 0;
+    for (i = 0; i < sizeof(ULONG_PTR) * 2; i++) {
+        *p-- = _st_hex[LO_NIBLE(n)];
+        n = n >> 4;
+    }
+    *p-- = TEXT('x');
+    *p = TEXT('0');
+    return TRUE;
+}
+
+ULONG apxStrToul(LPCTSTR szNum) 
+{
+    ULONG rv = 0;
+    DWORD sh = 0;
+    LPCTSTR p = szNum;
+    ++p;
+    while (*p && (*p != TEXT('x')) && (*(p - 1) != TEXT('0')))
+        p++;
+    if (*p != 'x')
+        return 0;
+    /* go to the last digit */
+    while (*(p + 1)) p++;
+    
+    /* go back to 'x' */
+    while (*p != TEXT('x')) {
+        ULONG v = 0;
+        switch (*p--) {
+            case TEXT('0'): v = 0UL; break;
+            case TEXT('1'): v = 1UL; break;
+            case TEXT('2'): v = 2UL; break;
+            case TEXT('3'): v = 3UL; break;
+            case TEXT('4'): v = 4UL; break;
+            case TEXT('5'): v = 5UL; break;
+            case TEXT('6'): v = 6UL; break;
+            case TEXT('7'): v = 7UL; break;
+            case TEXT('8'): v = 8UL; break;
+            case TEXT('9'): v = 9UL; break;
+            case TEXT('a'): case TEXT('A'): v = 10UL; break;
+            case TEXT('b'): case TEXT('B'): v = 11UL; break;
+            case TEXT('c'): case TEXT('C'): v = 12UL; break;
+            case TEXT('d'): case TEXT('D'): v = 13UL; break;
+            case TEXT('e'): case TEXT('E'): v = 14UL; break;
+            case TEXT('f'): case TEXT('F'): v = 15UL; break;
+            default: 
+                return 0; 
+            break;
+        }
+        rv |= rv + (v << sh);
+        sh += 4;
+    }
+    return rv;
+}
+
+ULONG apxStrToulW(LPCWSTR szNum) 
+{
+    ULONG rv = 0;
+    DWORD sh = 0;
+    LPCWSTR p = szNum;
+    ++p;
+    while (*p && (*p != L'x') && (*(p - 1) != L'0'))
+        p++;
+    if (*p != L'x')
+        return 0;
+    /* go to the last digit */
+    while (*(p + 1)) p++;
+    
+    /* go back to 'x' */
+    while (*p != L'x') {
+        ULONG v = 0;
+        switch (*p--) {
+            case L'0': v = 0UL; break;
+            case L'1': v = 1UL; break;
+            case L'2': v = 2UL; break;
+            case L'3': v = 3UL; break;
+            case L'4': v = 4UL; break;
+            case L'5': v = 5UL; break;
+            case L'6': v = 6UL; break;
+            case L'7': v = 7UL; break;
+            case L'8': v = 8UL; break;
+            case L'9': v = 9UL; break;
+            case L'a': case L'A': v = 10UL; break;
+            case L'b': case L'B': v = 11UL; break;
+            case L'c': case L'C': v = 12UL; break;
+            case L'd': case L'D': v = 13UL; break;
+            case L'e': case L'E': v = 14UL; break;
+            case L'f': case L'F': v = 15UL; break;
+            default: 
+                return 0; 
+            break;
+        }
+        rv |= rv + (v << sh);
+        sh += 4;
+    }
+    return rv;
+}
+
+ULONG apxAtoulW(LPCWSTR szNum) 
+{
+    ULONG rv = 0;
+    DWORD sh = 1;
+    int   s  = 1;
+    LPCWSTR p = szNum;
+
+    /* go to the last digit */
+    if (!p || !*p)
+        return 0;
+    if (*p == L'-') {
+        s = -1;
+        ++p;
+    }
+    while (*(p + 1)) p++;
+    
+    /* go back */
+    while (p >= szNum) {
+        ULONG v = 0;
+        switch (*p--) {
+            case L'0': v = 0UL; break;
+            case L'1': v = 1UL; break;
+            case L'2': v = 2UL; break;
+            case L'3': v = 3UL; break;
+            case L'4': v = 4UL; break;
+            case L'5': v = 5UL; break;
+            case L'6': v = 6UL; break;
+            case L'7': v = 7UL; break;
+            case L'8': v = 8UL; break;
+            case L'9': v = 9UL; break;
+            default: 
+                return rv * s; 
+            break;
+        }
+        rv = rv + (v * sh);
+        sh = sh * 10;
+    }
+    return rv * s;
+}
+
+/* Make the unique system resource name from prefix and process id 
+ * 
+ */
+BOOL
+apxMakeResourceName(LPCTSTR szPrefix, LPTSTR lpBuff, DWORD dwBuffLength)
+{
+    DWORD pl = lstrlen(szPrefix);        
+    if (dwBuffLength < (pl + 11))
+        return FALSE;
+    lstrcpy(lpBuff, szPrefix);
+    return apxUltohex(GetCurrentProcessId(), lpBuff + pl, dwBuffLength - pl);
+}
+/** apxStrMatchA ANSI string pattern matching
+ * Match = 0, NoMatch = 1, Abort = -1
+ * Based loosely on sections of wildmat.c by Rich Salz
+ */
+INT apxStrMatchA(LPCSTR szString, LPCSTR szPattern, BOOL bIgnoreCase)
+{
+    int x, y;
+
+    for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
+        if (!szPattern[x] && (szPattern[y] != '*' || szPattern[y] != '?'))
+            return -1;
+        if (szPattern[y] == '*') {
+            while (szPattern[++y] == '*');
+            if (!szPattern[y])
+                return 0;
+            while (szString[x]) {
+                INT rc;
+                if ((rc = apxStrMatchA(&szString[x++], &szPattern[y],
+                                       bIgnoreCase)) != 1)
+                    return rc;
+            }
+            return -1;
+        }
+        else if (szPattern[y] != '?') {
+            if (bIgnoreCase) {
+                if (CharLowerA((LPSTR)((SIZE_T)szString[x])) !=
+                    CharLowerA((LPSTR)((SIZE_T)szPattern[y])))
+                    return 1;
+            }
+            else {
+                if (szString[x] != szPattern[y])
+                    return 1;
+            }
+        }
+    }
+    return (szString[x] != '\0');
+} 
+
+INT apxStrMatchW(LPCWSTR szString, LPCWSTR szPattern, BOOL bIgnoreCase)
+{
+    int x, y;
+
+    for (x = 0, y = 0; szPattern[y]; ++y, ++x) {
+        if (!szPattern[x] && (szPattern[y] != L'*' || szPattern[y] != L'?'))
+            return -1;
+        if (szPattern[y] == L'*') {
+            while (szPattern[++y] == L'*');
+            if (!szPattern[y])
+                return 0;
+            while (szString[x]) {
+                INT rc;
+                if ((rc = apxStrMatchW(&szString[x++], &szPattern[y],
+                                       bIgnoreCase)) != 1)
+                    return rc;
+            }
+            return -1;
+        }
+        else if (szPattern[y] != L'?') {
+            if (bIgnoreCase) {
+                if (CharLowerW((LPWSTR)((SIZE_T)szString[x])) !=
+                    CharLowerW((LPWSTR)((SIZE_T)szPattern[y])))
+                    return 1;
+            }
+            else {
+                if (szString[x] != szPattern[y])
+                    return 1;
+            }
+        }
+    }
+    return (szString[x] != L'\0');
+} 
+
+INT apxMultiStrMatchW(LPCWSTR szString, LPCWSTR szPattern,
+                      WCHAR chSeparator, BOOL bIgnoreCase)
+{
+    WCHAR szM[SIZ_HUGLEN];
+    DWORD i = 0;
+    LPCWSTR p = szPattern;
+    INT   m = -1;
+
+    if (chSeparator == 0)
+        return apxStrMatchW(szString, szPattern, bIgnoreCase);
+    while (*p != L'\0') {
+        if (*p == chSeparator) {
+            m = apxStrMatchW(szString, szM, bIgnoreCase);
+            if (m == 0)
+                return 0;
+            p++;
+            i = 0;
+            szM[0] = L'\0';
+        }
+        else {
+            if (i < SIZ_HUGMAX)
+                szM[i++] = *p++;
+            else
+                return -1;
+        }
+    }
+    szM[i] = L'\0';
+    if (szM[0])
+        return apxStrMatchW(szString, szM, bIgnoreCase);
+    else
+        return m;
+}
+
+LPSTR apxArrayToMultiSzA(APXHANDLE hPool, DWORD nArgs, LPCSTR *lpArgs)
+{
+    DWORD  i, l = 0;
+    LPSTR lpSz, p;
+    if (!nArgs)
+        return NULL;
+    for (i = 0; i < nArgs; i++)
+        l += lstrlenA(lpArgs[i]);
+    l += (nArgs + 2);
+
+    p = lpSz = (LPSTR)apxPoolAlloc(hPool, l);
+    for (i = 0; i < nArgs; i++) {
+        lstrcpyA(p, lpArgs[i]);
+        p += lstrlenA(lpArgs[i]);
+        *p++ = '\0';
+    }
+    *p++ = '\0';
+    *p++ = '\0';
+    return lpSz;
+}
+
+void apxStrQuoteInplaceW(LPWSTR szString)
+{
+    LPWSTR p = szString;
+    BOOL needsQuote = FALSE;
+    while (*p) {
+        if (*p++ == L' ') {
+            needsQuote = TRUE;
+            break;
+        }
+    }
+    if (needsQuote) {
+        DWORD l = lstrlenW(szString);
+        AplMoveMemory(&szString[1], szString, l  * sizeof(WCHAR));
+        szString[0]   = L'"';
+        szString[++l] = L'"';
+        szString[++l] = L'\0';
+    }
+}
+
+DWORD apxStrUnQuoteInplaceA(LPSTR szString)
+{
+    LPSTR p = szString;
+    BOOL needsQuote = FALSE;
+    BOOL inQuote = FALSE;
+    while (*p) {
+        if (*p == '"') {
+            if (inQuote)
+                break;
+            else
+                inQuote = TRUE;
+        }
+        else if (*p == ' ') {
+            if (inQuote) {
+                needsQuote = TRUE;
+                break;
+            }
+        }
+        ++p;
+    }
+    if (!needsQuote)
+        return apxStrCharRemoveA(szString, '"');
+    else
+        return 0;
+}
+
+DWORD apxStrUnQuoteInplaceW(LPWSTR szString)
+{
+    LPWSTR p = szString;
+    BOOL needsQuote = FALSE;
+    BOOL inQuote = FALSE;
+    while (*p) {
+        if (*p == L'"') {
+            if (inQuote)
+                break;
+            else
+                inQuote = TRUE;
+        }
+        else if (*p == L' ') {
+            if (inQuote) {
+                needsQuote = TRUE;
+                break;
+            }
+        }
+        ++p;
+    }
+    if (!needsQuote)
+        return apxStrCharRemoveW(szString, L'"');
+    else
+        return 0;
+}
+
+LPWSTR
+apxMszToCRLFW(APXHANDLE hPool, LPCWSTR szStr)
+{
+    DWORD l, c;
+    LPWSTR rv, b;
+    LPCWSTR p = szStr;
+
+    l = __apxGetMultiSzLengthW(szStr, &c);    
+    b = rv = apxPoolCalloc(hPool, (l + c + 2) * sizeof(WCHAR));
+    do {
+        if (*p)
+            *b++ = *p;
+        else {
+            *b++ = L'\r';
+            *b++ = L'\n';
+        }
+        p++;
+    } while( *p || *(p + 1));
+ 
+    return rv;
+}
+
+LPWSTR
+apxCRLFToMszW(APXHANDLE hPool, LPCWSTR szStr, LPDWORD lpdwBytes)
+{
+    DWORD l, c, n = 0;
+    LPWSTR rv, b;
+
+    l = lstrlenW(szStr);    
+    b = rv = apxPoolCalloc(hPool, (l + 2) * sizeof(WCHAR));
+    for (c = 0; c < l; c++) {
+        if (szStr[c] == L'\r') {
+            *b++ = '\0';
+            n++;
+        }
+        else if (szStr[c] != L'\n') {
+            *b++ = szStr[c];
+            n++;
+        }
+    }
+    if (lpdwBytes)
+        *lpdwBytes = (n + 2) * sizeof(WCHAR);
+    return rv;
+}
+
+LPSTR
+apxExpandStrA(APXHANDLE hPool, LPCSTR szString)
+{
+    LPCSTR p = szString;
+    while (*p) {
+        if (*p == '%') {
+            p = szString;
+            break;
+        }
+        ++p;
+    }
+    if (p != szString)
+        return (LPSTR)szString;
+    else {
+        DWORD l = ExpandEnvironmentStringsA(szString, NULL, 0);
+        if (l) {
+            LPSTR rv = apxPoolAlloc(hPool, l);
+            l = ExpandEnvironmentStringsA(szString, rv, l);
+            if (l)
+                return rv;
+            else {
+                apxFree(rv);
+                return NULL;
+            }
+        }
+        else
+            return NULL;
+    }
+}
+
+LPWSTR
+apxExpandStrW(APXHANDLE hPool, LPCWSTR szString)
+{
+    LPCWSTR p = szString;
+    while (*p) {
+        if (*p == L'%') {
+            p = szString;
+            break;
+        }
+        ++p;
+    }
+    if (p != szString)
+        return (LPWSTR)szString;
+    else {
+        DWORD l = ExpandEnvironmentStringsW(szString, NULL, 0);
+        if (l) {
+            LPWSTR rv = apxPoolAlloc(hPool, l * sizeof(WCHAR));
+            l = ExpandEnvironmentStringsW(szString, rv, l);
+            if (l)
+                return rv;
+            else {
+                apxFree(rv);
+                return NULL;
+            }
+        }
+        else
+            return NULL;
+    }
+}
diff --git a/src/native/nt/procrun/testchild/testchild.c b/src/native/nt/procrun/testchild/testchild.c
index 1789c43..fc45da5 100644
--- a/src/native/nt/procrun/testchild/testchild.c
+++ b/src/native/nt/procrun/testchild/testchild.c
@@ -1,59 +1,17 @@
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
+/*
+ *  Copyright 2002-2004 The Apache Software Foundation
  *
- * 3. The end-user documentation included with the redistribution,
- *    if any, must include the following acknowledgment:
- *       "This product includes software developed by the
- *        Apache Software Foundation (http://www.apache.org/)."
- *    Alternately, this acknowledgment may appear in the software itself,
- *    if and wherever such third-party acknowledgments normally appear.
+ *  Licensed 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
  *
- * 4. The names "Apache" and "Apache Software Foundation" must
- *    not be used to endorse or promote products derived from this
- *    software without prior written permission. For written
- *    permission, please contact apache at apache.org.
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- * 5. Products derived from this software may not be called "Apache",
- *    nor may "Apache" appear in their name, without prior written
- *    permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- * Portions of this software are based upon public domain software
- * originally written at the National Center for Supercomputing Applications,
- * University of Illinois, Urbana-Champaign.
+ *  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.
  */
 
 /* ====================================================================
@@ -118,4 +76,4 @@ void __cdecl main(int argc, char **argv)
     fflush(stdout);
     for (i = 0; i < 1000; i++)
         Sleep(100);
-}
\ No newline at end of file
+}
diff --git a/src/native/nt/procrun/testchild/testchild.vcproj b/src/native/nt/procrun/testchild/testchild.vcproj
index e3cacb1..998f4c9 100644
--- a/src/native/nt/procrun/testchild/testchild.vcproj
+++ b/src/native/nt/procrun/testchild/testchild.vcproj
@@ -1,120 +1,120 @@
-<?xml version="1.0" encoding = "windows-1250"?>
-<VisualStudioProject
-	ProjectType="Visual C++"
-	Version="7.00"
-	Name="testchild"
-	ProjectGUID="{C815B005-1292-47F7-9052-F46676CE2879}"
-	Keyword="Win32Proj">
-	<Platforms>
-		<Platform
-			Name="Win32"/>
-	</Platforms>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory="Debug"
-			IntermediateDirectory="Debug"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
-				MinimalRebuild="TRUE"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="3"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="4"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
-				LinkIncremental="2"
-				GenerateDebugInformation="TRUE"
-				ProgramDatabaseFile="$(OutDir)/testchild.pdb"
-				SubSystem="1"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			OutputDirectory="Release"
-			IntermediateDirectory="Release"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="1"
-				OmitFramePointers="TRUE"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
-				StringPooling="TRUE"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				OutputFile="$(OutDir)/testchild.exe"
-				LinkIncremental="1"
-				GenerateDebugInformation="TRUE"
-				SubSystem="1"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-		</Configuration>
-	</Configurations>
-	<Files>
-		<Filter
-			Name="Source Files"
-			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
-			<File
-				RelativePath="testchild.c">
-			</File>
-		</Filter>
-		<Filter
-			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc">
-		</Filter>
-		<Filter
-			Name="Resource Files"
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
-		</Filter>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding = "windows-1250"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.00"
+	Name="testchild"
+	ProjectGUID="{C815B005-1292-47F7-9052-F46676CE2879}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/testchild.exe"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/testchild.pdb"
+				SubSystem="1"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="1"
+				OmitFramePointers="TRUE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				StringPooling="TRUE"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="TRUE"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/testchild.exe"
+				LinkIncremental="1"
+				GenerateDebugInformation="TRUE"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+		</Configuration>
+	</Configurations>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+			<File
+				RelativePath="testchild.c">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc">
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/src/native/nt/procrun/xdocs/index.xml b/src/native/nt/procrun/xdocs/index.xml
new file mode 100644
index 0000000..622080a
--- /dev/null
+++ b/src/native/nt/procrun/xdocs/index.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<document>
+ <properties>
+  <title>Daemon : Procrun</title>
+  <author email="mturk at apache.org">Mladen Turk</author>
+ </properties>
+
+<body> 
+<section name="Introduction">
+<p>
+    Procrun is a set of libraries and applications for making Java
+    applications to run on WIN32 much easier.    
+</p> 
+</section>
+
+</body>
+</document> 
diff --git a/src/native/nt/service/instmain.c b/src/native/nt/service/instmain.c
index 0d12ca5..077e8fb 100644
--- a/src/native/nt/service/instmain.c
+++ b/src/native/nt/service/instmain.c
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: instmain.c,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: instmain.c 155409 2005-02-26 12:57:06Z dirkv $ */
 
 /*
  * jsvc.exe install program, create the service JavaService
diff --git a/src/native/nt/signals/kills.c b/src/native/nt/signals/kills.c
index dbc2f98..d4563fe 100644
--- a/src/native/nt/signals/kills.c
+++ b/src/native/nt/signals/kills.c
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
-/* @version $Id: kills.c,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/* @version $Id: kills.c 155409 2005-02-26 12:57:06Z dirkv $ */
 
 /*
  * as Windows does not support signal, jsvc uses events to emulate them.
diff --git a/src/native/nt/supcalls_nt/vdenv.c b/src/native/nt/supcalls_nt/vdenv.c
index f2653c3..9b33554 100644
--- a/src/native/nt/supcalls_nt/vdenv.c
+++ b/src/native/nt/supcalls_nt/vdenv.c
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: vdenv.c,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: vdenv.c 155409 2005-02-26 12:57:06Z dirkv $ */
 
 /* Read the Win-NT register and set the jsvc environment variable. */
 /* XXX We should use a property file instead  registry */
diff --git a/src/native/unix/CHANGES.txt b/src/native/unix/CHANGES.txt
new file mode 100644
index 0000000..37520d0
--- /dev/null
+++ b/src/native/unix/CHANGES.txt
@@ -0,0 +1,15 @@
+JAKARTA COMMONS DAEMON (UNIX) CHANGELOG:
+Last modified at [$Date: 2005-05-17 10:03:57 +0200 (Tue, 17 May 2005) $]
+
+Changes with 1.0.1
+  * Allow enableassertions -ea (PR 304310).
+  * Add -lpthread to LDFLAGS on Linux (PR 30177).
+  * Add support for x86_64 (PR 27523).
+  * Add support for Tru64 (PR 29465).
+  * Remove the pid file when son exits correctly (PR 31614).
+  * Add support for JVM-4.1.x on MAC OS X (part of PR 31613).
+  * Prevent starting jsvc several times with the same pidfile (PR 33580).
+  * Finish fixing 31613, automatic detection of JAVA_HOME and headers locations.
+  * -wait and -stop parameters.
+  * fix 34851.
+  * Don't break when set_caps() failed and the user is unchanged (linux).
diff --git a/src/native/unix/INSTALL.txt b/src/native/unix/INSTALL.txt
index 60c04f5..218358e 100644
--- a/src/native/unix/INSTALL.txt
+++ b/src/native/unix/INSTALL.txt
@@ -5,7 +5,7 @@ system you will need:
   GNU AutoConf
   A Java Platform 2 compliant SDK
 
-First of all you need to build the "configure" program with:
+When building from CVS sources you need to build the "configure" program with:
 
    sh support/buildconf.sh
 (Note it is possible to replace sh by any compatible shell like bash, ksh).
@@ -22,6 +22,13 @@ or
   export JAVA_HOME
   ./configure
 
+or (when using gcj (use fastjar for jar))
+  JAVAC=gcj; export JAVAC
+  JAVACFLAGS=-c; export JAVACFLAGS
+  ./configure
+
+Note: On Mac OS X <dir> is /System/Library/Frameworks/JavaVM.framework/Home.
+
 If your operating system is supported, configure will go thru cleanly,
 otherwise it will report an error (please send us the details of your
 OS/JDK, or a patch against the sources). To build the binaries and
diff --git a/src/native/unix/Makedefs.in b/src/native/unix/Makedefs.in
index 2154bdf..44155d6 100644
--- a/src/native/unix/Makedefs.in
+++ b/src/native/unix/Makedefs.in
@@ -1,62 +1,21 @@
-# ========================================================================= #
-#                                                                           #
-#                 The Apache Software License,  Version 1.1                 #
-#                                                                           #
-#          Copyright (c) 1999-2001 The Apache Software Foundation.          #
-#                           All rights reserved.                            #
-#                                                                           #
-# ========================================================================= #
-#                                                                           #
-# Redistribution and use in source and binary forms,  with or without modi- #
-# fication, are permitted provided that the following conditions are met:   #
-#                                                                           #
-# 1. Redistributions of source code  must retain the above copyright notice #
-#    notice, this list of conditions and the following disclaimer.          #
-#                                                                           #
-# 2. Redistributions  in binary  form  must  reproduce the  above copyright #
-#    notice,  this list of conditions  and the following  disclaimer in the #
-#    documentation and/or other materials provided with the distribution.   #
-#                                                                           #
-# 3. The end-user documentation  included with the redistribution,  if any, #
-#    must include the following acknowlegement:                             #
-#                                                                           #
-#       "This product includes  software developed  by the Apache  Software #
-#        Foundation <http://www.apache.org/>."                              #
-#                                                                           #
-#    Alternately, this acknowlegement may appear in the software itself, if #
-#    and wherever such third-party acknowlegements normally appear.         #
-#                                                                           #
-# 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software #
-#    Foundation"  must not be used  to endorse or promote  products derived #
-#    from this  software without  prior  written  permission.  For  written #
-#    permission, please contact <apache at apache.org>.                        #
-#                                                                           #
-# 5. Products derived from this software may not be called "Apache" nor may #
-#    "Apache" appear in their names without prior written permission of the #
-#    Apache Software Foundation.                                            #
-#                                                                           #
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES #
-# INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY #
-# AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL #
-# THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY #
-# DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL #
-# DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS #
-# OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) #
-# HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, #
-# STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
-# ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE #
-# POSSIBILITY OF SUCH DAMAGE.                                               #
-#                                                                           #
-# ========================================================================= #
-#                                                                           #
-# This software  consists of voluntary  contributions made  by many indivi- #
-# duals on behalf of the  Apache Software Foundation.  For more information #
-# on the Apache Software Foundation, please see <http://www.apache.org/>.   #
-#                                                                           #
-# ========================================================================= #
+#
+#   Copyright 1999-2004 The Apache Software Foundation
+#
+#   Licensed 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.
+#
 
 # @author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-# @version $Id: Makedefs.in,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $
+# @version $Id: Makedefs.in 140756 2004-02-27 08:40:46Z jfclere $
 
 CC = @CC@
 JAVAC = @JAVAC@
diff --git a/src/native/unix/Makefile.in b/src/native/unix/Makefile.in
index ba4fc2b..ef35845 100644
--- a/src/native/unix/Makefile.in
+++ b/src/native/unix/Makefile.in
@@ -1,62 +1,21 @@
-# ========================================================================= #
-#                                                                           #
-#                 The Apache Software License,  Version 1.1                 #
-#                                                                           #
-#          Copyright (c) 1999-2001 The Apache Software Foundation.          #
-#                           All rights reserved.                            #
-#                                                                           #
-# ========================================================================= #
-#                                                                           #
-# Redistribution and use in source and binary forms,  with or without modi- #
-# fication, are permitted provided that the following conditions are met:   #
-#                                                                           #
-# 1. Redistributions of source code  must retain the above copyright notice #
-#    notice, this list of conditions and the following disclaimer.          #
-#                                                                           #
-# 2. Redistributions  in binary  form  must  reproduce the  above copyright #
-#    notice,  this list of conditions  and the following  disclaimer in the #
-#    documentation and/or other materials provided with the distribution.   #
-#                                                                           #
-# 3. The end-user documentation  included with the redistribution,  if any, #
-#    must include the following acknowlegement:                             #
-#                                                                           #
-#       "This product includes  software developed  by the Apache  Software #
-#        Foundation <http://www.apache.org/>."                              #
-#                                                                           #
-#    Alternately, this acknowlegement may appear in the software itself, if #
-#    and wherever such third-party acknowlegements normally appear.         #
-#                                                                           #
-# 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software #
-#    Foundation"  must not be used  to endorse or promote  products derived #
-#    from this  software without  prior  written  permission.  For  written #
-#    permission, please contact <apache at apache.org>.                        #
-#                                                                           #
-# 5. Products derived from this software may not be called "Apache" nor may #
-#    "Apache" appear in their names without prior written permission of the #
-#    Apache Software Foundation.                                            #
-#                                                                           #
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES #
-# INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY #
-# AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL #
-# THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY #
-# DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL #
-# DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS #
-# OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) #
-# HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, #
-# STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
-# ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE #
-# POSSIBILITY OF SUCH DAMAGE.                                               #
-#                                                                           #
-# ========================================================================= #
-#                                                                           #
-# This software  consists of voluntary  contributions made  by many indivi- #
-# duals on behalf of the  Apache Software Foundation.  For more information #
-# on the Apache Software Foundation, please see <http://www.apache.org/>.   #
-#                                                                           #
-# ========================================================================= #
+#
+#   Copyright 1999-2004 The Apache Software Foundation
+#
+#   Licensed 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.
+#
 
 # @author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-# @version $Id: Makefile.in,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $
+# @version $Id: Makefile.in 140756 2004-02-27 08:40:46Z jfclere $
 
 SUBDIRS = native
 
diff --git a/src/native/unix/configure b/src/native/unix/configure
index ef6b96e..57403b9 100755
--- a/src/native/unix/configure
+++ b/src/native/unix/configure
@@ -1,9 +1,8 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.57.
+# Generated by GNU Autoconf 2.59.
 #
-# Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
-# Free Software Foundation, Inc.
+# Copyright (C) 2003 Free Software Foundation, Inc.
 # This configure script is free software; the Free Software Foundation
 # gives unlimited permission to copy, distribute and modify it.
 ## --------------------- ##
@@ -20,9 +19,10 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
 elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
   set -o posix
 fi
+DUALCASE=1; export DUALCASE # for MKS sh
 
 # Support unset when possible.
-if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
   as_unset=unset
 else
   as_unset=false
@@ -41,7 +41,7 @@ for as_var in \
   LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
   LC_TELEPHONE LC_TIME
 do
-  if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
     eval $as_var=C; export $as_var
   else
     $as_unset $as_var
@@ -218,16 +218,17 @@ rm -f conf$$ conf$$.exe conf$$.file
 if mkdir -p . 2>/dev/null; then
   as_mkdir_p=:
 else
+  test -d ./-p && rmdir ./-p
   as_mkdir_p=false
 fi
 
 as_executable_p="test -f"
 
 # Sed expression to map a string onto a valid CPP name.
-as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
 
 # Sed expression to map a string onto a valid variable name.
-as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
 
 # IFS
@@ -630,7 +631,7 @@ done
 
 # Be sure to have absolute paths.
 for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
-              localstatedir libdir includedir oldincludedir infodir mandir
+	      localstatedir libdir includedir oldincludedir infodir mandir
 do
   eval ac_val=$`echo $ac_var`
   case $ac_val in
@@ -670,10 +671,10 @@ if test -z "$srcdir"; then
   # Try the directory containing this script, then its parent.
   ac_confdir=`(dirname "$0") 2>/dev/null ||
 $as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-         X"$0" : 'X\(//\)[^/]' \| \
-         X"$0" : 'X\(//\)$' \| \
-         X"$0" : 'X\(/\)' \| \
-         .     : '\(.\)' 2>/dev/null ||
+	 X"$0" : 'X\(//\)[^/]' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
 echo X"$0" |
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
   	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
@@ -761,9 +762,9 @@ _ACEOF
   cat <<_ACEOF
 Installation directories:
   --prefix=PREFIX         install architecture-independent files in PREFIX
-                          [$ac_default_prefix]
+			  [$ac_default_prefix]
   --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
-                          [PREFIX]
+			  [PREFIX]
 
 By default, \`make install' will install all the files in
 \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
@@ -848,12 +849,45 @@ case $srcdir in
     ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
     ac_top_srcdir=$ac_top_builddir$srcdir ;;
 esac
-# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
-# absolute.
-ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
-ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
-ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
-ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
 
     cd $ac_dir
     # Check for guested configure; otherwise get Cygnus style configure.
@@ -864,7 +898,7 @@ ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
       echo
       $SHELL $ac_srcdir/configure  --help=recursive
     elif test -f $ac_srcdir/configure.ac ||
-           test -f $ac_srcdir/configure.in; then
+	   test -f $ac_srcdir/configure.in; then
       echo
       $ac_configure --help
     else
@@ -878,8 +912,7 @@ test -n "$ac_init_help" && exit 0
 if $ac_init_version; then
   cat <<\_ACEOF
 
-Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
-Free Software Foundation, Inc.
+Copyright (C) 2003 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
@@ -891,7 +924,7 @@ This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by $as_me, which was
-generated by GNU Autoconf 2.57.  Invocation command line was
+generated by GNU Autoconf 2.59.  Invocation command line was
 
   $ $0 $@
 
@@ -968,19 +1001,19 @@ do
     2)
       ac_configure_args1="$ac_configure_args1 '$ac_arg'"
       if test $ac_must_keep_next = true; then
-        ac_must_keep_next=false # Got value, back to normal.
+	ac_must_keep_next=false # Got value, back to normal.
       else
-        case $ac_arg in
-          *=* | --config-cache | -C | -disable-* | --disable-* \
-          | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
-          | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
-          | -with-* | --with-* | -without-* | --without-* | --x)
-            case "$ac_configure_args0 " in
-              "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
-            esac
-            ;;
-          -* ) ac_must_keep_next=true ;;
-        esac
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
       fi
       ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
       # Get rid of the leading space.
@@ -1014,12 +1047,12 @@ _ASBOX
     case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
     *ac_space=\ *)
       sed -n \
-        "s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
-    	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
+	"s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
       ;;
     *)
       sed -n \
-        "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
       ;;
     esac;
 }
@@ -1048,7 +1081,7 @@ _ASBOX
       for ac_var in $ac_subst_files
       do
 	eval ac_val=$`echo $ac_var`
-        echo "$ac_var='"'"'$ac_val'"'"'"
+	echo "$ac_var='"'"'$ac_val'"'"'"
       done | sort
       echo
     fi
@@ -1067,7 +1100,7 @@ _ASBOX
       echo "$as_me: caught signal $ac_signal"
     echo "$as_me: exit $exit_status"
   } >&5
-  rm -f core core.* *.core &&
+  rm -f core *.core &&
   rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
     exit $exit_status
      ' 0
@@ -1147,7 +1180,7 @@ fi
 # value.
 ac_cache_corrupted=false
 for ac_var in `(set) 2>&1 |
-               sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+	       sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
   eval ac_old_set=\$ac_cv_env_${ac_var}_set
   eval ac_new_set=\$ac_env_${ac_var}_set
   eval ac_old_val="\$ac_cv_env_${ac_var}_value"
@@ -1164,13 +1197,13 @@ echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
     ,);;
     *)
       if test "x$ac_old_val" != "x$ac_new_val"; then
-        { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+	{ echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
 echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
-        { echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
+	{ echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
 echo "$as_me:   former value:  $ac_old_val" >&2;}
-        { echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
+	{ echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
 echo "$as_me:   current value: $ac_new_val" >&2;}
-        ac_cache_corrupted=:
+	ac_cache_corrupted=:
       fi;;
   esac
   # Pass precious variables to config.status.
@@ -1661,7 +1694,6 @@ ac_compiler=`set X $ac_compile; echo $2`
   (exit $ac_status); }
 
 cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -1681,8 +1713,8 @@ ac_clean_files="$ac_clean_files a.out a.exe b.out"
 # Try to create an executable without -o first, disregard a.out.
 # It will help us diagnose broken compilers, and finding out an intuition
 # of exeext.
-echo "$as_me:$LINENO: checking for C compiler default output" >&5
-echo $ECHO_N "checking for C compiler default output... $ECHO_C" >&6
+echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6
 ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
 if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
   (eval $ac_link_default) 2>&5
@@ -1702,23 +1734,23 @@ do
   test -f "$ac_file" || continue
   case $ac_file in
     *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
-        ;;
+	;;
     conftest.$ac_ext )
-        # This is the source file.
-        ;;
+	# This is the source file.
+	;;
     [ab].out )
-        # We found the default executable, but exeext='' is most
-        # certainly right.
-        break;;
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
     *.* )
-        ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
-        # FIXME: I believe we export ac_cv_exeext for Libtool,
-        # but it would be cool to find out if it's true.  Does anybody
-        # maintain Libtool? --akim.
-        export ac_cv_exeext
-        break;;
+	ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	# FIXME: I believe we export ac_cv_exeext for Libtool,
+	# but it would be cool to find out if it's true.  Does anybody
+	# maintain Libtool? --akim.
+	export ac_cv_exeext
+	break;;
     * )
-        break;;
+	break;;
   esac
 done
 else
@@ -1792,8 +1824,8 @@ for ac_file in conftest.exe conftest conftest.*; do
   case $ac_file in
     *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
     *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
-          export ac_cv_exeext
-          break;;
+	  export ac_cv_exeext
+	  break;;
     * ) break;;
   esac
 done
@@ -1818,7 +1850,6 @@ if test "${ac_cv_objext+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -1869,7 +1900,6 @@ if test "${ac_cv_c_compiler_gnu+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -1889,11 +1919,21 @@ main ()
 _ACEOF
 rm -f conftest.$ac_objext
 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -1906,7 +1946,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 
 ac_compiler_gnu=no
 fi
-rm -f conftest.$ac_objext conftest.$ac_ext
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_c_compiler_gnu=$ac_compiler_gnu
 
 fi
@@ -1922,7 +1962,6 @@ if test "${ac_cv_prog_cc_g+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -1939,11 +1978,21 @@ main ()
 _ACEOF
 rm -f conftest.$ac_objext
 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -1956,7 +2005,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 
 ac_cv_prog_cc_g=no
 fi
-rm -f conftest.$ac_objext conftest.$ac_ext
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
 echo "${ECHO_T}$ac_cv_prog_cc_g" >&6
@@ -1983,7 +2032,6 @@ else
   ac_cv_prog_cc_stdc=no
 ac_save_CC=$CC
 cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -2011,6 +2059,16 @@ static char *f (char * (*g) (char **, int), char **p, ...)
   va_end (v);
   return s;
 }
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std1 is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std1.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
 int test (int i, double x);
 struct s1 {int (*f) (int a);};
 struct s2 {int (*f) (double a);};
@@ -2037,11 +2095,21 @@ do
   CC="$ac_save_CC $ac_arg"
   rm -f conftest.$ac_objext
 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2054,7 +2122,7 @@ else
 sed 's/^/| /' conftest.$ac_ext >&5
 
 fi
-rm -f conftest.$ac_objext
+rm -f conftest.err conftest.$ac_objext
 done
 rm -f conftest.$ac_ext conftest.$ac_objext
 CC=$ac_save_CC
@@ -2082,19 +2150,28 @@ cat >conftest.$ac_ext <<_ACEOF
 _ACEOF
 rm -f conftest.$ac_objext
 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
   for ac_declaration in \
-   ''\
-   '#include <stdlib.h>' \
+   '' \
    'extern "C" void std::exit (int) throw (); using std::exit;' \
    'extern "C" void std::exit (int); using std::exit;' \
    'extern "C" void exit (int) throw ();' \
@@ -2102,14 +2179,13 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
    'void exit (int);'
 do
   cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include <stdlib.h>
 $ac_declaration
+#include <stdlib.h>
 int
 main ()
 {
@@ -2120,11 +2196,21 @@ exit (42);
 _ACEOF
 rm -f conftest.$ac_objext
 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2137,9 +2223,8 @@ sed 's/^/| /' conftest.$ac_ext >&5
 
 continue
 fi
-rm -f conftest.$ac_objext conftest.$ac_ext
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
   cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -2156,11 +2241,21 @@ exit (42);
 _ACEOF
 rm -f conftest.$ac_objext
 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -2172,7 +2267,7 @@ else
 sed 's/^/| /' conftest.$ac_ext >&5
 
 fi
-rm -f conftest.$ac_objext conftest.$ac_ext
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 rm -f conftest*
 if test -n "$ac_declaration"; then
@@ -2186,7 +2281,7 @@ else
 sed 's/^/| /' conftest.$ac_ext >&5
 
 fi
-rm -f conftest.$ac_objext conftest.$ac_ext
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -2275,6 +2370,113 @@ fi
 
 
 
+  printf "*** %s ***\n" "Host support" 1>&2
+
+
+
+  echo "$as_me:$LINENO: checking C flags dependant on host system type" >&5
+echo $ECHO_N "checking C flags dependant on host system type... $ECHO_C" >&6
+
+  case $host_os in
+  darwin*)
+    CFLAGS="$CFLAGS -DOS_DARWIN -DDSO_DYLD"
+    supported_os="darwin"
+    ;;
+  solaris*)
+    CFLAGS="$CFLAGS -DOS_SOLARIS -DDSO_DLFCN"
+    supported_os="solaris"
+    LDFLAGS="$LDFLAGS -ldl -lthread"
+    ;;
+  linux*)
+    CFLAGS="$CFLAGS -DOS_LINUX -DDSO_DLFCN"
+    supported_os="linux"
+    LDFLAGS="$LDFLAGS -ldl -lpthread"
+    ;;
+  cygwin)
+    CFLAGS="$CFLAGS -DOS_CYGWIN -DDSO_DLFCN -DNO_SETSID"
+    supported_os="win32"
+    ;;
+  sysv)
+    CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN"
+    LDFLAGS="$LDFLAGS -ldl"
+    ;;
+  sysv4)
+    CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN -Kthread"
+    LDFLAGS="-Kthread $LDFLAGS -ldl"
+    ;;
+  freebsd4.?)
+    CFLAGS="$CFLAGS -DOS_FREEBSD -DDSO_DLFCN -D_THREAD_SAFE -pthread"
+    LDFLAGS="-pthread $LDFLAGS"
+    supported_os="freebsd"
+    ;;
+  osf5*)
+    CFLAGS="$CFLAGS -pthread -DOS_TRU64 -DDSO_DLFCN -D_XOPEN_SOURCE_EXTENDED"
+    LDFLAGS="$LDFLAGS -pthread"
+    ;;
+  *)
+    echo "$as_me:$LINENO: result: failed" >&5
+echo "${ECHO_T}failed" >&6
+    { { echo "$as_me:$LINENO: error: Unsupported operating system \"$host_os\"" >&5
+echo "$as_me: error: Unsupported operating system \"$host_os\"" >&2;}
+   { (exit 1); exit 1; }; }
+    ;;
+  esac
+  case $host_cpu in
+  powerpc)
+    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
+  sparc*)
+    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
+  i?86)
+    CFLAGS="$CFLAGS -DCPU=\\\"i386\\\"" ;;
+  x86_64)
+    CFLAGS="$CFLAGS -DCPU=\\\"amd64\\\"" ;;
+  bs2000)
+    CFLAGS="$CFLAGS -DCPU=\\\"osd\\\" -DCHARSET_EBCDIC -DOSD_POSIX"
+    supported_os="osd"
+    LDFLAGS="-Kno_link_stdlibs -B llm4 -l BLSLIB"
+    LDCMD="/opt/C/bin/cc"
+    ;;
+  mips)
+    CFLAGS="$CFLAGS -DCPU=\\\"mips\\\""
+    supported_os="mips"
+    ;;
+  alpha*)
+    CFLAGS="$CFLAGS -DCPU=\\\"alpha\\\""
+    supported_os="alpha"
+    ;;
+  *)
+    echo "$as_me:$LINENO: result: failed" >&5
+echo "${ECHO_T}failed" >&6
+    { { echo "$as_me:$LINENO: error: Unsupported CPU architecture \"$host_cpu\"" >&5
+echo "$as_me: error: Unsupported CPU architecture \"$host_cpu\"" >&2;}
+   { (exit 1); exit 1; }; };;
+  esac
+
+  echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+
+
+
+if test "$supported_os" = "darwin"
+then
+  if test -z "$JAVA_HOME" -a -d /System/Library/Frameworks/JavaVM.framework/Home; then
+  	JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
+  fi
+
+  _prevdir=`/bin/pwd`
+  if test -n "$JAVA_HOME" -a -d "$JAVA_HOME/include"; then
+    cd "$JAVA_HOME/include"
+  elif test -n "$JAVA_HOME" -a -d "$JAVA_HOME/../Headers"; then
+    cd "$JAVA_HOME/../Headers"
+  else
+    cd /System/Library/Frameworks/JavaVM.framework/Headers
+  fi
+  CFLAGS="$CFLAGS -I`/bin/pwd -P`"
+  cd $_prevdir
+  unset _prevdir
+fi
+
+
   printf "*** %s ***\n" "Java compilation tools" 1>&2
 
 
@@ -2523,93 +2725,8 @@ echo "$as_me: error: jar not found" >&2;}
 
 
 
-
-
-  printf "*** %s ***\n" "Host support" 1>&2
-
-
-
-  echo "$as_me:$LINENO: checking C flags dependant on host system type" >&5
-echo $ECHO_N "checking C flags dependant on host system type... $ECHO_C" >&6
-  case $host_cpu in
-  powerpc)
-    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
-  sparc)
-    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
-  i?86)
-    CFLAGS="$CFLAGS -DCPU=\\\"i386\\\"" ;;
-  bs2000)
-    CFLAGS="$CFLAGS -DCPU=\\\"osd\\\" -DCHARSET_EBCDIC -DOSD_POSIX"
-    supported_os="osd"
-    LDFLAGS="-Kno_link_stdlibs -B llm4 -l BLSLIB $LDFLAGS"
-    LDCMD="cc"
-    ;;
-  mips)
-    CFLAGS="$CFLAGS -DCPU=\\\"mips\\\""
-    supported_os="mips"
-    ;;
-  *)
-    echo "$as_me:$LINENO: result: failed" >&5
-echo "${ECHO_T}failed" >&6
-    { { echo "$as_me:$LINENO: error: Unsupported CPU architecture \"$host_cpu\"" >&5
-echo "$as_me: error: Unsupported CPU architecture \"$host_cpu\"" >&2;}
-   { (exit 1); exit 1; }; };;
-  esac
-
-  case $host_os in
-  darwin*)
-    CFLAGS="$CFLAGS -DOS_DARWIN -DDSO_DYLD"
-    supported_os="darwin"
-    ;;
-  solaris*)
-    CFLAGS="$CFLAGS -DOS_SOLARIS -DDSO_DLFCN"
-    supported_os="solaris"
-    LDFLAGS="$LDFLAGS -ldl -lthread"
-    ;;
-  linux*)
-    CFLAGS="$CFLAGS -DOS_LINUX -DDSO_DLFCN"
-    supported_os="linux"
-    LDFLAGS="$LDFLAGS -ldl"
-    ;;
-  cygwin)
-    CFLAGS="$CFLAGS -DOS_CYGWIN -DDSO_DLFCN -DNO_SETSID"
-    supported_os="win32"
-    ;;
-  sysv)
-    CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN"
-    LDFLAGS="$LDFLAGS -ldl"
-    ;;
-  sysv4)
-    CFLAGS="$CFLAGS -DOS_SYSV -DDSO_DLFCN -Kthread"
-    LDFLAGS="-Kthread $LDFLAGS -ldl"
-    ;;
-  freebsd4.?)
-    CFLAGS="$CFLAGS -DOS_FREEBSD -DDSO_DLFCN -D_THREAD_SAFE -pthread"
-    LDFLAGS="-pthread $LDFLAGS"
-    supported_os="freebsd"
-    ;;
-  *)
-    echo "$as_me:$LINENO: result: failed" >&5
-echo "${ECHO_T}failed" >&6
-    { { echo "$as_me:$LINENO: error: Unsupported operating system \"$host_os\"" >&5
-echo "$as_me: error: Unsupported operating system \"$host_os\"" >&2;}
-   { (exit 1); exit 1; }; }
-    ;;
-  esac
-  echo "$as_me:$LINENO: result: ok" >&5
-echo "${ECHO_T}ok" >&6
-
-
-if test "$supported_os" = "darwin"
+if test "$supported_os" != "darwin"
 then
-  _prevdir=`/bin/pwd`
-  cd $JAVA_HOME
-  cd ..
-  cd Headers
-  CFLAGS="$CFLAGS -I`/bin/pwd -P`"
-  cd $_prevdir
-  unset _prevdir
-else
   CFLAGS="$CFLAGS -I$JAVA_HOME/include -I$JAVA_HOME/include/$supported_os"
 fi
 
@@ -2658,13 +2775,13 @@ _ACEOF
       # `set' does not quote correctly, so add quotes (double-quote
       # substitution turns \\\\ into \\, and sed turns \\ into \).
       sed -n \
-        "s/'/'\\\\''/g;
-    	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
       ;;
     *)
       # `set' quotes correctly as required by POSIX, so do not add quotes.
       sed -n \
-        "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
       ;;
     esac;
 } |
@@ -2694,13 +2811,13 @@ test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
 # trailing colons and then remove the whole line if VPATH becomes empty
 # (actually we leave an empty line to preserve line numbers).
 if test "x$srcdir" = x.; then
-  ac_vpsub='/^[ 	]*VPATH[ 	]*=/{
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
 s/:*\$(srcdir):*/:/;
 s/:*\${srcdir}:*/:/;
 s/:*@srcdir@:*/:/;
-s/^\([^=]*=[ 	]*\):*/\1/;
+s/^\([^=]*=[	 ]*\):*/\1/;
 s/:*$//;
-s/^[^=]*=[ 	]*$//;
+s/^[^=]*=[	 ]*$//;
 }'
 fi
 
@@ -2714,13 +2831,13 @@ fi
 cat >confdef2opt.sed <<\_ACEOF
 t clear
 : clear
-s,^[ 	]*#[ 	]*define[ 	][ 	]*\([^ 	(][^ 	(]*([^)]*)\)[ 	]*\(.*\),-D\1=\2,g
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\),-D\1=\2,g
 t quote
-s,^[ 	]*#[ 	]*define[ 	][ 	]*\([^ 	][^ 	]*\)[ 	]*\(.*\),-D\1=\2,g
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\),-D\1=\2,g
 t quote
 d
 : quote
-s,[ 	`~#$^&*(){}\\|;'"<>?],\\&,g
+s,[	 `~#$^&*(){}\\|;'"<>?],\\&,g
 s,\[,\\&,g
 s,\],\\&,g
 s,\$,$$,g
@@ -2742,7 +2859,7 @@ ac_ltlibobjs=
 for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
   # 1. Remove the extension, and $U if already installed.
   ac_i=`echo "$ac_i" |
-         sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
+	 sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
   # 2. Add them.
   ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
   ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
@@ -2786,9 +2903,10 @@ if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
 elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
   set -o posix
 fi
+DUALCASE=1; export DUALCASE # for MKS sh
 
 # Support unset when possible.
-if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
   as_unset=unset
 else
   as_unset=false
@@ -2807,7 +2925,7 @@ for as_var in \
   LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
   LC_TELEPHONE LC_TIME
 do
-  if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
     eval $as_var=C; export $as_var
   else
     $as_unset $as_var
@@ -2986,16 +3104,17 @@ rm -f conf$$ conf$$.exe conf$$.file
 if mkdir -p . 2>/dev/null; then
   as_mkdir_p=:
 else
+  test -d ./-p && rmdir ./-p
   as_mkdir_p=false
 fi
 
 as_executable_p="test -f"
 
 # Sed expression to map a string onto a valid CPP name.
-as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
 
 # Sed expression to map a string onto a valid variable name.
-as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
 
 # IFS
@@ -3022,7 +3141,7 @@ _ASBOX
 cat >&5 <<_CSEOF
 
 This file was extended by $as_me, which was
-generated by GNU Autoconf 2.57.  Invocation command line was
+generated by GNU Autoconf 2.59.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -3066,7 +3185,7 @@ Usage: $0 [OPTIONS] [FILE]...
   -d, --debug      don't remove temporary files
       --recheck    update $as_me by reconfiguring in the same conditions
   --file=FILE[:TEMPLATE]
-                   instantiate the configuration file FILE
+		   instantiate the configuration file FILE
 
 Configuration files:
 $config_files
@@ -3077,11 +3196,10 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
 config.status
-configured by $0, generated by GNU Autoconf 2.57,
+configured by $0, generated by GNU Autoconf 2.59,
   with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
 
-Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
-Free Software Foundation, Inc.
+Copyright (C) 2003 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 srcdir=$srcdir
@@ -3320,9 +3438,9 @@ _ACEOF
       (echo ':t
   /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
       if test -z "$ac_sed_cmds"; then
-  	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
+	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
       else
-  	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
+	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
       fi
       ac_sed_frag=`expr $ac_sed_frag + 1`
       ac_beg=$ac_end
@@ -3340,21 +3458,21 @@ for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
   # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
   case $ac_file in
   - | *:- | *:-:* ) # input from stdin
-        cat >$tmp/stdin
-        ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
-        ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
   *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
-        ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
   * )   ac_file_in=$ac_file.in ;;
   esac
 
   # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
   ac_dir=`(dirname "$ac_file") 2>/dev/null ||
 $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-         X"$ac_file" : 'X\(//\)[^/]' \| \
-         X"$ac_file" : 'X\(//\)$' \| \
-         X"$ac_file" : 'X\(/\)' \| \
-         .     : '\(.\)' 2>/dev/null ||
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
 echo X"$ac_file" |
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
   	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
@@ -3370,10 +3488,10 @@ echo X"$ac_file" |
       as_dirs="$as_dir $as_dirs"
       as_dir=`(dirname "$as_dir") 2>/dev/null ||
 $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-         X"$as_dir" : 'X\(//\)[^/]' \| \
-         X"$as_dir" : 'X\(//\)$' \| \
-         X"$as_dir" : 'X\(/\)' \| \
-         .     : '\(.\)' 2>/dev/null ||
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
 echo X"$as_dir" |
     sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
   	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
@@ -3411,12 +3529,45 @@ case $srcdir in
     ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
     ac_top_srcdir=$ac_top_builddir$srcdir ;;
 esac
-# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
-# absolute.
-ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
-ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
-ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
-ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
 
 
 
@@ -3434,7 +3585,7 @@ echo "$as_me: creating $ac_file" >&6;}
     configure_input="$ac_file.  "
   fi
   configure_input=$configure_input"Generated from `echo $ac_file_in |
-                                     sed 's,.*/,,'` by configure."
+				     sed 's,.*/,,'` by configure."
 
   # First look for the input files in the build tree, otherwise in the
   # src tree.
@@ -3443,24 +3594,24 @@ echo "$as_me: creating $ac_file" >&6;}
       case $f in
       -) echo $tmp/stdin ;;
       [\\/$]*)
-         # Absolute (can't be DOS-style, as IFS=:)
-         test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
-         echo $f;;
+	 echo "$f";;
       *) # Relative
-         if test -f "$f"; then
-           # Build tree
-           echo $f
-         elif test -f "$srcdir/$f"; then
-           # Source tree
-           echo $srcdir/$f
-         else
-           # /dev/null tree
-           { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
-         fi;;
+	 fi;;
       esac
     done` || { (exit 1); exit 1; }
 _ACEOF
diff --git a/src/native/unix/configure.in b/src/native/unix/configure.in
index c6f8420..b91a3b0 100644
--- a/src/native/unix/configure.in
+++ b/src/native/unix/configure.in
@@ -1,68 +1,30 @@
-dnl =========================================================================
 dnl
-dnl                 The Apache Software License,  Version 1.1
+dnl Copyright 1999-2004 The Apache Software Foundation
 dnl
-dnl          Copyright (c) 1999-2001 The Apache Software Foundation.
-dnl                           All rights reserved.
+dnl Licensed under the Apache License, Version 2.0 (the "License");
+dnl you may not use this file except in compliance with the License.
+dnl You may obtain a copy of the License at
 dnl
-dnl =========================================================================
+dnl     http://www.apache.org/licenses/LICENSE-2.0
 dnl
-dnl Redistribution and use in source and binary forms,  with or without modi-
-dnl fication, are permitted provided that the following conditions are met:
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
 dnl
-dnl 1. Redistributions of source code  must retain the above copyright notice
-dnl    notice, this list of conditions and the following disclaimer.
-dnl
-dnl 2. Redistributions  in binary  form  must  reproduce the  above copyright
-dnl    notice,  this list of conditions  and the following  disclaimer in the
-dnl    documentation and/or other materials provided with the distribution.
-dnl
-dnl 3. The end-user documentation  included with the redistribution,  if any,
-dnl    must include the following acknowlegement:
-dnl
-dnl       "This product includes  software developed  by the Apache  Software
-dnl        Foundation <http://www.apache.org/>."
-dnl
-dnl    Alternately, this acknowlegement may appear in the software itself, if
-dnl    and wherever such third-party acknowlegements normally appear.
-dnl
-dnl 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software
-dnl    Foundation"  must not be used  to endorse or promote  products derived
-dnl    from this  software without  prior  written  permission.  For  written
-dnl    permission, please contact <apache at apache.org>.
-dnl
-dnl 5. Products derived from this software may not be called "Apache" nor may
-dnl    "Apache" appear in their names without prior written permission of the
-dnl    Apache Software Foundation.
-dnl
-dnl THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES
-dnl INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY
-dnl AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL
-dnl THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY
-dnl DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL
-dnl DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS
-dnl OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION)
-dnl HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT,
-dnl STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-dnl ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE
-dnl POSSIBILITY OF SUCH DAMAGE.
-dnl
-dnl =========================================================================
-dnl
-dnl This software  consists of voluntary  contributions made  by many indivi-
-dnl duals on behalf of the  Apache Software Foundation.  For more information
-dnl on the Apache Software Foundation, please see <http://www.apache.org/>.
-dnl
-dnl =========================================================================
 
 dnl -------------------------------------------------------------------------
 dnl Author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-dnl Version $Id: configure.in,v 1.2 2003/09/12 09:08:51 jfclere Exp $
+dnl Version $Id: configure.in 164232 2005-04-22 13:01:30Z jfclere $
 dnl -------------------------------------------------------------------------
 
 dnl -------------------------------------------------------------------------
 dnl Initialize AutoConf
 dnl -------------------------------------------------------------------------
+
+AC_PREREQ(2.53)
+
 sinclude(./support/apfunctions.m4)dnl
 sinclude(./support/apjava.m4)dnl
 sinclude(./support/apsupport.m4)dnl
@@ -85,28 +47,38 @@ AC_PROG_CC()
 AC_CHECK_TOOL(RANLIB, ranlib, :)
 
 dnl -------------------------------------------------------------------------
-dnl Check JAVA environment
-dnl -------------------------------------------------------------------------
-AP_MSG_HEADER([Java compilation tools])
-AP_JAVA()
-AP_PROG_JAVAC()
-AP_PROG_JAR()
-
-dnl -------------------------------------------------------------------------
 dnl Check if this host is supported
 dnl -------------------------------------------------------------------------
 AP_MSG_HEADER([Host support])
 AP_SUPPORTED_HOST()
 if test "$supported_os" = "darwin"
 then
+  if test -z "$JAVA_HOME" -a -d /System/Library/Frameworks/JavaVM.framework/Home; then
+  	JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
+  fi
+
   _prevdir=`/bin/pwd`
-  cd $JAVA_HOME
-  cd ..
-  cd Headers
+  if test -n "$JAVA_HOME" -a -d "$JAVA_HOME/include"; then
+    cd "$JAVA_HOME/include"
+  elif test -n "$JAVA_HOME" -a -d "$JAVA_HOME/../Headers"; then
+    cd "$JAVA_HOME/../Headers"
+  else
+    cd /System/Library/Frameworks/JavaVM.framework/Headers
+  fi
   CFLAGS="$CFLAGS -I`/bin/pwd -P`"
   cd $_prevdir
   unset _prevdir
-else
+fi
+
+dnl -------------------------------------------------------------------------
+dnl Check JAVA environment
+dnl -------------------------------------------------------------------------
+AP_MSG_HEADER([Java compilation tools])
+AP_JAVA()
+AP_PROG_JAVAC()
+AP_PROG_JAR()
+if test "$supported_os" != "darwin"
+then
   CFLAGS="$CFLAGS -I$JAVA_HOME/include -I$JAVA_HOME/include/$supported_os"
 fi
 
diff --git a/src/native/unix/man/README b/src/native/unix/man/README
new file mode 100644
index 0000000..080250a
--- /dev/null
+++ b/src/native/unix/man/README
@@ -0,0 +1,20 @@
+To build it use:
+docbook2man jsvc.1.xml
+
+If your docbook2man uses xalan and you are behind a firewall
+Modify jsvc.1.xml as below:
++++
+Index: jsvc.1.xml
+===================================================================
+--- jsvc.1.xml	(revision 170004)
++++ jsvc.1.xml	(working copy)
+@@ -1,6 +1,6 @@
+ <?xml version="1.0" encoding="utf-8"?>
+ <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+-                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
++                   "docbookx.dtd">
+ <refentry id='jsvc1'>
+   <refmeta>
+     <refentrytitle>JSVC</refentrytitle>
++++
+Use fetch.sh to get docbook files.
diff --git a/src/native/unix/man/fetch.sh b/src/native/unix/man/fetch.sh
new file mode 100644
index 0000000..e950064
--- /dev/null
+++ b/src/native/unix/man/fetch.sh
@@ -0,0 +1,21 @@
+mkdir -p ent
+rm -f JSVC.1
+while true
+do
+  FILE=`docbook2man jsvc.1.xml 2>&1 | grep FileNotFoundException | awk -F FileNotFoundException: ' { print $2 } ' | awk ' { print $1 } '`
+  if [ -f JSVC.1 ]
+  then
+    break
+  fi
+  echo "FILE: $FILE"
+  file=`basename $FILE`
+  dir=`dirname $FILE`
+  man=`basename $dir`
+  echo "file: $file dir: $dir man: $man"
+  if [ "$man" = "ent" ]
+  then
+    (cd ent; wget http://www.oasis-open.org/docbook/xml/4.1.2/ent/$file)
+  else
+    wget http://www.oasis-open.org/docbook/xml/4.1.2/$file
+  fi
+done
diff --git a/src/native/unix/man/jsvc.1.xml b/src/native/unix/man/jsvc.1.xml
new file mode 100644
index 0000000..677e430
--- /dev/null
+++ b/src/native/unix/man/jsvc.1.xml
@@ -0,0 +1,172 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
+<refentry id='jsvc1'>
+  <refmeta>
+    <refentrytitle>JSVC</refentrytitle>
+    <manvolnum>1</manvolnum>
+    <refmiscinfo class='date'>May 2005</refmiscinfo>
+    <refmiscinfo class='source'>Jsvc version 1.0.1</refmiscinfo>
+    <refmiscinfo class='manual'>Jakarta project</refmiscinfo>
+  </refmeta>
+  <refnamediv id='name'>
+    <refname>jsvc</refname>
+    <refpurpose>application to launch java daemon</refpurpose>
+  </refnamediv>
+  <!-- body begins here -->
+  <refsynopsisdiv id='synopsis'>
+    <cmdsynopsis>
+      <command>jsvc</command>
+      <arg choice='opt'>-jvm <replaceable>JVM name</replaceable></arg>
+      <arg choice='opt'>-classpath <replaceable>path</replaceable></arg>
+      <arg choice='opt'>-cp <replaceable>path</replaceable></arg>
+      <arg choice='opt'>-home <replaceable>directory</replaceable></arg>
+      <arg choice='opt'>-version</arg>
+      <arg choice='opt'>-help</arg>
+      <arg choice='opt'>-?</arg>
+      <arg choice='opt'>-nodetach</arg>
+      <arg choice='opt'>-debug</arg>
+      <arg choice='opt'>-check</arg>
+      <arg choice='opt'>-user <replaceable>user</replaceable></arg>
+      <arg choice='opt'>-wait <replaceable>waittime</replaceable></arg>
+      <arg choice='opt'>-stop</arg>
+      <arg choice='opt'>-verbose<replaceable>:class|gc|jni</replaceable></arg>
+      <arg choice='opt'>-outfile <replaceable>/full/path/to/file</replaceable></arg>
+      <arg choice='opt'>-errfile <replaceable>/full/path/to/file</replaceable></arg>
+      <arg choice='opt'>-pidfile <replaceable>/full/path/to/file</replaceable></arg>
+      <arg choice='opt'>-Dproperty=<replaceable>value</replaceable></arg>
+      <arg choice='opt'>-X<replaceable>option</replaceable></arg>
+      <!-- end of the new arguments -->
+    </cmdsynopsis>
+  </refsynopsisdiv>
+  <refsect1 id="description">
+    <title>DESCRIPTION</title>
+    <para><command>jsvc</command> executes <emphasis remap="I">classfile</emphasis>
+    that implements a Daemon interface.</para>
+  </refsect1>
+
+  <refsect1 id="options">
+    <title>OPTIONS</title>
+
+    <variablelist remap="TP">
+      <varlistentry>
+        <term><option>-jvm</option> JVM name</term>
+        <listitem>
+          <para>use a specific Java Virtual Machine.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-cp/ -classpath</option> directory and zip/jar 
+          files</term>
+        <listitem>
+          <para>set search path for service classes and resouces</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-home</option> directory</term>
+        <listitem>
+          <para>set the path of your JDK or JRE installation (or set
+        				the JAVA_HOME environment variable)
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-version</option></term>
+        <listitem>
+          <para>show the current Java environment version (to check
+        				correctness of -home and -jvm. Implies -nodetach)</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-help</option></term>
+        <listitem>
+          <para>show this help page (implies -nodetach)</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-nodetach</option></term>
+        <listitem>
+          <para>don't detach from parent process and become a daemon</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-debug</option></term>
+        <listitem>
+          <para>verbosely print debugging information</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-check</option></term>
+        <listitem>
+          <para>only check service (implies -nodetach)</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-stop</option></term>
+        <listitem>
+          <para>stop the service using the file given in the -pidfile option</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-wait</option> waittime</term>
+        <listitem>
+          <para>wait up to waittime seconds for the service to start
+                                       waittime should multiple of 10 (min=10)
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-user</option> user</term>
+        <listitem>
+          <para>user used to run the daemon (defaults to current user)</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-verbose[:class|gc|jni]</option></term>
+        <listitem>
+          <para>enable verbose output</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-outfile</option> /full/path/to/file</term>
+        <listitem>
+          <para>Location for output from stdout (defaults to /dev/null). Use 
+            the value '&2' to simulate '1>&2'</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-errfile</option> /full/path/to/file</term>
+        <listitem>
+          <para>Location for output from stderr (defaults to /dev/null). Use 
+            the value '&1' to simulate '2>&1'</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-pidfile</option> /full/path/to/file</term>
+        <listitem>
+          <para>Location for output from the file containing the pid of jsvc 
+            (defaults to /var/run/jsvc.pid)</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-D</option><name>=<value></term>
+        <listitem>
+          <para>set a Java system property</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term><option>-X</option><option></term>
+        <listitem>
+          <para>set Virtual Machine specific option</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1 id='author'><title>AUTHOR</title>
+    <para>JSVC is part of the Jakarta Commons Daemon project. Authors are 
+      Jean-Frederic Clere, Remy Maucherat, Yoav Shapira, Bill Barker. JSVC is 
+      under the Apache License Version 2.0.</para>
+  </refsect1>
+
+</refentry>
diff --git a/src/native/unix/native/Makefile.in b/src/native/unix/native/Makefile.in
index 93ea2b7..6d319ae 100644
--- a/src/native/unix/native/Makefile.in
+++ b/src/native/unix/native/Makefile.in
@@ -14,7 +14,7 @@
 #   limitations under the License.
 #
 # @author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-# @version $Id: Makefile.in,v 1.2 2004/02/09 15:55:21 jfclere Exp $
+# @version $Id: Makefile.in 161711 2005-04-18 02:32:38Z billbarker $
 
 include ../Makedefs
 
diff --git a/src/native/unix/native/Tomcat5.sh b/src/native/unix/native/Tomcat5.sh
index 87a4c49..1f631ed 100755
--- a/src/native/unix/native/Tomcat5.sh
+++ b/src/native/unix/native/Tomcat5.sh
@@ -29,12 +29,17 @@
 # That is for Tomcat-5.0.x (Apache Tomcat/5.0)
 #
 # Adapt the following lines to your configuration
-JAVA_HOME=/usr/java/j2sdk1.4.2_03
-CATALINA_HOME=/home/tomcat5/jakarta-tomcat-5/build
-DAEMON_HOME=/home/tomcat5/jakarta-commons/daemon
+JAVA_HOME=/home2/java/j2sdk1.4.2_03
+CATALINA_HOME=/home/tomcat5/tomcat5/jakarta-tomcat-5/build
+DAEMON_HOME=/home/jfclere/daemon
 TOMCAT_USER=tomcat5
+
+# for multi instances adapt those lines.
 TMP_DIR=/var/tmp
-CATALINA_OPTS=
+PID_FILE=/var/run/jsvc.pid
+CATALINA_BASE=/home/tomcat5/tomcat5/jakarta-tomcat-5/build
+
+CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs"
 CLASSPATH=\
 $JAVA_HOME/lib/tools.jar:\
 $CATALINA_HOME/bin/commons-daemon.jar:\
@@ -49,7 +54,10 @@ case "$1" in
     -user $TOMCAT_USER \
     -home $JAVA_HOME \
     -Dcatalina.home=$CATALINA_HOME \
+    -Dcatalina.base=$CATALINA_BASE \
     -Djava.io.tmpdir=$TMP_DIR \
+    -wait 10 \
+    -pidfile $PID_FILE \
     -outfile $CATALINA_HOME/logs/catalina.out \
     -errfile '&1' \
     $CATALINA_OPTS \
@@ -60,14 +68,18 @@ case "$1" in
     #-verbose \
     # To get a debug of jsvc.
     #-debug \
+    exit $?
     ;;
 
   stop)
     #
     # Stop Tomcat
     #
-    PID=`cat /var/run/jsvc.pid`
-    kill $PID
+    $DAEMON_HOME/src/native/unix/jsvc \
+    -stop \
+    -pidfile $PID_FILE \
+    org.apache.catalina.startup.Bootstrap
+    exit $?
     ;;
 
   *)
diff --git a/src/native/unix/native/arguments.c b/src/native/unix/native/arguments.c
index d7cbd9d..2d9821b 100644
--- a/src/native/unix/native/arguments.c
+++ b/src/native/unix/native/arguments.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: arguments.c,v 1.4 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: arguments.c 165124 2005-04-28 09:36:02Z jfclere $ */
 #include "jsvc.h"
 
 /* Return the argument of a command line option */
@@ -42,6 +42,8 @@ static arg_data *parse(int argc, char *argv[]) {
     args->vers=false;           /* Don't display version */
     args->help=false;           /* Don't display help */
     args->chck=false;           /* Don't do a check-only startup */
+    args->stop=false;           /* Stop a running jsvc */
+    args->wait=0;               /* Wait until jsvc has started the JVM */
     args->install=false;        /* Don't install as a service */
     args->remove=false;         /* Don't remove the installed service */
     args->service=false;        /* Don't run as a service */
@@ -54,7 +56,7 @@ static arg_data *parse(int argc, char *argv[]) {
     args->outfile="/dev/null";   /* Swallow by default */
     args->errfile="/dev/null";   /* Swallow by default */
     args->args=(char **)malloc(argc*sizeof(char *));
-
+    args->procname = "jsvc.exec";
     /* Set up the command name */
     cmnd=strrchr(argv[0],'/');
     if (cmnd==NULL) cmnd=argv[0];
@@ -113,6 +115,18 @@ static arg_data *parse(int argc, char *argv[]) {
         } else if (strcmp(argv[x],"-debug")==0) {
             log_debug_flag=true;
 
+        } else if (strcmp(argv[x],"-wait")==0) {
+            temp=optional(argc,argv,x++);
+            if (temp!=NULL)
+                args->wait=atoi(temp);
+            if (args->wait<10) {
+                log_error("Invalid wait time specified (min=10)");
+                return(NULL);
+            }
+
+        } else if (strcmp(argv[x],"-stop")==0) {
+            args->stop=true;
+
         } else if (strcmp(argv[x],"-check")==0) {
             args->chck=true;
             args->dtch=false;
@@ -169,10 +183,19 @@ static arg_data *parse(int argc, char *argv[]) {
         } else if (strstr(argv[x],"-X")==argv[x]) {
             args->opts[args->onum++]=strdup(argv[x]);
 
+        } else if (strstr(argv[x],"-ea")==argv[x]) {
+            args->opts[args->onum++]=strdup(argv[x]);
+
         } else if (strstr(argv[x],"-")==argv[x]) {
             log_error("Invalid option %s",argv[x]);
             return(NULL);
 
+        } else if (strcmp(argv[x],"-procname") == 0) {
+            args->procname = optional(argc, argv, x++);
+            if(args->procname == NULL) {
+              log_error("Invalid process name specified");
+              return (NULL);
+            }
         } else {
             args->clas=strdup(argv[x]);
             break;
@@ -237,6 +260,10 @@ arg_data *arguments(int argc, char *argv[]) {
 
         log_debug("| Check Only:      %s",IsEnabledDisabled(args->chck));
 
+        log_debug("| Stop:            %s",IsTrueFalse(args->stop));
+
+        log_debug("| Wait:            %d",args->wait);
+
         log_debug("| Run as service:  %s",IsYesNo(args->service));
 
         log_debug("| Install service: %s",IsYesNo(args->install));
diff --git a/src/native/unix/native/arguments.h b/src/native/unix/native/arguments.h
index 2dd68f1..60886b6 100644
--- a/src/native/unix/native/arguments.h
+++ b/src/native/unix/native/arguments.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: arguments.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: arguments.h 165124 2005-04-28 09:36:02Z jfclere $ */
 #ifndef __JSVC_ARGUMENTS_H__
 #define __JSVC_ARGUMENTS_H__
 
@@ -51,6 +51,10 @@ typedef struct {
     bool help;
     /** Only check environment without running the service. */
     bool chck;
+    /** Stop running jsvc */
+    bool stop;
+    /** number of seconds to until service started */
+    int wait;
     /** Install as a service (win32) */
     bool install;
     /** Remove when installed as a service (win32) */
@@ -61,6 +65,8 @@ typedef struct {
     char *outfile;
     /** Destination for stderr */
     char *errfile;
+    /** Program name for Linux **/
+    char *procname;
 } arg_data;
 
 /**
diff --git a/src/native/unix/native/debug.c b/src/native/unix/native/debug.c
index 2ba44ed..32dc8cb 100644
--- a/src/native/unix/native/debug.c
+++ b/src/native/unix/native/debug.c
@@ -13,8 +13,11 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: debug.c,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: debug.c 165119 2005-04-28 09:00:08Z jfclere $ */
 #include "jsvc.h"
+#include <sys/types.h>
+#include <unistd.h>
+#include <time.h> 
 
 /* Wether debug is enabled or not */
 bool log_debug_flag = false;
@@ -25,12 +28,19 @@ char *log_prog = "jsvc";
 /* Dump a debug message to stderr */
 void log_debug(const char *fmt, ...) {
     va_list ap;
+    time_t now;
+    struct tm *nowtm;
+    char buff[80];
 
     if (log_debug_flag==false) return;
     if (fmt==NULL) return;
 
+    now = time(NULL);
+    nowtm = localtime(&now);
+    strftime(buff, sizeof(buff), "%d/%m/%Y %T", nowtm);
+
     va_start(ap,fmt);
-    fprintf(stderr,"%s debug: ",log_prog);
+    fprintf(stderr,"%s %d %s debug: ", buff,  getpid(), log_prog);
     vfprintf(stderr,fmt,ap);
     fprintf(stderr,"\n");
     fflush(stderr);
@@ -40,11 +50,18 @@ void log_debug(const char *fmt, ...) {
 /* Dump an error message to stderr */
 void log_error(const char *fmt, ...) {
     va_list ap;
+    time_t now;
+    struct tm *nowtm;
+    char buff[80];
 
     if (fmt==NULL) return;
 
+    now = time(NULL);
+    nowtm = localtime(&now);
+    strftime(buff, sizeof(buff), "%d/%m/%Y %T", nowtm);
+
     va_start(ap,fmt);
-    fprintf(stderr,"%s error: ",log_prog);
+    fprintf(stderr,"%s %d %s error: ", buff, getpid(), log_prog);
     vfprintf(stderr,fmt,ap);
     fprintf(stderr,"\n");
     fflush(stderr);
diff --git a/src/native/unix/native/debug.h b/src/native/unix/native/debug.h
index 6baf555..a8fd994 100644
--- a/src/native/unix/native/debug.h
+++ b/src/native/unix/native/debug.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: debug.h,v 1.3 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: debug.h 155409 2005-02-26 12:57:06Z dirkv $ */
 #ifndef __JSVC_DEBUG_H__
 #define __JSVC_DEBUG_H__
 
diff --git a/src/native/unix/native/dso-dlfcn.c b/src/native/unix/native/dso-dlfcn.c
index 9611a45..827abd1 100644
--- a/src/native/unix/native/dso-dlfcn.c
+++ b/src/native/unix/native/dso-dlfcn.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: dso-dlfcn.c,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: dso-dlfcn.c 155409 2005-02-26 12:57:06Z dirkv $ */
 #include "jsvc.h"
 
 #ifdef DSO_DLFCN
diff --git a/src/native/unix/native/dso-dyld.c b/src/native/unix/native/dso-dyld.c
index 2dfcef5..fa0e350 100644
--- a/src/native/unix/native/dso-dyld.c
+++ b/src/native/unix/native/dso-dyld.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: dso-dyld.c,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: dso-dyld.c 155409 2005-02-26 12:57:06Z dirkv $ */
 #include "jsvc.h"
 
 #ifdef DSO_DYLD
diff --git a/src/native/unix/native/dso.h b/src/native/unix/native/dso.h
index f9b330d..4023cec 100644
--- a/src/native/unix/native/dso.h
+++ b/src/native/unix/native/dso.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: dso.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: dso.h 155409 2005-02-26 12:57:06Z dirkv $ */
 #include "jsvc.h"
 
 /**
diff --git a/src/native/unix/native/help.c b/src/native/unix/native/help.c
index f2c145b..6620633 100644
--- a/src/native/unix/native/help.c
+++ b/src/native/unix/native/help.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: help.c,v 1.4 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: help.c 169613 2005-05-11 09:52:00Z jfclere $ */
 #include "jsvc.h"
 
 void help(home_data *data) {
@@ -55,7 +55,7 @@ void help(home_data *data) {
     printf("    -check\n");
     printf("        only check service (implies -nodetach)\n");
  
-    printf("    -user\n");
+    printf("    -user <user>\n");
     printf("        user used to run the daemon (defaults to current user)\n");
  
     printf("    -verbose[:class|gc|jni]\n");
@@ -79,5 +79,12 @@ void help(home_data *data) {
     printf("    -X<option>\n");
     printf("        set Virtual Machine specific option\n");
 
+    printf("    -wait <waittime>\n");
+    printf("        wait waittime seconds for the service to start\n");
+    printf("        waittime should multiple of 10 (min=10)\n");
+
+    printf("    -stop\n");
+    printf("        stop the service using the file given in the -pidfile option\n");
+
     printf("\n");
 }
diff --git a/src/native/unix/native/help.h b/src/native/unix/native/help.h
index b765983..2c46c64 100644
--- a/src/native/unix/native/help.h
+++ b/src/native/unix/native/help.h
@@ -13,5 +13,5 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: help.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: help.h 155409 2005-02-26 12:57:06Z dirkv $ */
 void help(home_data *data);
diff --git a/src/native/unix/native/home.c b/src/native/unix/native/home.c
index 596519c..f57131c 100644
--- a/src/native/unix/native/home.c
+++ b/src/native/unix/native/home.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: home.c,v 1.7 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: home.c 155409 2005-02-26 12:57:06Z dirkv $ */
 #include "jsvc.h"
 
 /* Check if a path is a directory */
diff --git a/src/native/unix/native/home.h b/src/native/unix/native/home.h
index d4d6f56..6415f28 100644
--- a/src/native/unix/native/home.h
+++ b/src/native/unix/native/home.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: home.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: home.h 155409 2005-02-26 12:57:06Z dirkv $ */
 #ifndef __JSVC_HOME_H__
 #define __JSVC_HOME_H__
 
diff --git a/src/native/unix/native/java.c b/src/native/unix/native/java.c
index f00b458..af5ff3a 100644
--- a/src/native/unix/native/java.c
+++ b/src/native/unix/native/java.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: java.c,v 1.3 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: java.c 169326 2005-05-09 15:14:56Z jfclere $ */
 #include "jsvc.h"
 
 #ifdef OS_CYGWIN
@@ -44,6 +44,11 @@ static void shutdown(JNIEnv *env, jobject source, jboolean reload) {
     if (reload==TRUE) main_reload();
     else main_shutdown();
 }
+/* Automaticly restart when the JVM crashes */
+static void java_abort123()
+{
+    exit(123);
+}
 
 char *java_library(arg_data *args, home_data *data) {
     char *libf=NULL;
@@ -81,6 +86,7 @@ bool java_init(arg_data *args, home_data *data) {
 #ifdef OS_DARWIN
     dso_handle apph=NULL;
     char appf[1024];
+    struct stat sb;
 #endif /* ifdef OS_DARWIN */
     jint (*symb)(JavaVM **, JNIEnv **, JavaVMInitArgs *);
     JNINativeMethod nativemethod;
@@ -108,6 +114,8 @@ bool java_init(arg_data *args, home_data *data) {
     }
 
     /* Load the JVM library */
+#ifdef OSD_POSIX
+#else
     libh=dso_link(libf);
     if (libh==NULL) {
         log_error("Cannot dynamically link to %s",libf);
@@ -115,15 +123,27 @@ bool java_init(arg_data *args, home_data *data) {
         return(false);
     }
     log_debug("JVM library %s loaded",libf);
+#endif
 
 #ifdef OS_DARWIN
-    /* MacOS/X actually has two libraries, one with the REAL vm, and one for
-       the VM startup. The first one (libappshell.dyld) contains CreateVM */
+    /*
+       MacOS/X actually has two libraries, one with the REAL vm, and one for
+       the VM startup.
+       before JVM 1.4.1 The first one (libappshell.dyld) contains CreateVM
+       after JVM 1.4.1 The library name is libjvm_compat.dylib.
+    */
     if (replace(appf,1024,"$JAVA_HOME/../Libraries/libappshell.dylib",
                  "$JAVA_HOME",data->path)!=0) {
         log_error("Cannot replace values in loader library");
         return(false);
     }
+    if (stat(appf, &sb)) {
+        if (replace(appf,1024,"$JAVA_HOME/../Libraries/libjvm_compat.dylib",
+                    "$JAVA_HOME",data->path)!=0) {
+            log_error("Cannot replace values in loader library");
+            return(false);
+        }
+    }
     apph=dso_link(appf);
     if (apph==NULL) {
         log_error("Cannot load required shell library %s",appf);
@@ -131,6 +151,8 @@ bool java_init(arg_data *args, home_data *data) {
     }
     log_debug("Shell library %s loaded",appf);
 #endif /* ifdef OS_DARWIN */
+#ifdef OSD_POSIX
+#else
     symb=dso_symbol(libh,"JNI_CreateJavaVM");
     if (symb==NULL) {
 #ifdef OS_DARWIN
@@ -144,22 +166,38 @@ bool java_init(arg_data *args, home_data *data) {
 #endif /* ifdef OS_DARWIN */
     }
     log_debug("JVM library entry point found (0x%08X)",symb);
+#endif
 
     /* Prepare the VM initialization arguments */
-    arg.version=JNI_VERSION_1_2;
+    
+    /*
+    	Mac OS X Java will load JVM 1.3.1 instead of 1.4.2 if JNI_VERSION_1_2
+    	is specified. So use JNI_VERSION_1_4 if we can.
+    */
+    #if defined(JNI_VERSION_1_4)
+        arg.version=JNI_VERSION_1_4;
+    #else
+        arg.version=JNI_VERSION_1_2;
+    #endif
+#ifdef OSD_POSIX_JFC
+    if (JNI_GetDefaultJavaVMInitArgs(&arg)<0) {
+        log_error("Cannot init default JVM default args");
+        return(false);
+    }
+#endif
     arg.ignoreUnrecognized=FALSE;
     arg.nOptions=args->onum;
-    if (arg.nOptions==0) {
-        arg.options=NULL;
-    } else {
-        opt=(JavaVMOption *)malloc(arg.nOptions*sizeof(JavaVMOption));
-        for (x=0; x<args->onum; x++) {
-            opt[x].optionString=strdup(args->opts[x]);
-            jsvc_xlate_to_ascii(opt[x].optionString);
-            opt[x].extraInfo=NULL;
-        }
-        arg.options=opt;
+    arg.nOptions++; /* Add abort code */
+    opt=(JavaVMOption *)malloc(arg.nOptions*sizeof(JavaVMOption));
+    for (x=0; x<args->onum; x++) {
+        opt[x].optionString=strdup(args->opts[x]);
+        jsvc_xlate_to_ascii(opt[x].optionString);
+        opt[x].extraInfo=NULL;
     }
+    opt[x].optionString=strdup("abort");
+    jsvc_xlate_to_ascii(opt[x].optionString);
+    opt[x].extraInfo=java_abort123;
+    arg.options=opt;
 
     /* Do some debugging */
     if (log_debug_flag==true) {
@@ -179,8 +217,12 @@ bool java_init(arg_data *args, home_data *data) {
     }
 
     /* And finally create the Java VM */
+#ifdef OSD_POSIX
+    ret=JNI_CreateJavaVM(&jvm, &env, &arg);
+#else
     ret=(*symb)(&jvm, &env, &arg);
-    if (ret!=0) {
+#endif
+    if (ret<0) {
         log_error("Cannot create Java VM");
         return(false);
     }
@@ -229,7 +271,7 @@ bool JVM_destroy(int exit) {
     jsvc_xlate_to_ascii(exitparams);
     method=(*env)->GetStaticMethodID(env,system,exitclass,exitparams);
     if (method==NULL) {
-        log_error("Cannot found \"System.exit(int)\" entry point");
+        log_error("Cannot find \"System.exit(int)\" entry point");
         return(false);
     }
 
@@ -293,7 +335,7 @@ bool java_load(arg_data *args) {
     jsvc_xlate_to_ascii(loadparams);
     method=(*env)->GetStaticMethodID(env,cls,load,loadparams);
     if (method==NULL) {
-        log_error("Cannot found Daemon Loader \"load\" entry point");
+        log_error("Cannot find Daemon Loader \"load\" entry point");
         return(false);
     }
 
@@ -318,7 +360,7 @@ bool java_start(void) {
     jsvc_xlate_to_ascii(startparams); 
     method=(*env)->GetStaticMethodID(env,cls,start,startparams);
     if (method==NULL) {
-        log_error("Cannot found Daemon Loader \"start\" entry point");
+        log_error("Cannot find Daemon Loader \"start\" entry point");
         return(false);
     }
 
@@ -332,6 +374,34 @@ bool java_start(void) {
     return(true);
 }
 
+/*
+ * call the java sleep to prevent problems with threads
+ */
+void java_sleep(int wait) {
+    jclass clsThread;
+    jmethodID method;
+    char jsleep[]="sleep";
+    char jsleepparams[]="(J)V";
+    char jthread[]="java/lang/Thread"; 
+ 
+    jsvc_xlate_to_ascii(jsleep);
+    jsvc_xlate_to_ascii(jsleepparams);
+    jsvc_xlate_to_ascii(jthread);
+
+    clsThread = (*env)->FindClass(env,jthread);
+    if (clsThread==NULL) {
+        log_error("Cannot find java/lang/Thread class");
+        return;
+    }
+    method=(*env)->GetStaticMethodID(env,clsThread,jsleep,jsleepparams);
+    if (method==NULL) {
+        log_error("Cannot found the sleep entry point");
+        return;
+    }
+ 
+    (*env)->CallStaticVoidMethod(env,clsThread,method,(jlong)wait*1000);
+}
+
 /* Call the stop method in our daemon loader */
 bool java_stop(void) {
     jmethodID method;
diff --git a/src/native/unix/native/java.h b/src/native/unix/native/java.h
index 42d13fd..75d0bb1 100644
--- a/src/native/unix/native/java.h
+++ b/src/native/unix/native/java.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: java.h,v 1.3 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: java.h 155409 2005-02-26 12:57:06Z dirkv $ */
 
 #define LOADER "org/apache/commons/daemon/support/DaemonLoader"
 
diff --git a/src/native/unix/native/jsvc-unix.c b/src/native/unix/native/jsvc-unix.c
index 2ff271f..d284fe0 100644
--- a/src/native/unix/native/jsvc-unix.c
+++ b/src/native/unix/native/jsvc-unix.c
@@ -13,14 +13,18 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: jsvc-unix.c,v 1.9 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: jsvc-unix.c 170536 2005-05-17 08:02:30Z jfclere $ */
 #include "jsvc.h"
 
 #include <signal.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
+#include <fcntl.h>
+#include <stdio.h>
 #include <pwd.h>
+#include <grp.h>
 #ifdef OS_LINUX
 #include <sys/prctl.h>
 #include <sys/syscall.h>
@@ -46,7 +50,6 @@ static void handler(int sig) {
             } else {
                 stopping=true;
             }
-            if (handler_trm!=NULL) (*handler_trm)(sig);
             break;
         }
 
@@ -57,7 +60,6 @@ static void handler(int sig) {
             } else {
                 stopping=true;
             }
-            if (handler_int!=NULL) (*handler_int)(sig);
             break;
         }
 
@@ -69,7 +71,6 @@ static void handler(int sig) {
                 stopping=true;
                 doreload=true;
             }
-            if (handler_hup!=NULL) (*handler_hup)(sig);
             break;
         }
 
@@ -88,6 +89,13 @@ static int set_user_group(char *user, int uid, int gid)
             log_error("Cannot set group id for user '%s'",user);
             return(-1);
         }
+        if (initgroups(user, gid)!=0) {
+            if (getuid()!= uid) {
+                log_error("Cannot set supplement group list for user '%s'",user);
+                return(-1);
+            } else
+                log_debug("Cannot set supplement group list for user '%s'",user);
+        }
         if (setuid(uid)!=0) {
             log_error("Cannot set user id for user '%s'",user);
             return(-1);
@@ -134,8 +142,13 @@ static int set_caps(int caps)
 static int linuxset_user_group(char *user, int uid, int gid)
 {
     /* set capabilities enough for binding port 80 setuid/getuid */
-    if (set_caps(CAPS)!=0)
-        return(-1);
+    if (set_caps(CAPS)!=0) {
+        if (getuid()!= uid) {
+            log_error("set_caps(CAPS) failed");
+            return(-1);
+        }
+        log_debug("set_caps(CAPS) failed");
+    }
 
     /* make sure they are kept after setuid */ 
     if (prctl(PR_SET_KEEPCAPS,1,0,0,0) < 0) {
@@ -150,8 +163,13 @@ static int linuxset_user_group(char *user, int uid, int gid)
     }
 
     /* set capability to binding port 80 read conf */
-    if (set_caps(CAPSMIN)!=0)
-        return(-1);
+    if (set_caps(CAPSMIN)!=0) {
+        if (getuid()!= uid) {
+            log_error("set_caps(CAPSMIN) failed");
+            return(-1);
+        }
+        log_debug("set_caps(CAPSMIN) failed");
+    }
 
     return(0);
 }
@@ -243,20 +261,209 @@ static void * signal_set(int sig, void * newHandler) {
 }
 
 /*
+ * Check pid and if still running
+ */
+
+static int check_pid(arg_data *args) {
+    int fd;
+    FILE *pidf;
+    char buff[80];
+    pid_t pidn=getpid();
+    int i,pid;
+
+    fd = open(args->pidf,O_RDWR|O_CREAT,S_IRUSR|S_IWUSR);
+    if (fd<0) {
+        log_error("Cannot open PID file %s, PID is %d",args->pidf,pidn);
+        return(-1);
+    } else {
+        lockf(fd,F_LOCK,0);
+        i = read(fd,buff,sizeof(buff));
+        if (i>0) {
+            buff[i] = '\0';
+            pid = atoi(buff);
+            if (kill(pid, 0)==0) {
+                log_error("Still running according to PID file %s, PID is %d",args->pidf,pid);
+                lockf(fd,F_ULOCK,0);
+                close(fd);
+                return(122);
+            }
+        }
+
+        /* skip writing the pid file if version or check */
+        if (args->vers!=true && args->chck!=true) {
+            lseek(fd, SEEK_SET, 0);
+            pidf = fdopen(fd,"r+");
+            fprintf(pidf,"%d\n",(int)getpid());
+            fflush(pidf);
+            lockf(fd,F_ULOCK,0);
+            fclose(pidf);
+            close(fd);
+        } else {
+            lockf(fd,F_ULOCK,0);
+            close(fd);
+        }
+    }
+    return(0);
+}
+
+/*
+ * read the pid from the pidfile
+ */
+static int get_pidf(arg_data *args) {
+    int fd;
+    int i;
+    char buff[80];
+
+    fd = open(args->pidf, O_RDONLY, 0);
+    log_debug("get_pidf: %d in %s", fd, args->pidf);
+    if (fd<0)
+        return(-1); /* something has gone wrong the JVM has stopped */
+    lockf(fd,F_LOCK,0);
+    i = read(fd,buff,sizeof(buff));
+    lockf(fd,F_ULOCK,0);
+    close(fd);
+    if (i>0) {
+        buff[i] = '\0';
+        i = atoi(buff);
+        log_debug("get_pidf: pid %d", i);
+        if (kill(i, 0)==0)
+            return(i);
+    }
+    return(-1);
+}
+
+/*
+ * Check temporatory file created by controller
+ * /tmp/pid.jsvc_up
+ * Notes:
+ * we fork several times
+ * 1 - to be a daemon before the setsid(), the son is the controler process.
+ * 2 - to start the JVM in the son process. (whose pid is stored in pidfile).
+ */
+static int check_tmp_file(arg_data *args) {
+    int pid;
+    char buff[80];
+    int fd;
+    pid = get_pidf(args);
+    if (pid<0)
+        return(-1);
+    sprintf(buff,"/tmp/%d.jsvc_up", pid);
+    log_debug("check_tmp_file: %s", buff);
+    fd = open(buff, O_RDONLY);
+    if (fd<0)
+        return(-1);
+    close(fd);
+    return(0);
+}
+static void create_tmp_file(arg_data *args) {
+    char buff[80];
+    int fd;
+    sprintf(buff,"/tmp/%d.jsvc_up", (int) getpid());
+    log_debug("create_tmp_file: %s", buff);
+    fd = open(buff, O_RDWR|O_CREAT,S_IRUSR|S_IWUSR);
+    if (fd<0)
+        return;
+    close(fd);
+}
+static void remove_tmp_file(arg_data *args) {
+    char buff[80];
+    sprintf(buff,"/tmp/%d.jsvc_up", (int) getpid());
+    log_debug("remove_tmp_file: %s", buff);
+    unlink(buff);
+}
+
+/*
+ * wait until jsvc create the I am ready file
+ * pid is the controller and args->pidf the JVM itself.
+ */
+static int wait_child(arg_data *args, int pid) {
+    int count=10;
+    bool havejvm=false;
+    int fd;
+    char buff[80];
+    int i, status, waittime;
+    log_debug("wait_child %d", pid);
+    waittime = args->wait/10;
+    if (waittime>10) {
+        count = waittime;
+        waittime = 10;
+    }
+    while (count>0) {
+        sleep(1);
+        /* check if the controler is still running */
+        if (waitpid(pid,&status,WNOHANG)==pid) {
+            if (WIFEXITED(status))
+                return(WEXITSTATUS(status));
+            else
+                return(1);
+        }
+
+        /* check if the pid file process exists */
+        fd = open(args->pidf, O_RDONLY);
+        if (fd<0 && havejvm)
+            return(1); /* something has gone wrong the JVM has stopped */
+        lockf(fd,F_LOCK,0);
+        i = read(fd,buff,sizeof(buff));
+        lockf(fd,F_ULOCK,0);
+        close(fd);
+        if (i>0) {
+            buff[i] = '\0';
+            i = atoi(buff);
+            if (kill(i, 0)==0) {
+                /* the JVM process has started */
+                havejvm=true;
+                if (check_tmp_file(args)==0) {
+                    /* the JVM is started */
+                    if (waitpid(pid,&status,WNOHANG)==pid) {
+                        if (WIFEXITED(status))
+                            return(WEXITSTATUS(status));
+                        else
+                            return(1);
+                    }
+                    return(0); /* ready JVM started */
+                }
+            }
+        }
+        sleep(waittime);
+        count--;
+    }
+    return(1); /* It takes more than the wait time to start, something must be wrong */
+}
+
+/*
+ * stop the running jsvc
+ */
+static int stop_child(arg_data *args) {
+    int pid=get_pidf(args);
+    int count=10;
+    if (pid>0) {
+        /* kill the process and wait until the pidfile has been removed by the controler */
+        kill(pid,SIGTERM);
+        while (count>0) {
+            sleep(6);
+            pid=get_pidf(args);
+            if (pid<=0)
+                return(0); /* JVM has stopped */
+            count--;
+        }
+    }
+    return(-1);
+}
+
+/*
  * son process logic.
  */
 
 static int child(arg_data *args, home_data *data, uid_t uid, gid_t gid) {
-    FILE *pidf=fopen(args->pidf,"w");
-    pid_t pidn=getpid();
     int ret=0;
 
-    /* Write the our pid in the pid file */
-    if (pidf!=NULL) {
-        fprintf(pidf,"%d\n",(int)pidn);
-        fclose(pidf);
-    } else {
-        log_error("Cannot open PID file %s, PID is %d",args->pidf,pidn);
+    /* check the pid file */
+    ret = check_pid(args); 
+    if (args->vers!=true && args->chck!=true) {
+        if (ret==122)
+            return(ret);
+        if (ret<0)
+            return(ret);
     }
 
     /* create a new process group to prevent kill 0 killing the monitor process */
@@ -282,8 +489,8 @@ static int child(arg_data *args, home_data *data, uid_t uid, gid_t gid) {
     }
 
     /* Do we have to do a "check-only" initialization? */
-    if (java_check(args)!=true) return(2);
-    else if (args->chck==true) {
+    if (args->chck==true) {
+        if (java_check(args)!=true) return(2);
         printf("Service \"%s\" checked successfully\n",args->clas);
         return(0);
     }
@@ -311,7 +518,16 @@ static int child(arg_data *args, home_data *data, uid_t uid, gid_t gid) {
     handler_int=signal_set(SIGINT,handler);
     controlled = getpid();
     log_debug("Waiting for a signal to be delivered");
-    while (!stopping) sleep(60); /* pause() not threadsafe */
+    create_tmp_file(args);
+    while (!stopping) {
+#ifdef OSD_POSIX
+        java_sleep(60);
+        /* pause(); */
+#else
+        sleep(60); /* pause() not threadsafe */
+#endif
+    }
+    remove_tmp_file(args);
     log_debug("Shutdown or reload requested: exiting");
 
     /* Stop the service */
@@ -389,6 +605,10 @@ int main(int argc, char *argv[]) {
     args=arguments(argc,argv);
     if (args==NULL) return(1);
 
+    /* Stop running jsvc if required */
+    if (args->stop==true)
+        return(stop_child(args));
+
     /* Let's check if we can switch user/group IDs */
     if (checkuser(args->user, &uid, &gid)==false) return(1);
 
@@ -406,7 +626,7 @@ int main(int argc, char *argv[]) {
     /* On some UNIX operating systems, we need to REPLACE this current
        process image with another one (thru execve) to allow the correct
        loading of VMs (notably this is for Linux). Set, replace, and go. */
-    if (strcmp(argv[0],"jsvc.exec")!=0) {
+    if (strcmp(argv[0],args->procname)!=0) {
         char *oldpath=getenv("LD_LIBRARY_PATH");
         char *libf=java_library(args,data);
         char *old=argv[0];
@@ -431,7 +651,7 @@ int main(int argc, char *argv[]) {
 
         log_debug("Invoking w/ LD_LIBRARY_PATH=%s",getenv("LD_LIBRARY_PATH"));
 
-        argv[0]="jsvc.exec";
+        argv[0]=args->procname;
         execve(old,argv,environ);
         log_error("Cannot execute JSVC executor process");
         return(1);
@@ -446,8 +666,13 @@ int main(int argc, char *argv[]) {
             log_error("Cannot detach from parent process");
             return(1);
         }
-        /* If we're in the parent process, we siply quit */
-        if (pid!=0) return(0);
+        /* If we're in the parent process */
+        if (pid!=0) {
+            if (args->wait>=10)
+                return(wait_child(args,pid));
+            else
+                return(0);
+        }
 #ifndef NO_SETSID
         setsid();
 #endif
@@ -477,6 +702,10 @@ int main(int argc, char *argv[]) {
         if (WIFEXITED(status)) {
             status=WEXITSTATUS(status);
 
+            /* Delete the pid file */
+            if (args->vers!=true && args->chck!=true && status!=122)
+                unlink(args->pidf);
+
             /* If the child got out with 123 he wants to be restarted */
             if (status==123) {
                 log_debug("Reloading service");
diff --git a/src/native/unix/native/jsvc.h b/src/native/unix/native/jsvc.h
index aa1255f..0117179 100644
--- a/src/native/unix/native/jsvc.h
+++ b/src/native/unix/native/jsvc.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: jsvc.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: jsvc.h 155409 2005-02-26 12:57:06Z dirkv $ */
 #ifndef __JSVC_H__
 #define __JSVC_H__
 
diff --git a/src/native/unix/native/location.c b/src/native/unix/native/location.c
index e6721cc..4355c5e 100644
--- a/src/native/unix/native/location.c
+++ b/src/native/unix/native/location.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: location.c,v 1.3 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: location.c 165006 2005-04-27 16:28:57Z jfclere $ */
 #include "jsvc.h"
 
 /* Locations of various JVM files. We have to deal with all this madness since
@@ -37,6 +37,9 @@ char *location_home[] = {
 #elif defined(OS_SYSV)
     "/opt/java",
     "/opt/java/jdk13",
+#elif defined(OS_TRU64)
+    "/usr/opt/java142",
+    "/usr/opt/java13",
 #endif
     NULL,
 };
@@ -49,6 +52,8 @@ char *location_home[] = {
 char *location_jvm_cfg[] = {
     "$JAVA_HOME/jre/lib/jvm.cfg", /* JDK */
     "$JAVA_HOME/lib/jvm.cfg",     /* JRE */
+    "$JAVA_HOME/jre/lib/" CPU "/jvm.cfg", /* JDK */
+    "$JAVA_HOME/lib/" CPU "/jvm.cfg",     /* JRE */
     NULL,
 };
 
@@ -60,7 +65,7 @@ char *location_jvm_default[] = {
 #elif defined(OS_CYGWIN)
     "$JAVA_HOME/jre/bin/classic/jvm.dll",           /* Sun JDK 1.3 */
     "$JAVA_HOME/jre/bin/client/jvm.dll",            /* Sun JDK 1.4 */
-#elif defined(OS_LINUX) || defined(OS_SOLARIS) || defined(OS_BSD) || defined(OS_SYSV) || defined(OS_FREEBSD)
+#elif defined(OS_LINUX) || defined(OS_SOLARIS) || defined(OS_BSD) || defined(OS_SYSV) || defined(OS_FREEBSD) || defined(OS_TRU64)
     "$JAVA_HOME/jre/lib/" CPU "/classic/libjvm.so", /* Sun JDK 1.2 */
     "$JAVA_HOME/jre/lib/" CPU "/client/libjvm.so",  /* Sun JDK 1.3 */
     "$JAVA_HOME/jre/lib/" CPU "/libjvm.so",         /* Sun JDK */
@@ -74,6 +79,10 @@ char *location_jvm_default[] = {
     /* Those are "weirdos: if we got here, we're probably in troubles and
        we're not going to find anything, but hope never dies... */
     "$JAVA_HOME/jre/lib/" CPU "/classic/green_threads/libjvm.so",
+#if defined(OSD_POSIX)
+    "$JAVA_HOME/lib/s390/client/green_threads/libjvm.so",
+    "$JAVA_HOME/lib/sparc/client/green_threads/libjvm.so",
+#endif
     "$JAVA_HOME/jre/lib/classic/libjvm.so",
     "$JAVA_HOME/jre/lib/client/libjvm.so",
     "$JAVA_HOME/jre/lib/libjvm.so",
@@ -86,6 +95,10 @@ char *location_jvm_default[] = {
     "$JAVA_HOME/bin/classic/libjvm.so",
     "$JAVA_HOME/bin/client/libjvm.so",
     "$JAVA_HOME/bin/libjvm.so",
+    "$JAVA_HOME/jre/lib/" CPU "/fast64/libjvm.so",
+    "$JAVA_HOME/jre/lib/" CPU "/fast32/libjvm.so",
+    "$JAVA_HOME/lib/" CPU "/fast64/libjvm.so",
+    "$JAVA_HOME/lib/" CPU "/fast32/libjvm.so",
 #endif
     NULL,
 };
@@ -98,7 +111,7 @@ char *location_jvm_configured[] = {
     "$JAVA_HOME/../Libraries/lib$VM_NAME.dylib",
 #elif defined(OS_CYGWIN)
     "$JAVA_HOME/jre/bin/$VM_NAME/jvm.dll",          /* Sun JDK 1.3 */
-#elif defined(OS_LINUX) || defined(OS_SOLARIS) || defined(OS_BSD) || defined(OS_FREEBSD)
+#elif defined(OS_LINUX) || defined(OS_SOLARIS) || defined(OS_BSD) || defined(OS_FREEBSD) || defined(OS_TRU64)
     "$JAVA_HOME/jre/lib/" CPU "/$VM_NAME/libjvm.so",/* Sun JDK 1.3 */
     "$JAVA_HOME/lib/" CPU "/$VM_NAME/libjvm.so",    /* Sun JRE 1.3 */
 #elif defined(OS_SYSV)
diff --git a/src/native/unix/native/location.h b/src/native/unix/native/location.h
index 4ab3c32..43ed596 100644
--- a/src/native/unix/native/location.h
+++ b/src/native/unix/native/location.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: location.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: location.h 155409 2005-02-26 12:57:06Z dirkv $ */
 #include "jsvc.h"
 
 extern char *location_home[];
diff --git a/src/native/unix/native/replace.c b/src/native/unix/native/replace.c
index 3e91783..bae7154 100644
--- a/src/native/unix/native/replace.c
+++ b/src/native/unix/native/replace.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: replace.c,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: replace.c 155409 2005-02-26 12:57:06Z dirkv $ */
 #include "jsvc.h"
 
 /* Replace all occurrences of a string in another */
diff --git a/src/native/unix/native/replace.h b/src/native/unix/native/replace.h
index a111a4a..8f310a2 100644
--- a/src/native/unix/native/replace.h
+++ b/src/native/unix/native/replace.h
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: replace.h,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: replace.h 155409 2005-02-26 12:57:06Z dirkv $ */
 #ifndef __JSVC_REPLACE_H__
 #define __JSVC_REPLACE_H__
 
diff --git a/src/native/unix/native/signals.c b/src/native/unix/native/signals.c
index 87fdaf0..162cff7 100644
--- a/src/native/unix/native/signals.c
+++ b/src/native/unix/native/signals.c
@@ -13,7 +13,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 */
-/* @version $Id: signals.c,v 1.2 2004/02/09 15:55:21 jfclere Exp $ */
+/* @version $Id: signals.c 155409 2005-02-26 12:57:06Z dirkv $ */
 
 /*
  * as Windows does not support signal, jsvc use event to emulate them.
diff --git a/src/native/unix/support/apfunctions.m4 b/src/native/unix/support/apfunctions.m4
index b535245..703f09f 100644
--- a/src/native/unix/support/apfunctions.m4
+++ b/src/native/unix/support/apfunctions.m4
@@ -1,63 +1,22 @@
-dnl =========================================================================
 dnl
-dnl                 The Apache Software License,  Version 1.1
+dnl Copyright 1999-2004 The Apache Software Foundation
 dnl
-dnl          Copyright (c) 1999-2001 The Apache Software Foundation.
-dnl                           All rights reserved.
+dnl Licensed under the Apache License, Version 2.0 (the "License");
+dnl you may not use this file except in compliance with the License.
+dnl You may obtain a copy of the License at
 dnl
-dnl =========================================================================
+dnl     http://www.apache.org/licenses/LICENSE-2.0
 dnl
-dnl Redistribution and use in source and binary forms,  with or without modi-
-dnl fication, are permitted provided that the following conditions are met:
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
 dnl
-dnl 1. Redistributions of source code  must retain the above copyright notice
-dnl    notice, this list of conditions and the following disclaimer.
-dnl
-dnl 2. Redistributions  in binary  form  must  reproduce the  above copyright
-dnl    notice,  this list of conditions  and the following  disclaimer in the
-dnl    documentation and/or other materials provided with the distribution.
-dnl
-dnl 3. The end-user documentation  included with the redistribution,  if any,
-dnl    must include the following acknowlegement:
-dnl
-dnl       "This product includes  software developed  by the Apache  Software
-dnl        Foundation <http://www.apache.org/>."
-dnl
-dnl    Alternately, this acknowlegement may appear in the software itself, if
-dnl    and wherever such third-party acknowlegements normally appear.
-dnl
-dnl 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software
-dnl    Foundation"  must not be used  to endorse or promote  products derived
-dnl    from this  software without  prior  written  permission.  For  written
-dnl    permission, please contact <apache at apache.org>.
-dnl
-dnl 5. Products derived from this software may not be called "Apache" nor may
-dnl    "Apache" appear in their names without prior written permission of the
-dnl    Apache Software Foundation.
-dnl
-dnl THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES
-dnl INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY
-dnl AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL
-dnl THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY
-dnl DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL
-dnl DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS
-dnl OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION)
-dnl HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT,
-dnl STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-dnl ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE
-dnl POSSIBILITY OF SUCH DAMAGE.
-dnl
-dnl =========================================================================
-dnl
-dnl This software  consists of voluntary  contributions made  by many indivi-
-dnl duals on behalf of the  Apache Software Foundation.  For more information
-dnl on the Apache Software Foundation, please see <http://www.apache.org/>.
-dnl
-dnl =========================================================================
 
 dnl -------------------------------------------------------------------------
 dnl Author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-dnl Version $Id: apfunctions.m4,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $
+dnl Version $Id: apfunctions.m4 140756 2004-02-27 08:40:46Z jfclere $
 dnl -------------------------------------------------------------------------
 
 AC_DEFUN(AP_MSG_HEADER,[
diff --git a/src/native/unix/support/apjava.m4 b/src/native/unix/support/apjava.m4
index e190b9f..f5b766b 100644
--- a/src/native/unix/support/apjava.m4
+++ b/src/native/unix/support/apjava.m4
@@ -1,63 +1,22 @@
-dnl =========================================================================
 dnl
-dnl                 The Apache Software License,  Version 1.1
+dnl Copyright 1999-2004 The Apache Software Foundation
 dnl
-dnl          Copyright (c) 1999-2001 The Apache Software Foundation.
-dnl                           All rights reserved.
+dnl Licensed under the Apache License, Version 2.0 (the "License");
+dnl you may not use this file except in compliance with the License.
+dnl You may obtain a copy of the License at
 dnl
-dnl =========================================================================
+dnl     http://www.apache.org/licenses/LICENSE-2.0
 dnl
-dnl Redistribution and use in source and binary forms,  with or without modi-
-dnl fication, are permitted provided that the following conditions are met:
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
 dnl
-dnl 1. Redistributions of source code  must retain the above copyright notice
-dnl    notice, this list of conditions and the following disclaimer.
-dnl
-dnl 2. Redistributions  in binary  form  must  reproduce the  above copyright
-dnl    notice,  this list of conditions  and the following  disclaimer in the
-dnl    documentation and/or other materials provided with the distribution.
-dnl
-dnl 3. The end-user documentation  included with the redistribution,  if any,
-dnl    must include the following acknowlegement:
-dnl
-dnl       "This product includes  software developed  by the Apache  Software
-dnl        Foundation <http://www.apache.org/>."
-dnl
-dnl    Alternately, this acknowlegement may appear in the software itself, if
-dnl    and wherever such third-party acknowlegements normally appear.
-dnl
-dnl 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software
-dnl    Foundation"  must not be used  to endorse or promote  products derived
-dnl    from this  software without  prior  written  permission.  For  written
-dnl    permission, please contact <apache at apache.org>.
-dnl
-dnl 5. Products derived from this software may not be called "Apache" nor may
-dnl    "Apache" appear in their names without prior written permission of the
-dnl    Apache Software Foundation.
-dnl
-dnl THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES
-dnl INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY
-dnl AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL
-dnl THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY
-dnl DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL
-dnl DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS
-dnl OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION)
-dnl HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT,
-dnl STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-dnl ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE
-dnl POSSIBILITY OF SUCH DAMAGE.
-dnl
-dnl =========================================================================
-dnl
-dnl This software  consists of voluntary  contributions made  by many indivi-
-dnl duals on behalf of the  Apache Software Foundation.  For more information
-dnl on the Apache Software Foundation, please see <http://www.apache.org/>.
-dnl
-dnl =========================================================================
 
 dnl -------------------------------------------------------------------------
 dnl Author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-dnl Version $Id: apjava.m4,v 1.2 2003/09/25 11:13:02 jfclere Exp $
+dnl Version $Id: apjava.m4 140756 2004-02-27 08:40:46Z jfclere $
 dnl -------------------------------------------------------------------------
 
 AC_DEFUN([AP_PROG_JAVAC_WORKS],[
diff --git a/src/native/unix/support/apsupport.m4 b/src/native/unix/support/apsupport.m4
index 89a5a1a..1cae65f 100644
--- a/src/native/unix/support/apsupport.m4
+++ b/src/native/unix/support/apsupport.m4
@@ -1,88 +1,26 @@
-dnl =========================================================================
 dnl
-dnl                 The Apache Software License,  Version 1.1
+dnl Copyright 1999-2004 The Apache Software Foundation
 dnl
-dnl          Copyright (c) 1999-2001 The Apache Software Foundation.
-dnl                           All rights reserved.
+dnl Licensed under the Apache License, Version 2.0 (the "License");
+dnl you may not use this file except in compliance with the License.
+dnl You may obtain a copy of the License at
 dnl
-dnl =========================================================================
+dnl     http://www.apache.org/licenses/LICENSE-2.0
 dnl
-dnl Redistribution and use in source and binary forms,  with or without modi-
-dnl fication, are permitted provided that the following conditions are met:
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
 dnl
-dnl 1. Redistributions of source code  must retain the above copyright notice
-dnl    notice, this list of conditions and the following disclaimer.
-dnl
-dnl 2. Redistributions  in binary  form  must  reproduce the  above copyright
-dnl    notice,  this list of conditions  and the following  disclaimer in the
-dnl    documentation and/or other materials provided with the distribution.
-dnl
-dnl 3. The end-user documentation  included with the redistribution,  if any,
-dnl    must include the following acknowlegement:
-dnl
-dnl       "This product includes  software developed  by the Apache  Software
-dnl        Foundation <http://www.apache.org/>."
-dnl
-dnl    Alternately, this acknowlegement may appear in the software itself, if
-dnl    and wherever such third-party acknowlegements normally appear.
-dnl
-dnl 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software
-dnl    Foundation"  must not be used  to endorse or promote  products derived
-dnl    from this  software without  prior  written  permission.  For  written
-dnl    permission, please contact <apache at apache.org>.
-dnl
-dnl 5. Products derived from this software may not be called "Apache" nor may
-dnl    "Apache" appear in their names without prior written permission of the
-dnl    Apache Software Foundation.
-dnl
-dnl THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES
-dnl INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY
-dnl AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL
-dnl THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY
-dnl DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL
-dnl DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS
-dnl OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION)
-dnl HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT,
-dnl STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-dnl ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE
-dnl POSSIBILITY OF SUCH DAMAGE.
-dnl
-dnl =========================================================================
-dnl
-dnl This software  consists of voluntary  contributions made  by many indivi-
-dnl duals on behalf of the  Apache Software Foundation.  For more information
-dnl on the Apache Software Foundation, please see <http://www.apache.org/>.
-dnl
-dnl =========================================================================
 
 dnl -------------------------------------------------------------------------
 dnl Author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-dnl Version $Id: apsupport.m4,v 1.3 2003/09/25 13:38:27 jfclere Exp $
+dnl Version $Id: apsupport.m4 165114 2005-04-28 08:03:15Z jfclere $
 dnl -------------------------------------------------------------------------
 
 AC_DEFUN(AP_SUPPORTED_HOST,[
   AC_MSG_CHECKING([C flags dependant on host system type])
-  case $host_cpu in
-  powerpc)
-    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
-  sparc)
-    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
-  i?86)
-    CFLAGS="$CFLAGS -DCPU=\\\"i386\\\"" ;;
-  bs2000)
-    CFLAGS="$CFLAGS -DCPU=\\\"osd\\\" -DCHARSET_EBCDIC -DOSD_POSIX"
-    supported_os="osd"
-    LDFLAGS="-Kno_link_stdlibs -B llm4 -l BLSLIB $LDFLAGS"
-    LDCMD="cc"
-    ;;
-  mips)
-    CFLAGS="$CFLAGS -DCPU=\\\"mips\\\""
-    supported_os="mips"
-    ;;
-  *)
-    AC_MSG_RESULT([failed])
-    AC_MSG_ERROR([Unsupported CPU architecture "$host_cpu"]);;
-  esac
 
   case $host_os in
   darwin*)
@@ -97,7 +35,7 @@ AC_DEFUN(AP_SUPPORTED_HOST,[
   linux*)
     CFLAGS="$CFLAGS -DOS_LINUX -DDSO_DLFCN"
     supported_os="linux"
-    LDFLAGS="$LDFLAGS -ldl"
+    LDFLAGS="$LDFLAGS -ldl -lpthread"
     ;;
   cygwin)
     CFLAGS="$CFLAGS -DOS_CYGWIN -DDSO_DLFCN -DNO_SETSID"
@@ -116,11 +54,44 @@ AC_DEFUN(AP_SUPPORTED_HOST,[
     LDFLAGS="-pthread $LDFLAGS"
     supported_os="freebsd"
     ;;
+  osf5*)
+    CFLAGS="$CFLAGS -pthread -DOS_TRU64 -DDSO_DLFCN -D_XOPEN_SOURCE_EXTENDED"
+    LDFLAGS="$LDFLAGS -pthread"
+    ;;
   *)
     AC_MSG_RESULT([failed])
     AC_MSG_ERROR([Unsupported operating system "$host_os"])
     ;;
   esac
+  case $host_cpu in
+  powerpc)
+    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
+  sparc*)
+    CFLAGS="$CFLAGS -DCPU=\\\"$host_cpu\\\"" ;;
+  i?86)
+    CFLAGS="$CFLAGS -DCPU=\\\"i386\\\"" ;;
+  x86_64)
+    CFLAGS="$CFLAGS -DCPU=\\\"amd64\\\"" ;;
+  bs2000)
+    CFLAGS="$CFLAGS -DCPU=\\\"osd\\\" -DCHARSET_EBCDIC -DOSD_POSIX"
+    supported_os="osd"
+    LDFLAGS="-Kno_link_stdlibs -B llm4 -l BLSLIB"
+    LDCMD="/opt/C/bin/cc"
+    ;;
+  mips)
+    CFLAGS="$CFLAGS -DCPU=\\\"mips\\\""
+    supported_os="mips"
+    ;;
+  alpha*)
+    CFLAGS="$CFLAGS -DCPU=\\\"alpha\\\""
+    supported_os="alpha"
+    ;;
+  *)
+    AC_MSG_RESULT([failed])
+    AC_MSG_ERROR([Unsupported CPU architecture "$host_cpu"]);;
+  esac
+
   AC_MSG_RESULT([ok])
   AC_SUBST(CFLAGS)
+  AC_SUBST(LDFLAGS)
 ])
diff --git a/src/native/unix/support/buildconf.sh b/src/native/unix/support/buildconf.sh
index b79edc0..a01a1b5 100644
--- a/src/native/unix/support/buildconf.sh
+++ b/src/native/unix/support/buildconf.sh
@@ -1,63 +1,22 @@
 #!/bin/sh
-# ========================================================================= #
-#                                                                           #
-#                 The Apache Software License,  Version 1.1                 #
-#                                                                           #
-#          Copyright (c) 1999-2001 The Apache Software Foundation.          #
-#                           All rights reserved.                            #
-#                                                                           #
-# ========================================================================= #
-#                                                                           #
-# Redistribution and use in source and binary forms,  with or without modi- #
-# fication, are permitted provided that the following conditions are met:   #
-#                                                                           #
-# 1. Redistributions of source code  must retain the above copyright notice #
-#    notice, this list of conditions and the following disclaimer.          #
-#                                                                           #
-# 2. Redistributions  in binary  form  must  reproduce the  above copyright #
-#    notice,  this list of conditions  and the following  disclaimer in the #
-#    documentation and/or other materials provided with the distribution.   #
-#                                                                           #
-# 3. The end-user documentation  included with the redistribution,  if any, #
-#    must include the following acknowlegement:                             #
-#                                                                           #
-#       "This product includes  software developed  by the Apache  Software #
-#        Foundation <http://www.apache.org/>."                              #
-#                                                                           #
-#    Alternately, this acknowlegement may appear in the software itself, if #
-#    and wherever such third-party acknowlegements normally appear.         #
-#                                                                           #
-# 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software #
-#    Foundation"  must not be used  to endorse or promote  products derived #
-#    from this  software without  prior  written  permission.  For  written #
-#    permission, please contact <apache at apache.org>.                        #
-#                                                                           #
-# 5. Products derived from this software may not be called "Apache" nor may #
-#    "Apache" appear in their names without prior written permission of the #
-#    Apache Software Foundation.                                            #
-#                                                                           #
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES #
-# INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY #
-# AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL #
-# THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY #
-# DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL #
-# DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS #
-# OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) #
-# HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, #
-# STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN #
-# ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE #
-# POSSIBILITY OF SUCH DAMAGE.                                               #
-#                                                                           #
-# ========================================================================= #
-#                                                                           #
-# This software  consists of voluntary  contributions made  by many indivi- #
-# duals on behalf of the  Apache Software Foundation.  For more information #
-# on the Apache Software Foundation, please see <http://www.apache.org/>.   #
-#                                                                           #
-# ========================================================================= #
+# 
+#   Copyright 1999-2004 The Apache Software Foundation
+# 
+#   Licensed 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.
+#
 
 # @author  Pier Fumagalli <mailto:pier.fumagalli at eng.sun.com>
-# @version $Id: buildconf.sh,v 1.2 2003/09/12 09:05:57 jfclere Exp $
+# @version $Id: buildconf.sh 155409 2005-02-26 12:57:06Z dirkv $
 
 # The cache of automake always brings problems when changing *.m4 files.
 rm -rf autom4te.cache
diff --git a/src/native/unix/support/install.sh b/src/native/unix/support/install.sh
index 398a88e..6c4d358 100644
--- a/src/native/unix/support/install.sh
+++ b/src/native/unix/support/install.sh
@@ -1,37 +1,36 @@
 #!/bin/sh
 #
-# install - install a program, script, or datafile
-# This comes from X11R5 (mit/util/scripts/install.sh).
+#   Copyright 1999-2004 The Apache Software Foundation
 #
-# Copyright 1991 by the Massachusetts Institute of Technology
+#   Licensed 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
 #
-# Permission to use, copy, modify, distribute, and sell this software and its
-# documentation for any purpose is hereby granted without fee, provided that
-# the above copyright notice appear in all copies and that both that
-# copyright notice and this permission notice appear in supporting
-# documentation, and that the name of M.I.T. not be used in advertising or
-# publicity pertaining to distribution of the software without specific,
-# written prior permission.  M.I.T. makes no representations about the
-# suitability of this software for any purpose.  It is provided "as is"
-# without express or implied warranty.
+#       http://www.apache.org/licenses/LICENSE-2.0
 #
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
+#   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.
 #
-# This script is compatible with the BSD install script, but was written
-# from scratch.  It can only install one file at a time, a restriction
-# shared with many OS's install programs.
-
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
-
+##
+##  install.sh -- install a program, script or datafile
+##
+##  Based on `install-sh' from the X Consortium's X11R5 distribution
+##  as of 89/12/18 which is freely available.
+##  Cleaned up for Apache's Autoconf-style Interface (APACI)
+##  by Ralf S. Engelschall <rse at apache.org>
+##
+#
+# This script falls under the Apache License.
+# See http://www.apache.org/docs/LICENSE
 
-# put in absolute paths if you don't have them in your path; or use env. vars.
 
+#
+#   put in absolute paths if you don't have them in your path; 
+#   or use env. vars.
+#
 mvprog="${MVPROG-mv}"
 cpprog="${CPPROG-cp}"
 chmodprog="${CHMODPROG-chmod}"
@@ -39,213 +38,90 @@ chownprog="${CHOWNPROG-chown}"
 chgrpprog="${CHGRPPROG-chgrp}"
 stripprog="${STRIPPROG-strip}"
 rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
 
-transformbasename=""
-transform_arg=""
+#
+#   parse argument line
+#
 instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
+chmodcmd=""
 chowncmd=""
 chgrpcmd=""
 stripcmd=""
 rmcmd="$rmprog -f"
 mvcmd="$mvprog"
+ext=""
 src=""
 dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
+while [ "x$1" != "x" ]; do
     case $1 in
-	-c) instcmd="$cpprog"
-	    shift
-	    continue;;
-
-	-d) dir_arg=true
-	    shift
-	    continue;;
-
-	-m) chmodcmd="$chmodprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-o) chowncmd="$chownprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-g) chgrpcmd="$chgrpprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-s) stripcmd="$stripprog"
-	    shift
-	    continue;;
-
-	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
-	    shift
-	    continue;;
-
-	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-	    shift
-	    continue;;
-
-	*)  if [ x"$src" = x ]
-	    then
-		src=$1
-	    else
-		# this colon is to work around a 386BSD /bin/sh bug
-		:
-		dst=$1
-	    fi
-	    shift
-	    continue;;
+        -c) instcmd="$cpprog"
+            shift; continue
+            ;;
+        -m) chmodcmd="$chmodprog $2"
+            shift; shift; continue
+            ;;
+        -o) chowncmd="$chownprog $2"
+            shift; shift; continue
+            ;;
+        -g) chgrpcmd="$chgrpprog $2"
+            shift; shift; continue
+            ;;
+        -s) stripcmd="$stripprog"
+            shift; continue
+            ;;
+        -S) stripcmd="$stripprog $2"
+            shift; shift; continue
+            ;;
+        -e) ext="$2"
+            shift; shift; continue
+            ;;
+        *)  if [ "x$src" = "x" ]; then
+                src=$1
+            else
+                dst=$1
+            fi
+            shift; continue
+            ;;
     esac
 done
-
-if [ x"$src" = x ]
-then
-	echo "install:	no input file specified"
-	exit 1
-else
-	:
+if [ "x$src" = "x" ]; then
+     echo "install.sh: no input file specified"
+     exit 1
 fi
-
-if [ x"$dir_arg" != x ]; then
-	dst=$src
-	src=""
-	
-	if [ -d $dst ]; then
-		instcmd=:
-		chmodcmd=""
-	else
-		instcmd=$mkdirprog
-	fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad 
-# if $src (and thus $dsttmp) contains '*'.
-
-	if [ -f $src -o -d $src ]
-	then
-		:
-	else
-		echo "install:  $src does not exist"
-		exit 1
-	fi
-	
-	if [ x"$dst" = x ]
-	then
-		echo "install:	no destination specified"
-		exit 1
-	else
-		:
-	fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
-	if [ -d $dst ]
-	then
-		dst="$dst"/`basename $src`
-	else
-		:
-	fi
+if [ "x$dst" = "x" ]; then
+     echo "install.sh: no destination specified"
+     exit 1
 fi
 
-## this sed command emulates the dirname command
-dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-#  this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='
-	'
-IFS="${IFS-${defaultIFS}}"
-
-oIFS="${IFS}"
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS="${oIFS}"
-
-pathcomp=''
-
-while [ $# -ne 0 ] ; do
-	pathcomp="${pathcomp}${1}"
-	shift
-
-	if [ ! -d "${pathcomp}" ] ;
-        then
-		$mkdirprog "${pathcomp}"
-	else
-		:
-	fi
-
-	pathcomp="${pathcomp}/"
-done
+#
+#  If destination is a directory, append the input filename; if
+#  your system does not like double slashes in filenames, you may
+#  need to add some logic
+#
+if [ -d $dst ]; then
+    dst="$dst/`basename $src`"
 fi
 
-if [ x"$dir_arg" != x ]
-then
-	$doit $instcmd $dst &&
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
+#  Add a possible extension (such as ".exe") to src and dst
+src="$src$ext"
+dst="$dst$ext"
 
-	if [ x"$transformarg" = x ] 
-	then
-		dstfile=`basename $dst`
-	else
-		dstfile=`basename $dst $transformbasename | 
-			sed $transformarg`$transformbasename
-	fi
+#  Make a temp file name in the proper directory.
+dstdir=`dirname $dst`
+dsttmp=$dstdir/#inst.$$#
 
-# don't allow the sed command to completely eliminate the filename
+#  Move or copy the file name to the temp name
+$instcmd $src $dsttmp
 
-	if [ x"$dstfile" = x ] 
-	then
-		dstfile=`basename $dst`
-	else
-		:
-	fi
-
-# Make a temp file name in the proper directory.
-
-	dsttmp=$dstdir/#inst.$$#
-
-# Move or copy the file name to the temp name
-
-	$doit $instcmd $src $dsttmp &&
-
-	trap "rm -f ${dsttmp}" 0 &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing.  If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi &&
-
-# Now rename the file to the real destination.
-
-	$doit $rmcmd -f $dstdir/$dstfile &&
-	$doit $mvcmd $dsttmp $dstdir/$dstfile 
-
-fi &&
+#  And set any options; do chmod last to preserve setuid bits
+if [ "x$chowncmd" != "x" ]; then $chowncmd $dsttmp; fi
+if [ "x$chgrpcmd" != "x" ]; then $chgrpcmd $dsttmp; fi
+if [ "x$stripcmd" != "x" ]; then $stripcmd $dsttmp; fi
+if [ "x$chmodcmd" != "x" ]; then $chmodcmd $dsttmp; fi
 
+#  Now rename the file to the real destination.
+$rmcmd $dst
+$mvcmd $dsttmp $dst
 
 exit 0
+
diff --git a/src/samples/AloneDaemon.sh b/src/samples/AloneDaemon.sh
index fe1320b..b3f9c9b 100755
--- a/src/samples/AloneDaemon.sh
+++ b/src/samples/AloneDaemon.sh
@@ -1,4 +1,19 @@
 #!/bin/sh
+# 
+#   Copyright 1999-2004 The Apache Software Foundation
+# 
+#   Licensed 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.
+#
 #
 # Small shell script to show how to start the sample services.
 # That is for linux, if your are using cygwin look to ServiceDaemon.sh.
diff --git a/src/samples/AloneService.java b/src/samples/AloneService.java
index 179a332..1f54687 100644
--- a/src/samples/AloneService.java
+++ b/src/samples/AloneService.java
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: AloneService.java,v 1.1 2003/09/27 15:45:02 jfclere Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: AloneService.java 155409 2005-02-26 12:57:06Z dirkv $ */
 
 import java.io.*;
 import java.net.*;
diff --git a/src/samples/Native.c b/src/samples/Native.c
new file mode 100644
index 0000000..44a4802
--- /dev/null
+++ b/src/samples/Native.c
@@ -0,0 +1,42 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+/*
+ * Native routine to core JVM
+ */
+#include <jni.h>
+ 
+#ifndef _Included_Native
+#define _Included_Native
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     Native
+ * Method:    toto
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_SimpleDaemon_toto
+  (JNIEnv *env, jclass class) {
+	int i;
+	i = -1;
+	memcpy(&i, &i, i);
+}
+ 
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/samples/Native.sh b/src/samples/Native.sh
new file mode 100644
index 0000000..33899f1
--- /dev/null
+++ b/src/samples/Native.sh
@@ -0,0 +1,18 @@
+## Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+## applicable.
+##
+## Licensed 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.
+##
+# for linux ;-)
+gcc -c -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux Native.c
+gcc -shared -o Native.so Native.o
diff --git a/src/samples/README.txt b/src/samples/README.txt
index 008c6df..804a072 100644
--- a/src/samples/README.txt
+++ b/src/samples/README.txt
@@ -5,7 +5,7 @@ jar file in ../../dist
 SimpleDaemon:
 
 SimpleDaemon demonstrates the feature of the daemon ofered by
-jakarta-commons-sandbox/daemon.
+jakarta-commons/daemon.
 To run it adapt the SimpleDaemon.sh file and connect to it using:
 telnet localhost 1200
 Additional information in ../native/unix/INSTALL.txt
@@ -18,8 +18,10 @@ services support under win NT/2000/XP.
 (See in ../native/nt/README how to install jsvc as a service in win32).
 
 It uses jakarta Commons Collections:
-http://jakarta.apache.org/commons/collections.html
+http://jakarta.apache.org/commons/collections/
 To use it you need at least commons-collections-1.0
+Check in build.xml that the property commons-collections.jar correspond to thei
+location of your commons-collections.jar file.
 
 You have to create a file named startfile that uses a property format:
 name = string to start the program
diff --git a/src/samples/ServiceDaemon.java b/src/samples/ServiceDaemon.java
index 766420a..e1dd758 100644
--- a/src/samples/ServiceDaemon.java
+++ b/src/samples/ServiceDaemon.java
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: ServiceDaemon.java,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: ServiceDaemon.java 155409 2005-02-26 12:57:06Z dirkv $ */
 
 import java.io.*;
 import java.net.*;
diff --git a/src/samples/ServiceDaemon.sh b/src/samples/ServiceDaemon.sh
index ae1d960..86f166b 100755
--- a/src/samples/ServiceDaemon.sh
+++ b/src/samples/ServiceDaemon.sh
@@ -1,4 +1,19 @@
 #!/bin/sh
+# 
+#   Copyright 1999-2004 The Apache Software Foundation
+# 
+#   Licensed 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.
+#
 #
 # Small shell script to show how to start the sample services.
 #
diff --git a/src/samples/ServiceDaemonReadThread.java b/src/samples/ServiceDaemonReadThread.java
index 7390ec1..79299ad 100644
--- a/src/samples/ServiceDaemonReadThread.java
+++ b/src/samples/ServiceDaemonReadThread.java
@@ -1,62 +1,20 @@
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
 
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: ServiceDaemonReadThread.java,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/* @version $Id: ServiceDaemonReadThread.java 155409 2005-02-26 12:57:06Z dirkv $ */
 import java.io.InputStream;
 import java.io.IOException;
 import java.lang.Thread;
diff --git a/src/samples/SimpleDaemon.java b/src/samples/SimpleDaemon.java
index b25808b..4d38637 100644
--- a/src/samples/SimpleDaemon.java
+++ b/src/samples/SimpleDaemon.java
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: SimpleDaemon.java,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: SimpleDaemon.java 165001 2005-04-27 16:01:42Z jfclere $ */
 
 import java.io.*;
 import java.net.*;
@@ -76,6 +35,8 @@ public class SimpleDaemon implements Daemon, Runnable {
     private String directory=null;
     private Vector handlers=null;
 
+    public static native void toto();
+
     public SimpleDaemon() {
         super();
         System.err.println("SimpleDaemon: instance "+this.hashCode()+
@@ -238,7 +199,7 @@ public class SimpleDaemon implements Daemon, Runnable {
             return(this.directory);
         }
 
-        public void log(String name)
+        public void createFile(String name)
         throws IOException {
             OutputStream file=new FileOutputStream(name,true);
             PrintStream out=new PrintStream(file);
@@ -249,8 +210,22 @@ public class SimpleDaemon implements Daemon, Runnable {
             file.close();
         }
 
+        public void createDir(String name)
+        throws IOException {
+            File file = new File(name);
+            boolean ok = file.mkdirs();
+            if(! ok)
+                throw new IOException("mkdirs for "+name+" failed");
+            createFile(name);
+        }
+
         public void handle(InputStream in, OutputStream os) {
-            PrintStream out=new PrintStream(os);
+            PrintStream out=null;
+            try {
+                out=new PrintStream(os, true, "US-ASCII");
+            } catch (UnsupportedEncodingException ex) {
+                out=new PrintStream(os);
+            }
 
             while(true) {
                 try {
@@ -263,6 +238,8 @@ public class SimpleDaemon implements Daemon, Runnable {
                         out.println("    2) Reload");
                         out.println("    3) Create a file");
                         out.println("    4) Disconnect");
+                        out.println("    5) Cause a core of the JVM");
+                        out.println("    6) Create a directory");
                         out.print("Your choiche: ");
                     }
 
@@ -298,14 +275,14 @@ public class SimpleDaemon implements Daemon, Runnable {
                             }
                             break;
 
-                        /* Disconnect */
+                        /* Create a file */
                         case '3':
                             String name=this.getDirectoryName()+
                                         "/SimpleDaemon."+
                                         this.getConnectionNumber()+
                                         ".tmp";
                             try {
-                                this.log(name);
+                                this.createFile(name);
                                 out.println("File '"+name+"' created");
                             } catch (IOException e) {
                                 e.printStackTrace(out);
@@ -317,6 +294,28 @@ public class SimpleDaemon implements Daemon, Runnable {
                             out.println("Disconnecting...");
                             return;
 
+                        /* Crash JVM in a native call: It need an so file ;-) */
+                        case '5':
+                            System.load(System.getProperty("native.library", "./Native.so"));
+                            toto();
+                            break;
+
+                        /* Create a directory (PR 30177 with 1.4.x and 1.5.0 */
+                        case '6':
+                            String name1=this.getDirectoryName()+
+                                        "/a/b/c/d/e"+
+                                        "/SimpleDaemon."+
+                                        this.getConnectionNumber()+
+                                        ".tmp";
+                            try {
+                                this.createDir(name1);
+                                out.println("File '"+name1+"' created");
+                            } catch (IOException e) {
+                                e.printStackTrace(out);
+                            }
+                            break;
+
+
                         /* Discard any carriage return / newline characters */
                         case '\r':
                         case '\n':
diff --git a/src/samples/SimpleDaemon.sh b/src/samples/SimpleDaemon.sh
index 941792d..cab1628 100755
--- a/src/samples/SimpleDaemon.sh
+++ b/src/samples/SimpleDaemon.sh
@@ -1,5 +1,20 @@
 #!/bin/sh
 #
+#   Copyright 1999-2005 The Apache Software Foundation
+#
+#   Licensed 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.
+#
+#
 # Small shell script to show how to start the sample services.
 #
 # Adapt the following lines to your configuration
@@ -15,9 +30,16 @@ $DAEMON_HOME/src/native/unix/jsvc \
     -home $JAVA_HOME \
     -cp $CLASSPATH \
     -pidfile ./pidfile \
+    -wait 90 \
+    -debug \
+    -outfile toto.txt \
+    -errfile '&1' \
+    -Dnative.library=${DAEMON_HOME}/src/samples/Native.so \
     SimpleDaemon \
 #
 # To get a verbose JVM
 #-verbose \
 # To get a debug of jsvc.
 #-debug \
+
+echo "result: $?"
diff --git a/src/samples/build.xml b/src/samples/build.xml
index 1d5a90f..a8a0500 100644
--- a/src/samples/build.xml
+++ b/src/samples/build.xml
@@ -6,7 +6,7 @@
   <property name="dist.home"   value="../../dist"/>
   <property name="build.home"  value="./build"/>
   <property name="source.home" value="."/>
-  <property name="commons-collections.jar" value="${user.home}/commons-collections-2.1/commons-collections.jar"/>
+  <property name="commons-collections.jar" value="${user.home}/commons-collections-3.1/commons-collections-3.1.jar"/>
 
   <target name="jars" depends="SimpleDaemon,ServiceDaemon,AloneService"/>
 
@@ -14,7 +14,7 @@
    description="Create SimpleDaemon.jar">
     <mkdir      dir="${dist.home}"/>
     <mkdir      dir="${build.home}/classes/META-INF"/>
-    <copy      file="../../../LICENSE"
+    <copy      file="../../LICENSE"
                tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
     <jar    jarfile="${dist.home}/SimpleDaemon.jar">
       <fileset dir="${build.home}/classes">
@@ -27,7 +27,7 @@
    description="Create ServiceDaemon.jar">
     <mkdir      dir="${dist.home}"/>
     <mkdir      dir="${build.home}/classes/META-INF"/>
-    <copy      file="../../../LICENSE"
+    <copy      file="../../LICENSE"
                tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
     <jar    jarfile="${dist.home}/service.jar">
       <fileset dir="${build.home}/classes">
@@ -40,7 +40,7 @@
    description="Create aloneservice.jar">
     <mkdir      dir="${dist.home}"/>
     <mkdir      dir="${build.home}/classes/META-INF"/>
-    <copy      file="../../../LICENSE"
+    <copy      file="../../LICENSE"
                tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
     <jar    jarfile="${dist.home}/aloneservice.jar">
       <fileset dir="${build.home}/classes">
diff --git a/src/test/org/apache/commons/daemon/SimpleDaemon.java b/src/test/org/apache/commons/daemon/SimpleDaemon.java
index 2065e87..bccbdf8 100644
--- a/src/test/org/apache/commons/daemon/SimpleDaemon.java
+++ b/src/test/org/apache/commons/daemon/SimpleDaemon.java
@@ -1,61 +1,20 @@
-/* ========================================================================= *
- *                                                                           *
- *                 The Apache Software License,  Version 1.1                 *
- *                                                                           *
- *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
- *                           All rights reserved.                            *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * Redistribution and use in source and binary forms,  with or without modi- *
- * fication, are permitted provided that the following conditions are met:   *
- *                                                                           *
- * 1. Redistributions of source code  must retain the above copyright notice *
- *    notice, this list of conditions and the following disclaimer.          *
- *                                                                           *
- * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
- *    notice,  this list of conditions  and the following  disclaimer in the *
- *    documentation and/or other materials provided with the distribution.   *
- *                                                                           *
- * 3. The end-user documentation  included with the redistribution,  if any, *
- *    must include the following acknowlegement:                             *
- *                                                                           *
- *       "This product includes  software developed  by the Apache  Software *
- *        Foundation <http://www.apache.org/>."                              *
- *                                                                           *
- *    Alternately, this acknowlegement may appear in the software itself, if *
- *    and wherever such third-party acknowlegements normally appear.         *
- *                                                                           *
- * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
- *    Foundation"  must not be used  to endorse or promote  products derived *
- *    from this  software without  prior  written  permission.  For  written *
- *    permission, please contact <apache at apache.org>.                        *
- *                                                                           *
- * 5. Products derived from this software may not be called "Apache" nor may *
- *    "Apache" appear in their names without prior written permission of the *
- *    Apache Software Foundation.                                            *
- *                                                                           *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
- * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
- * AND FITNESS FOR  A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL *
- * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
- * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
- * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
- * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
- * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
- * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
- * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
- * POSSIBILITY OF SUCH DAMAGE.                                               *
- *                                                                           *
- * ========================================================================= *
- *                                                                           *
- * This software  consists of voluntary  contributions made  by many indivi- *
- * duals on behalf of the  Apache Software Foundation.  For more information *
- * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
- *                                                                           *
- * ========================================================================= */
-
-/* @version $Id: SimpleDaemon.java,v 1.1.1.1 2003/09/04 23:28:20 yoavs Exp $ */
+/*
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ */
+
+/* @version $Id: SimpleDaemon.java 155409 2005-02-26 12:57:06Z dirkv $ */
 
 package org.apache.commons.daemon;
 
diff --git a/xdocs/faq.xml b/xdocs/faq.xml
index 40162d6..0b8b20c 100644
--- a/xdocs/faq.xml
+++ b/xdocs/faq.xml
@@ -45,6 +45,28 @@ the current directory (if you are not member of group "wheel")
 the group "wheel" cannot be set on the moved files.
 </p>
 </section>
+<section name="Runtime problems">
+<p>
+On linux 2.6.x jsvc does not start and write the following error:
+<source>
+jsvc.exec error: syscall failed in set_caps
+jsvc.exec error: Service exit with a return value of 4
+</source>
+CONFIG_SECURITY_CAPABILITIES in missing in your kernel try the following in the kernel sources:
+<ul>
+<li>
+Configure the kernel with "Default Linux Capabilities" and reboot
+  (by make gconfig or make xconfig under "security options" and "Enable different security models")
+</li>
+<li>
+Insert the module "capability":
+<source>
+modprobe capability
+</source>
+</li>
+</ul>
+</p>
+</section>
 
 </body>
 </document>
diff --git a/xdocs/jsvc.xml b/xdocs/jsvc.xml
index db7d41c..0d8473c 100644
--- a/xdocs/jsvc.xml
+++ b/xdocs/jsvc.xml
@@ -90,7 +90,7 @@ Where options include:
 
     -jvm <JVM name>
         use a specific Java Virtual Machine. Available JVMs:
-            '(null)'
+            'client' 'server'
     -cp / -classpath <directories and zip/jar files>
         set search path for service classes and resouces
     -home <directory>
@@ -107,7 +107,7 @@ Where options include:
         verbosely print debugging information
     -check
         only check service (implies -nodetach)
-    -user
+    -user <user>
         user used to run the daemon (defaults to current user)
     -verbose[:class|gc|jni]
         enable verbose output
@@ -124,6 +124,11 @@ Where options include:
         set a Java system property
     -X<option>
         set Virtual Machine specific option
+    -wait <waittime>
+        wait waittime seconds for the service to start
+        waittime should multiple of 10 (min=10)
+    -stop
+        stop the service using the file given in the -pidfile option
 
 </source>
 </p>
@@ -144,7 +149,7 @@ You have to do the following.
   <li>Put it in the jarfile (my.jar).</li>
   <li>Call jsvc like:
   <source>
-    jsvc -cp commons-daemon.jar:my.jar MyClass
+    ./jsvc -cp commons-daemon.jar:my.jar MyClass
   </source>
   </li>
 </ul>
@@ -162,7 +167,7 @@ You have to write a Class (MyClass) that implements the following methods:
 </ul>
 Store it in a jarfile and use as above:
 <source>
-  jsvc -cp commons-daemon.jar:my.jar MyClass
+  ./jsvc -cp commons-daemon.jar:my.jar MyClass
 </source>
 </p>
 </subsection>
diff --git a/xdocs/navigation.xml b/xdocs/navigation.xml
index 58f198b..aa8ae0f 100644
--- a/xdocs/navigation.xml
+++ b/xdocs/navigation.xml
@@ -1,9 +1,5 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
-
-<!DOCTYPE project [
-<!ENTITY commons-nav SYSTEM "../../commons-build/incl_nav.xml">
-]>
-
+<!DOCTYPE org.apache.commons.menus SYSTEM '../../commons-build/menus/menus.dtd'>
 <project name="Daemon">
 
   <title>Daemon</title>
@@ -31,7 +27,7 @@
           
     </menu>
     
-    &commons-nav;
+    &common-menus;
 
   </body>
 </project>
diff --git a/xdocs/procrun.xml b/xdocs/procrun.xml
index ec8511e..7d3fdd2 100644
--- a/xdocs/procrun.xml
+++ b/xdocs/procrun.xml
@@ -1,189 +1,337 @@
 <?xml version="1.0"?>
 
 <document>
-
  <properties>
   <title>Daemon : Procrun</title>
-  <author email="jfrederic.clere at fujitsu-siemens.con">Jean-Frederic Clere</author>
-  <author email="william.barker at wilshire.com">Bill Barker</author>
-  <author email="mladen.turk at gisdata.hr">Mladen Turk</author>
+  <author email="mturk at apache.org">Mladen Turk</author>
  </properties>
 
 <body>
 <section name="Introduction">
 <p>
-      Actualy only the win32 platforms are supported.
+    Procrun is a set of libraries and applications for making Java
+    applications to run on WIN32 much easier.    
+</p> 
+<subsection name="Procrun service application">
+<p>
+    <b>Prunsrv</b> is a service application for running applications as services.
+    It can convert any application to run as a service.
+</p>
+</subsection>
+<subsection name="Procrun monitor application">
+<p>
+    <b>Prunmgr</b> is a GUI application for monitoring and configuring procrun
+    services.
+</p>    
+    <p>The available command line options are:</p>
+<p> 
+    <table>
+    <tr><th>//ES//</th>
+        <td>Edit service configuration</td>
+        <td>This is the default operation. It is called if the no option is
+            provided but the executable is renamed to <b>servicenameW.exe</b></td>
+    </tr>
+    <tr><th>//MS//</th>
+        <td>Monitor service</td>
+        <td>Put the icon in the system try</td>
+    </tr>
+    </table>
 </p>
+</subsection>
 </section>
-<section name="Building">
+<section name="Command line arguments">
 <p>
-      It is possible to use cygwin to build procrun.
-      <a href="http://www.cygwin.com/"> cygwin</a> for more informations.
+    Each command line directive is in the form of <b>//XX//ServiceName</b>
 </p>
+    <p>The available command line options are:</p>
+<p> 
+    <table>
+    <tr><th>//TS//</th>
+        <td>Run the service as console application</td>
+        <td>This is the default operation. It is called if the no option is
+            provided but the executable is renamed to <b>servicename.exe</b></td>
+    </tr>
+    <tr><th>//RS//</th>
+        <td>Run the service</td>
+        <td>Called only from ServiceManager</td>
+    </tr>
+    <tr><th>//SS//</th>
+        <td>Stop the service</td>
+        <td></td>
+    </tr>
+    <tr><th>//US//</th>
+        <td>Update service parameters</td>
+        <td></td>
+    </tr>
+    <tr><th>//IS//</th>
+        <td>Install service</td>
+        <td></td>
+    </tr>
+    <tr><th>//DS//</th>
+        <td>Delete service</td>
+        <td>Stops the service if running</td>
+    </tr>        
+    </table>
+</p> 
+</section>
+<section name="Command line parameters">
 <p>
-      If you have access to MSVC (version 6.0 or higher), then simply 
-      open the corresponding build project file.
-      <ul>
-       <li>For MSVC 6.x, use <code>procrun.dsw</code></li>
-       <li>For MSVC.NET, use <code>procrun.sln</code></li>
-      </ul>
-      At this point, you need to select from the build menu which version you
-      want to build (select either the release or debug build, depending on 
-      your preferences).  The selections are:
-      <ul>
-       <li><code>procrun</code> if you want the GUI interface</li>
-       <li><code>procrun CONSOLE</code> if you don't want the GUI interface</li>
-       <li><code>procrun DLL</code> if you want the Control Panel application</li>
-      </ul>
+    Each command parameter is prefixed with <b>--</b>.
+    If the command line is prefixed with <b>++</b> then it's value will
+    be appended to the existing option.
+    If the environment variable with the same name as command line parameter but
+    prefixed with <code>PR_</code> exists it will take precedence.
+    For example:
+<source>set PR_CLASSPATH=xx.jar</source>
+</p>    
+<p>is equivalent to providing
+<source>--Classpath=xx.jar</source>
 </p>
+<p> as command line parameter.</p>
+<p> 
+    <table>
+    <tr>
+    <th>ParameterName</th>
+	<th>Default</th>
+	<th>Description</th>
+	</tr> 
+    <tr>
+    <td>--Description</td>
+    <td></td>
+    <td>Service name description (maximum 1024 characters)</td>
+    </tr>
+    <tr>
+    <td>--DisplayName</td>
+    <td>ServiceName</td>
+    <td>Service display name</td>
+    </tr>
+    <tr>
+    <td>--Install</td>
+    <td>procrun.exe //RS//ServiceName</td>
+    <td>Install image</td>
+    </tr>
+    <tr>
+    <td>--Startup</td>
+    <td>manual</td>
+    <td>Service startup mode can be either <b>auto</b> or <b>manual</b></td>
+    </tr>
+    <tr>
+    <td>--DependsOn</td>
+    <td></td>
+    <td>List of services that this service depend on. Dependent services
+        are separated using either <b>#</b> or <b>;</b> characters</td>
+    </tr>
+    <tr>
+    <td>--Environment</td>
+    <td></td>
+    <td>List of environment variables that will be provided to the service
+        in the form <b>key=value</b>. They are separated using either
+        <b>#</b> or <b>;</b> characters</td>
+    </tr>
+    <tr>
+    <td>--User</td>
+    <td></td>
+    <td>User account used for running executable. It is used only for
+    	StartMode <b>java</b> or <b>exe</b> and enables running applications
+    	as service under account without LogonAsService privilege.</td>
+    </tr>
+    <tr>
+    <td>--Password</td>
+    <td></td>
+    <td>Password for user account set by --User parameter</td>
+    </tr>
+    <tr>
+    <td>--JavaHome</td>
+    <td>JAVA_HOME</td>
+    <td>Set a different JAVA_HOME then defined by JAVA_HOME environment
+        variable</td>
+    </tr>
+    <tr>
+    <td>--Jvm</td>
+    <td>auto</td>
+    <td>Use either <b>auto</b> or specify the full path to the <b>jvm.dll</b>.
+        You can use the environment variable expansion here.</td>
+    </tr>
+    <tr>
+    <td>--JvmOptions</td>
+    <td>-Xrs</td>
+    <td>List of options in the form of <b>-D</b> or <b>-X</b> that will be
+        passed to the JVM. The options are separated using either
+        <b>#</b> or <b>;</b> characters.</td>
+    </tr>
+    <tr>
+    <td>--Classpath</td>
+    <td></td>
+    <td>Set the Java classpath</td>
+    </tr>
+    <tr>
+    <td>--JvmMs</td>
+    <td></td>
+    <td>Initial memory pool size in MB</td>
+    </tr>
+    <tr>
+    <td>--JvmMx</td>
+    <td></td>
+    <td>Maximum memory pool size in MB</td>
+    </tr>
+    <tr>
+    <td>--JvmSs</td>
+    <td></td>
+    <td>Thread stack size in KB</td>
+    </tr>
+    <tr>
+    <tr>
+    <td>--StartImage</td>
+    <td></td>
+    <td>Executable that will be run.</td>
+    </tr>
+    <tr>
+    <td>--StartPath</td>
+    <td></td>
+    <td>Working path for the start image executable.</td>
+    </tr>
+    <tr>
+    <td>--StartClass</td>
+    <td></td>
+    <td>Class that will be used for startup.</td>
+    </tr>
+    <tr>
+    <td>--StartParams</td>
+    <td></td>
+    <td>List of parameters that will be passed to either StartImage or
+        StartClass. Parameters are separated using either <b>#</b> or
+        <b>;</b> character.</td>
+    </tr>
+    <tr>
+    <td>--StartMethod</td>
+    <td>Main</td>
+    <td>Method name if differs then main</td>
+    </tr>
+    <tr>
+    <td>--StartMode</td>
+    <td>executable</td>
+    <td>Can one of <b>jvm</b> <b>java</b> or <b>exe</b></td>
+    </tr>
+    <td>--StopImage</td>
+    <td></td>
+    <td>Executable that will be run on Stop service signal.</td>
+    </tr>
+    <tr>
+    <td>--StopPath</td>
+    <td></td>
+    <td>Working path for the stop image executable.</td>
+    </tr>
+    <tr>
+    <td>--StopClass</td>
+    <td></td>
+    <td>Class that will be used on Stop service signal.</td>
+    </tr>
+    <tr>
+    <td>--StopParams</td>
+    <td></td>
+    <td>List of parameters that will be passed to either StopImage or
+        StopClass. Parameters are separated using either <b>#</b> or
+        <b>;</b> character.</td>
+    </tr>
+    <tr>
+    <td>--StopMethod</td>
+    <td>Main</td>
+    <td>Method name if differs then main</td>
+    </tr>
+    <tr>
+    <td>--StopMode</td>
+    <td>executable</td>
+    <td>Can one of <b>jvm</b> <b>java</b> or <b>exe</b></td>
+    </tr>
+    <tr>
+    <td>--StopTimeout</td>
+    <td>No Timeout</td>
+    <td>Defines the timeout in seconds that procrun waits for service to
+        exit gracefully.</td>
+    </tr>
+    <tr>
+    <td>--LogPath</td>
+    <td>working path</td>
+    <td>Defines the path for logging</td>
+    </tr>
+    <tr>
+    <td>--LogPrefix</td>
+    <td>jakarta_service</td>
+    <td>Defines the service log filename</td>
+    </tr>
+    <tr>
+    <td>--LogLevel</td>
+    <td>INFO</td>
+    <td>Defines the logging level and can be either <b>error</b>,
+        <b>info</b>, <b>warn</b> or <b>debug</b></td>
+    </tr>
+    <tr>
+    <td>--StdOutput</td>
+    <td></td>
+    <td>Redirected stdout filename</td>
+    </tr>
+    <tr>
+    <td>--StdError</td>
+    <td></td>
+    <td>Redirected stderr filename</td>
+    </tr>    
+    </table>
+</p> 
 </section>
-<section name="Using procrun">
-<subsection name="Installing the service">
+<section name="Installing services">
 <p>
-     The first thing that you must do is to install your service.  As a 
-     special case, if you haved installed Tomcat 5 via the installer, then it 
-     will do this for you, and you can skip this step.
+To install the service, you need to use the <b>//IS//</b> parameter.
 </p>
 <p>
-     To install the service, you need to use the <code>//IS//</code> parameter.
-     Use <code>tomcatw.exe</code> if you want to run the Graphical version, 
-     or <code>tomcat.exe</code> for the non-Graphical version.  For example:
-     <source>
-           tomcat //IS//Tomcat5 --DisplayName "Tomcat 5.0.12" \
-            --Description "Tomcat 5.0.12 JDK 1.4 http://jakarta.apache.org" \
-            --ImagePath "c:\devtools\tomcat\5.0\bin\bootstrap.jar" \
-            --StartupClass org.apache.catalina.startup.Bootstrap;main;start \
-            --ShutdownClass org.apache.catalina.startup.Bootstrap;main;stop \
-            --Java auto
-    </source>
-    <table>
-    <caption>The options available for installation are</caption>
-    <tr><th>--DisplayName</th>
-        <td>This is the name shown in the Windows Services manager.</td></tr>
-    <tr><th>--Description</th>
-        <td>This is the service description shown in the windows Services manager.</td></tr>
-    <tr><th>--ImagePath</th>
-        <td>Full path to the executable to be run as service,
-            or name of the Java Class Path. In cases when the
-            service runs JVM or Java binary this is the
-            parameter passed to -Djava.class.path option.</td></tr>
-    <tr><th>--Arguments</th>
-        <td>Arguments are enclosed inside double quotation
-            marks and passed to the service image.</td></tr>
-    <tr><th>--WorkingPath</th>
-        <td>Sets the working path to the desired value.</td></tr>
-    <tr><th>--Java</th>
-        <td><ul>
-             <li>auto:
-                    Auto will cause to load the default JVM read
-                    read from registry.</li>
-             <li>java[w]:
-                    The default java.exe or javaw.exe will be
-                    located and executed with
-                    -Djava.class.path=ImagePath</li>
-             <li>If neither java or auto are specified then this
-                parameter is treated as either the full path to the 
-                <code>jvm.dll</code>, or as the path to the Java 
-                installation.</li>
-            </ul></td></tr>
-    <tr><th>--JavaOptions</th>
-        <td>               This is the list of options to be passed to the JVM
-                The options are separated using hash (#) simbol.
-                For Example:
-                -Xmx=100M#-Djava.compiler=NONE</td></tr>
-    <tr><th>--StartupClass</th>
-        <td>Class name that will be called if started from JVM
-                when the applications starts.
-                The method name is separated by semicolon after the
-                class name.
-                The parameters passed to the class method are semicolon
-                separated values after the method name.
-                For example:
-                org/apache/jk/apr/TomcatStarter;Main;start</td></tr>
-    <tr><th>--ShutdownClass</th>
-        <td>Class name that will be called if started from JVM
-                when the applications stops. The class has to have
-                the method Main.
-                The method name is separated by semicolon after the
-                class name.
-                The parameters passed to the class method are semicolon
-                separated values after the method name.
-                For example:
-                org/apache/jk/apr/TomcatStarter;Main;stop;some;dummy;params</td></tr>
-   <tr><th>--StdInputFile</th>
-       <td>The file that will be read an passed as standard
-                input stream to the redirected application</td></tr>
-   <tr><th>--StdOutputFile</th>
-       <td>Path to the redirected stdout.</td></tr>
-   <tr><th>--StdErrorFile</th>
-       <td>Path to the redirected stderr.</td></tr>
-   <tr><th>--Startup</th>
-       <td>The services startup mode Automatic or Manual.
-                Default value is auto.</td></tr>
-   <tr><th>--User</th>
-       <td>The User account used for launching redirected process.</td></tr>
-   <tr><th>--Password</th>
-       <td>The password of User account used for launching
-                redirected process.</td></tr>
-   <tr><th>--Install</th>
-       <td>Used as Service manager ImagePath when installing
-                service from installation program using procrunw.</td></tr>
-  </table>
+<screen>
+<note>Install the service named 'TestService'</note>
+<type>prunsrv //IS//TestService --DisplayName="Test Service" \</type>
+<type>--Install=prunsrv.exe --Jvm=auto --StartMode=jvm --StopMode=jvm \</type>
+<type>--StartClass=org.apache.SomeStartClass --StartParams=arg1;arg2;arg3 \</type>
+<type>--StopClass=org.apache.SomeStopClass --StopParams=arg1#arg2 \</type>
+</screen>
 </p>
-</subsection>
-<subsection name="Running the service">
+</section>
+<section name="Updating services">
 <p>
-    You can use the Windows Service Manager to stop and start the 
-    service, as you would for any other service.  This is the recommended way
-    to manage the service.</p>
+To update the service parameters, you need to use the <b>//US//</b> parameter.
+</p>
 <p>
-    To test the service, or to simply run the process manually, use the //GT//
-    option for the Graphical version.  For example:
-    <source>
-       tomcatw //GT//Tomcat5
-    </source>
-    To test the non-Graphical version, use the //TS// option.  For example:
-    <source>
-      tomcat //TS//Tomcat5
-    </source>
-    Either of these will start your service as a normal program running under
-    the identity of the currently logged in user.  It is 
-    <strong>Important</strong> that the Service is stopped before testing, or
-    these commands will fail.</p>
-</subsection>
-<subsection name="Changing the Service Parameters from the GUI">
+<screen>
+<note>Update the service named 'TestService'</note>
+<type>prunsrv //US//TestService --Description="Some Dummy Test Service" \</type>
+<type>--Startup=auto --Classpath=%CLASSPATH%;test.jar</type>
+</screen>
+</p>
+</section>
+<section name="Removing services">
 <p>
-    To change the Service settings using the GUI interface, use the //ES// option with
-    <code>tomcatw.exe</code>.  You can then change the settings by entering
-    the new values in the correct boxes.  For example:
-    <source>
-      tomcatw //ES//Tomcat5
-    </source>
+To remove the service, you need to use the <b>//DS//</b> parameter.
+If the service is running it will be stopped and then deleted.
 </p>
-</subsection>
-<subsection name="Changing the Service Parameters from the Command Line">
 <p>
-   To change the Service settings from the command line, use the //US// option.
-   The parameters are the same as for <a href="#Installing%20the%20service">
-   Installing the service</a>.  For example:
-   <source>
-      tomcat //US//Tomcat5 --Java c:\jsdk1.4.1_02\jre\bin\client\jvm.dll \
-             --StdOutputFile c:\Tomcat5\logs\stdout.txt \
-             --StdErrorFile c:\Tomcat5\logs\stderr.txt
-   </source>
+<screen>
+<note>Remove the service named 'TestService'</note>
+<type>prunsrv //DS//TestService</type>
+</screen>
 </p>
-</subsection>
-<subsection name="Removing the Service">
+</section>
+
+<section name="Debugging services">
 <p>
-   To remove the service, use the //DS// option.  For example:
-   <source>
-     tomcat //DS//Tomcat5
-   </source>
-   This command will remove the service from the Windows Service Manager, but
-   it will still allow you to run it via the //GT// or //TS// options.
+To run the service in console mode, you need to use the <b>//TS//</b> parameter.
+The service shutdown can be initiated by pressing <b>CTRL+C</b> or
+<b>CTRL+BREAK</b>.
+If you rename the prunsrv.exe to testservice.exe then you can just execute the
+testservice.exe and this command mode will be executed by default.
+</p>
+<p>
+<screen>
+<note>Run the service named 'TestService' in console mode</note>
+<type>prunsrv //TS//TestService [additional arguments]</type>
+</screen>
 </p>
-</subsection>
 </section>
 
 </body>
-</document>
+</document> 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/commons-daemon.git



More information about the pkg-java-commits mailing list