:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Setting Parameters
Set Destination=%ProgramFiles%\SIX Payment Services Ltd\MPD(Multi Protocol Driver)



:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Testing Administartive permissions
@echo off
cls
ECHO.
Echo Administrative permissions required. Detecting ...

Net Session >nul 2>&1
If %errorLevel% == 0 (
   Echo Success: Administrative permissions confirmed.
   goto Install
) else (
   COLOR 0C
   ECHO.
   ECHO.
   ECHO.ERROR: Logged-on user does not have administrative privilege!
   ECHO.
   ECHO.Logon as administrator or try right click on %0 and select 'Run as administrator'
   ECHO.
   ECHO.
   ECHO.
   PAUSE
   COLOR 07 
   cls
   Exit /B 1
)


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: starting installation
:Install
CD /D "%~dp0"


@echo on


Set /p Version= < version.srv

Set ServiceDisplayName=SIX MPD(Multi Protocol Driver)

net stop eftmpd


copy ".\%Version%\Windows\eftdvs.exe" "%Destination%" /Y


sc config eftmpd displayname= "%ServiceDisplayName%"
sc description eftmpd "Runs SIX MPD(Multi Protocol Driver) %Version%"
sc failure "eftmpd" reset= 300 command= "" actions= restart/10000/restart/20000/restart/30000

ver | findstr /I /C:"Version 6" > nul
IF not ErrorLevel 1 GOTO VistaWin7
netsh firewall add portopening protocol=TCP port=8138 name="%ServiceDisplayName% allow inbound  TCP-8138" mode=ENABLE scope=ALL
netsh firewall add portopening protocol=UDP port=33333 name="%ServiceDisplayName% allow outbound UDP-33333" mode=ENABLE scope=ALL
GOTO StartService

:VistaWin7
netsh advfirewall firewall delete rule name="%ServiceDisplayName% allow inbound  TCP-8138"
netsh advfirewall firewall delete rule name="%ServiceDisplayName% allow outbound UDP-33333"
netsh advfirewall firewall add rule name="%ServiceDisplayName% allow inbound  TCP-8138" protocol=TCP dir=in  localport=8138  action=allow
netsh advfirewall firewall add rule name="%ServiceDisplayName% allow outbound UDP-33333" protocol=UDP dir=out localport=33333 action=allow
GOTO StartService

:StartService
net start eftmpd

Set Destination=
Set ServiceDisplayName=
Set Version=

pause
