anchor.diff:    shift
     goto LoopArgs
   )
  -if /I "%1"=="/password" (
  -  if not "%2"=="" (
  -    set PASSWORD=%2
  -  ) else (
  -    echo ERROR: You need to specify a password
  -    goto endBatch
  -  )
  -  shift
  -  shift
  -  goto LoopArgs
  -)
  -if /I "%1"=="/host" (
  +if /I "%~1"== "/jbosspass" (
  +  set JBOSSPASS=
  +  if not "%~2"=="" (
  +    set T=%~2
  +    if not "!T:~0,1!"=="/" (
  +      set JBOSSPASS=%~2
  +    )
  +  )
  +  if "!JBOSSPASS!" == "" (
  +    echo ERROR: You need to specify a password for /jbosspass
  +    goto endBatch
  +  )
  +  shift
  +  shift
  +  goto LoopArgs
  +)
  +if /I "%~1"== "/serviceuser" (
  +  set SERVICE_USER=
  +  if not "%~2"=="" (
  +    set T=%~2
  +    if not "!T:~0,1!"=="/" (
  +      set SERVICE_USER=%~2
  +    )
  +  )
  +  if "!SERVICE_USER!" == "" (
  +    echo ERROR: You need to specify a username in the format DOMAIN\USER, or .\USER for the local domain
  +    goto endBatch
  +  )
  +  shift
  +  shift
  +  goto LoopArgs
  +)
  +if /I "%~1"== "/servicepass" (
  +  set SERVICE_PASS=
  +  if not "%~2"=="" (
  +    set T=%~2
  +    if not "!T:~0,1!"=="/" (
  +      set SERVICE_PASS=%~2
  +    )
  +  )
  +  if "!SERVICE_PASS!" == "" (
  +    echo ERROR: You need to specify a password for /servicepass
  +    goto endBatch
  +  )
  +  shift
  +  shift
  +  goto LoopArgs
  +)
  +rem the hostname is optional
  +if /I "%~1"== "/host" (
     set IS_DOMAIN=true
  -  if not "%2"=="" (
  -    set T=%2
  -    if not "!T:~0,1!"=="/" (
  -      set DC_HOST=!T!
  +  if not "%~2"=="" (
  +    set T=%~2
  +    if not "!T:~0,1!"=="/" (
  +      set DC_HOST=%~2
         shift
       )
     )
     shift
     goto LoopArgs
   )
  -if /I "%1"=="/loglevel" (
  -  if /I not "%2"=="Error" if /I not "%2"=="Info" if /I not "%2"=="Warn" if /I not "%2"=="Debug" (
  +if /I "%~1"== "/loglevel" (
  +  if /I not "%~2"=="Error" if /I not "%~2"=="Info" if /I not "%~2"=="Warn" if /I not "%~2"=="Debug" (
       echo ERROR: /loglevel must be set to Error, Info, Warn or Debug ^(Case insensitive^)
  -    goto endBatch      
  -  )
  -  set LOGLEVEL=%2
  +    goto endBatch
  +  )
  +  set LOGLEVEL=%~2
  +  shift
  +  shift
  +  goto LoopArgs
  +)
  +if /I "%~1"== "/logpath" (
  +  set LOGPATH=
  +  if not "%~2"=="" (
  +    set T=%~2
  +    if not "!T:~0,1!"=="/" (
  +      set LOGPATH=%~2
  +	)
  +  )
  +  if "!LOGPATH!" == "" (
  +    echo ERROR: You need to specify a path for the service log
  +    goto endBatch
  +  )
     shift
     shift
     goto LoopArgs
  
positive.code: @echo off
  setlocal EnableExtensions EnableDelayedExpansion
  REM -------------------------------------------------------------------------
  REM  Red Hat - JBoss EAP 6 Service Script for Windows
  REM            It has to reside in modules\native\sbin\
  REM
  REM  2013-07-01 Minor changes to make it work with Wildfly
  REM  2012-09-14 fixed service log path
  REM             cmd line options for controller,domain host, loglevel,
  REM		username,password
  REM  2012-09-05 NOPAUSE support
  REM  2012-08-20 initial edit
  REM
  REM Author: Tom Fonteyne
  REM
  REM ==================================================================
  REM If more then one service is needed, copy this file to another name
  REM and use unique names for SHORTNAME, DISPLAYNAME, DESCRIPTION
  REM ==================================================================
  set SHORTNAME=Wildfly
  set DISPLAYNAME="Wildfly"
  set DESCRIPTION="Wildfly Application Server"
  REM ========================================================
  
  set "DIRNAME=%~dp0%"
  cd > nul
  pushd %DIRNAME%..\..
  set "RESOLVED_JBOSS_HOME=%CD%"
  popd
  set DIRNAME=
  
  if "x%JBOSS_HOME%" == "x" (
    set "JBOSS_HOME=%RESOLVED_JBOSS_HOME%" 
  )
  
  pushd "%JBOSS_HOME%"
  set "SANITIZED_JBOSS_HOME=%CD%"
  popd
  
  if "%RESOLVED_JBOSS_HOME%" NEQ "%SANITIZED_JBOSS_HOME%" (
      echo WARNING JBOSS_HOME may be pointing to a different installation - unpredictable results may occur.
      echo Please check that this script is located in the bin\services\ directory.
      goto cmdEnd
  )
  rem Find jboss-modules.jar to check JBOSS_HOME
  if not exist "%JBOSS_HOME%\jboss-modules.jar" (
    echo Could not locate "%JBOSS_HOME%\jboss-modules.jar".
    echo Please check that this script is located in the bin\services\ directory.
    goto cmdEnd
  )
  
  if "x%JAVA_HOME%" == "x" (
    echo JAVA_HOME is not set.
    echo Set JAVA_HOME to the directory of your local JDK to avoid this message.
    goto cmdEnd
  )
  
  if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
    echo Using the X86-64bit version of prunsrv
    set PRUNSRV="%JBOSS_HOME%\bin\service\amd64\wildfly-service"
  
negative.code: :doInstall
  set CREDENTIALS=
  if not "%JBOSSUSER%" == "" (
    if "%JBOSSPASS%" == "" (
      echo When specifying a user, you need to specify the password
      goto endBatch
    )
    set CREDENTIALS=--user=%JBOSSUSER% --password=%JBOSSPASS%
  )
  
  set RUNAS=
  if not "%SERVICE_USER%" == "" (
    if "%SERVICE_PASS%" == "" (
      echo When specifying a user, you need to specify the password
      goto endBatch
    )
    set RUNAS=--ServiceUser=%SERVICE_USER% --ServicePassword=%SERVICE_PASS%
  )
  
  if "%STDOUT%"=="" set STDOUT=auto
  if "%STDERR%"=="" set STDERR=auto
  
  if "%START_PATH%"=="" set START_PATH="%JBOSS_HOME%\bin"
  if "%STOP_PATH%"=="" set STOP_PATH="%JBOSS_HOME%\bin"
  
  if "%STOP_SCRIPT%"=="" set STOP_SCRIPT=jboss-cli.bat
  
  if /I "%IS_DOMAIN%" == "true" (
    if "%BASE%"=="" set BASE="%JBOSS_HOME%\domain"
    if "%CONFIG%"=="" set CONFIG=domain.xml
    if "%START_SCRIPT%"=="" set START_SCRIPT=domain.bat
    set STARTPARAM="/c#set#NOPAUSE=Y#&&#!START_SCRIPT!#-Djboss.domain.base.dir=!BASE!#--domain-config=!CONFIG!#--host-config=!HOSTCONFIG!"
    set STOPPARAM="/c %STOP_SCRIPT% --controller=%CONTROLLER% --connect %CREDENTIALS% --command=/host=!DC_HOST!:shutdown"
  ) else (
    if "%BASE%"=="" set "BASE=%JBOSS_HOME%\standalone"
    if "%CONFIG%"=="" set CONFIG=standalone.xml
    if "%START_SCRIPT%"=="" set START_SCRIPT=standalone.bat
    set STARTPARAM="/c#set#NOPAUSE=Y#&&#!START_SCRIPT!#-Djboss.server.base.dir=!BASE!#--server-config=!CONFIG!"
    set STOPPARAM="/c !STOP_SCRIPT! --controller=%CONTROLLER% --connect %CREDENTIALS% --command=:shutdown"
  )
  
  if "%LOGPATH%"=="" set LOGPATH="!BASE!\log"
  
  if not exist "%BASE%" (
    echo The base directory does not exist: "%BASE%"
    goto endBatch
  )
  
  if not exist "%BASE%\configuration\%CONFIG%" (
    echo The configuration does not exist: "%BASE%\configuration\%CONFIG%"
    goto endBatch
  )
  
  if /I "%ISDEBUG%" == "true" (
    echo JBOSS_HOME="%JBOSS_HOME%"
    echo RUNAS=%RUNAS%
    echo SHORTNAME="%SHORTNAME%"
    echo DESCRIPTION="%DESCRIPTION%"
    echo STARTPARAM=%STARTPARAM%
    echo STOPPARAM=%STOPPARAM%
    echo LOGLEVEL=%LOGLEVEL%
    echo LOGPATH=%LOGPATH%
    echo CREDENTIALS=%CREDENTIALS%
    echo BASE="%BASE%"
    echo CONFIG="%CONFIG%"
    echo START_SCRIPT=%START_SCRIPT%
    echo START_PATH=%START_PATH%
    echo STOP_SCRIPT=%STOP_SCRIPT%
    echo STOP_PATH=%STOP_PATH%
    echo STDOUT="%STDOUT%"
    echo STDERR="%STDERR%"
  )
  if /I "%ISDEBUG%" == "true" (
    @echo on
  )
  
  @rem quotes around the "%DESCRIPTION%" but nowhere else
  echo %PRUNSRV% install %SHORTNAME% %RUNAS% --DisplayName=%DISPLAYNAME% --Description="%DESCRIPTION%" --LogLevel=%LOGLEVEL% --LogPath=%LOGPATH% --LogPrefix=service --StdOutput=%STDOUT% --StdError=%STDERR% --StartMode=exe --Startup=%STARTUP_MODE% --StartImage=cmd.exe --StartPath=%START_PATH% ++StartParams=%STARTPARAM% --StopMode=exe --StopImage=cmd.exe --StopPath=%STOP_PATH%  ++StopParams=%STOPPARAM%
  
  %PRUNSRV% install %SHORTNAME% %RUNAS% --DisplayName=%DISPLAYNAME% --Description="%DESCRIPTION%" --LogLevel=%LOGLEVEL% --LogPath=%LOGPATH% --LogPrefix=service --StdOutput=%STDOUT% --StdError=%STDERR% --StartMode=exe --Startup=%STARTUP_MODE% --StartImage=cmd.exe --StartPath=%START_PATH% ++StartParams=%STARTPARAM% --StopMode=exe --StopImage=cmd.exe --StopPath=%STOP_PATH%  ++StopParams=%STOPPARAM%
  @rem %PRUNSRV% install "%SHORTNAME%" "%RUNAS%" --DisplayName="%DISPLAYNAME%" --Description="%DESCRIPTION%" --LogLevel="%LOGLEVEL%" --LogPath="%LOGPATH%" --LogPrefix=service --StdOutput="%STDOUT%" --StdError="%STDERR%" --StartMode=exe --Startup="%STARTUP_MODE%" --StartImage=cmd.exe --StartPath="%START_PATH%" ++StartParams="%STARTPARAM%" --StopMode=exe --StopImage=cmd.exe --StopPath="%STOP_PATH%"  ++StopParams="%STOPPARAM%"
  
  @if /I "%ISDEBUG%" == "true" (
    @echo off
  )
  
  if errorlevel 8 (
    echo ERROR: The service %SHORTNAME% already exists
    goto endBatch
  )
  if errorlevel 0 (
    echo Service %SHORTNAME% installed
    goto endBatch
  )
  goto cmdEnd
  
  
  REM the other commands take a /name parameter - if there is no ^<servicename^> passed as second parameter,
  REM we silently ignore this and use the default SHORTNAME
  
  :cmdUninstall
  if /I "%~1"=="/name" (
    if not "%~2"=="" (
      set SHORTNAME="%~2"
    )
  )
  %PRUNSRV% stop %SHORTNAME%
  if errorlevel 0 (
    %PRUNSRV% delete %SHORTNAME%
    if errorlevel 0 (
      echo Service %SHORTNAME% uninstalled
    )
  ) else (
    echo Unable to stop the service %SHORTNAME%
  )
  goto cmdEnd
  
  :cmdStart
  if /I "%~1"=="/name" (
    if not "%~2"=="" (
      set SHORTNAME="%~2"
    )
  )
  %PRUNSRV% start %SHORTNAME%
  echo Service %SHORTNAME% starting...
  goto cmdEnd
  
  :cmdStop
  if /I "%~1"=="/name" (
    if not "%~2"=="" (
      set SHORTNAME="%~2"
    )
  )
  %PRUNSRV% stop %SHORTNAME%
  echo Service %SHORTNAME% stopping...
  goto cmdEnd
  
  :cmdRestart
  if /I "%~1"=="/name" (
    if not "%~2"=="" (
      set SHORTNAME="%~2"
    )
  )
  %PRUNSRV% stop %SHORTNAME%
  echo Service %SHORTNAME% stopping...
  if "%errorlevel%" == "0" (
    %PRUNSRV% start %SHORTNAME%
    echo Service %SHORTNAME% starting...
  ) else (
    echo Unable to stop the service %SHORTNAME%
  )
  goto cmdEnd
  
  
  :cmdEnd
  REM if there is a need to add other error messages, make sure to list higher numbers first !
  if errorlevel 2 (
    echo ERROR: Failed to load service %SHORTNAME% configuration
    goto endBatch
  )
  if errorlevel 0 (
    goto endBatch
  )
  echo "Unforseen error=%errorlevel%"
  
  rem nothing below, exit
  :endBatch
  