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

REM You need to enter values in the area below between
REM the ****************
REM **************************************************
REM Start user input
REM You need to enter values for at least the 6 first
REM variables; NSControlPath, InstanceName, AppName, ServiceUserName, ServicePassWord, SqlServer

REM NSControlPath:REQUIRED. The path to NSControl.

set NSControlPath="c:\program files\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin"

echo %NSControlPath%

REM InstanceName:REQUIRED. The name for your Notification Service Instance.

set InstanceName=Stock


REM AppName:REQUIRED. The name for your Notification Service App.

set AppName=StockPrice


REM ServiceUserName:REQUIRED. The user name the Notification Services Windows 
REM service runs under - to make things easier, we hard code it to LocalSystem

set ServiceUserName=LocalSystem


REM ServicePassWord:REQUIRED. The password the Notification Services Windows 
REM service runs under

set ServicePassWord=


REM SqlServer:REQUIRED. Specifies the name of the SQL Server instance 
REM that is hosting the sample databases If using the default SQL Server 
REM instance, specify the computer name; otherwise, specify both the 
REM computer name and instance name in the form computer\instance.

set SqlServer=%COMPUTERNAME%


REM ServiceSqlServerUserName and ServiceSqlServerPassword: Optional. If you 
REM use SQL Server authentication to connect to SQL Server, this is the 
REM SQL Server user name and password that the service uses to access 
REM the sample databases. If you do not specify ServiceSqlServerUserName,
REM the account specified by ServiceUserName is used to connect to SQL Server.

set ServiceSqlServerAccount=
set ServiceSqlServerPassword=


REM SqlUserName:OPTIONAL. The account used by SetupSamples to run SQL Server 
REM tools, such as osql. Specify this parameter only if your SQL Server
REM administration account uses SQL authentication. If this value is not
REM supplied, Windows authentication is used.

set SqlUserName=

REM End user input
REM **********************************



REM Remove quotes from parameters that will be stored

set ServiceUserName=%ServiceUserName:"=%

set SqlServer=%SqlServer:"=%

if "%ServiceSqlServerAccount%" NEQ "" set ServiceSqlServerAccount=%ServiceSqlServerAccount:"=%

REM If there isn't an account specified that the service should use
REM to access SQL Server (ServiceSqlServerAccount) then use the
REM same account that the service runs under.  Note that this account
REM is not specified during Registration of the instance, only when
REM permissions are being granted on the database.

if "%ServiceSqlServerAccount%" EQU "" set ServiceSqlServerAccount=%ServiceUserName%

REM Convert the localsystem and NetworkService accounts into their machine account designation
if /I "localsystem" EQU "%ServiceSqlServerAccount%" set ServiceSqlServerAccount=NT AUTHORITY\SYSTEM
if /I "NT AUTHORITY\NetworkService" EQU "%ServiceSqlServerAccount%" set ServiceSqlServerAccount=NT AUTHORITY\NETWORK SERVICE


REM AppDirectory points at the root of the application. This
REM variable defaults to the directory above the current directory because we expect this
REM batch file to always be executed from that directory.

pushd ..\

set AppDirectory=%cd%

popd

REM NSHost defines the name of the computer where the Notifications
REM Services Windows service will run.

set NSHost=%COMPUTERNAME%

REM SqlLoginFlags defines the authentication scheme used when calling
REM SQL Server command line tools, such as OSQL.EXE.
REM   -E = Use trusted connection (Windows integrated security).  This
REM        is the recommended setting and the default if SqlUserName
REM        is not defined.
REM   -Uusername = Use SQL authentication (username and password).  Do
REM        not enter the password here, you will be prompted for it
REM        when needed.

set SqlLoginFlags=-E
if not "%SqlUserName%"=="" set SqlLoginFlags=-U%SqlUserName%

REM Path to SQL Server tools such as osql.exe.  Override if SQL was
REM installed to a different location.

if "%SQLTOOLS%" == "" set SQLTOOLS=%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn


REM SubscriptionApplicationAccount defines the account that the
REM accesses the database to manage subscriptions and events.  In the
REM Notification Services samples this is the ASPNET account on the
REM computer that hosts IIS.  If IIS and SQL Server are on separate
REM machines then the local ASPNET account cannot be used and either
REM ASP.NET must be configured to use a domain account or the
REM Notification Services instance must use SQL authentication.

REM This account must already have access to SQL Server.  If it is a
REM Windows account (integrated security) then grant access using
REM sp_grantlogin in Query Analyzer.  If it is a SQL Server account
REM then use sp_addlogin.

set SubscriptionApplicationAccount=%NSHost%\ASPNET


pushd ..\
set BaseDirectoryPath=%cd%
popd

set NSConfigFile=%BaseDirectoryPath%\appConfig.xml


goto End

:Usage
echo Required entried not entered
goto Error

:Error
echo Setup was unsuccessful.
exit /B 1

:End
echo Setup succeeded.
exit /B 0


