@echo off
setlocal enabledelayedexpansion 
cd %~dp0

if exist %SystemRoot%\System32\pnputil.exe (
	echo System32\pnputil.exe
    set "SystemPath=%SystemRoot%\System32"
) else if exist %SystemRoot%\Sysnative\pnputil.exe (
	echo Sysnative\pnputil.exe
    set "SystemPath=%SystemRoot%\Sysnative"
) else (
    echo ERROR: Cannot find pnputil.exe to install the driver.
    echo/
    pause
    goto :EOF
)
powershell "Get-PnpDevice -FriendlyName '*audio*'|Select-Object -Property HardwareID">[senary_temp].txt

rem withoutUWP, with Senary APO
type [senary_temp].txt|findstr /i "14F10252 14F10380 14F1037D 14F10247 14F10245 14F10242 14F10359 SUBSYS_14F10206 SUBSYS_14F10231 SUBSYS_14F10216 14F10215"
if !errorlevel!==0 goto Install-CA170

rem search for SK5.1
type [senary_temp].txt|findstr /i "SUBSYS_14F10224 SUBSYS_14F10101"
if !errorlevel!==0 goto Install-SK2

rem For other models
echo pnputil /add-driver "chdrt-base.inf" /install
%SystemPath%\pnputil.exe /add-driver "chdrt-base.inf" /install
echo pnputil /add-driver "chdrt-ext-common.inf" /install
%SystemPath%\pnputil.exe  /add-driver "chdrt-ext-common.inf" /install
goto end

:Install-CA170
echo pnputil /add-driver "chdrt-base.inf" /install
%SystemPath%\pnputil.exe  /add-driver "chdrt-base.inf" /install
echo pnputil /add-driver "chdrt-ext-common.inf" /install
%SystemPath%\pnputil.exe  /add-driver "chdrt-ext-common.inf" /install
echo pnputil /add-driver ".\SenaryAPO\SenaryAPO.inf" /install
%SystemPath%\pnputil.exe  /add-driver ".\SenaryAPO\SenaryAPO.inf" /install
goto end

:Install-SK2
echo pnputil /add-driver "chdrt-base.inf" /install
%SystemPath%\pnputil.exe  /add-driver "chdrt-base.inf" /install
echo pnputil /add-driver "chdrt-ext-common.inf" /install
%SystemPath%\pnputil.exe  /add-driver "chdrt-ext-common.inf" /install
echo pnputil /add-driver ".\SynaAPO\cisstrtU-component-OEM.inf" /install
%SystemPath%\pnputil.exe  /add-driver ".\SynaAPO\cisstrtU-component-OEM.inf" /install
echo pnputil /add-driver ".\SynaAPO\AudioService.inf" /install
%SystemPath%\pnputil.exe  /add-driver ".\SynaAPO\AudioService.inf" /install
goto end

:end
if exist [senary_temp].txt del [senary_temp].txt
REM restart two services
net.exe stop "audioendpointbuilder" /y
net.exe start "audioendpointbuilder"
net stop audiosrv /y
net start audiosrv

echo ===============================
echo Reboot now? [Y/N]
set /p var=
if /i %var% == y (shutdown /r /f /t 0) else pause
