@if "%_echo%" == "" echo off

setlocal

REM set up the parameters
echo **** Retrieving parameters
call Setup.cmd

echo **** Get status of the instance to determine its existence
call %NSControlPath%\NSControl.exe status -name %InstanceName% > nul
if %ERRORLEVEL% GEQ 1 goto Create

echo.
echo **** Instance exists. Running NSControl Disable to prepare for Update
call %NSControlPath%\NSControl.exe disable -n %InstanceName%
if %ERRORLEVEL% GEQ 1 goto Error

echo.
echo **** Running NSControl Update to update the existing instance
call %NSControlPath%\NSControl.exe update -force -in "%NSConfigFile%"
if %ERRORLEVEL% GEQ 1 goto Error

echo.
echo **** Running NSControl Enable to re-enable the instance
call %NSControlPath%\NSControl.exe enable -n %InstanceName%
if %ERRORLEVEL% GEQ 1 goto Error

goto End


:Create
echo.
echo **** Instance does not exist. Running NSControl Create
call RunCreate.cmd
if %ERRORLEVEL% GEQ 1 goto Error



:End
exit /B 0

:Error
exit /B 1

