@echo off
setlocal
REM Check administrator permissions
net session >nul 2>&1
if %errorLevel% neq 0 (
  echo "Please use administrator privileges to run this script!"
  pause
  exit /b
)

REM Kill Current Runing App
taskkill /F /IM "Yealink USB Connect.exe"

REM Install file Name
set "APP_INSTALL_FILE=Yealink USB Connect(X86)-4.41.12.0.msi"
REM EnterpriseId
set "EnterpriseId=oxtqoyae"
REM SitedId
set "SiteId="
REM AppDir
set "AppDir="
REM AutoRun
set "AutoRun=1"
REM RunApp
set "RunApp=0"
REM Protocol
set "Protocol="
REM Domain name or IP address
set "DomainName="
REM Port
set "Port=0"
REM Username
set "Username="
REM Password
set "Password="


REM Gets the directory path of the current script
set "script_dir=%~dp0"
REM Create a directory
set "publicDataPath=%public%\Yealink\Yealink USB Connect\Config"
if not exist "%publicDataPath%" (
  mkdir "%publicDataPath%"
)
REM Generates the specified file
echo {"EnterpriseId":"%EnterpriseId%","SiteId":"%SiteId%","EnterpriseMode":true, "Protocol":"%Protocol%", "DomainName":"%DomainName%", "Port":%Port%, "Username":"%Username%", "Password":"%Password%"} > "%publicDataPath%\yucdeploy.json"

msiexec /i "%script_dir%%APP_INSTALL_FILE%" /passive APPDIR="%AppDir%" ENABLE_AUTORUN=%AutoRun% RUNAPPLICATION=%RunApp%
endlocal
exit /b