@echo off
setlocal enabledelayedexpansion 

echo Begin removing Senary drivers infs....
rem uninstall infs
for /f "tokens=1,2,5 delims=|" %%i in ( 'dism /online /get-drivers /format:table ^|findstr /i Senary' ) do (
	echo %%k|findstr /i Senary>nul
	if !errorlevel!==0 (
	pnputil /delete-driver %%i /uninstall /force>nul
	echo --^> %%j removed!
	)
)

rem uninstall app
powershell "get-appxpackage -allusers *Senary* |remove-appxpackage -allusers"

rem remove registry settings
for /L %%i in (0,1,9) do (reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}\000%%i /f "senary" >nul 2>nul
if !errorlevel!==0 (reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}\000%%i /f >nul 2>nul&&echo 000%%i deleted)
)
for /L %%i in (10,1,19) do (reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}\00%%i /f "senary" >nul 2>nul
if !errorlevel!==0 (reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}\00%%i /f >nul 2>nul&&echo 00%%i deleted)
)


@echo off

rem Setting all UWD inf names
set substring_1=intcaudiobus.inf
set substring_2=intcdmic.inf
set substring_3=intcoed.inf
set substring_4=intcsdw.inf
set substring_5=intcsst.inf
set substring_6=Intcbtau.inf
set substring_7=detectionverificationdrv.inf
set substring_8=Intcusb.inf
set substring_9=Intelmvaextension.inf

set counter1=0
set counter2=0
set counter3=0
set counter4=0
set counter5=0
set counter6=0
set counter7=0
set counter8=0
set counter9=0

set prev_line=""

pnputil /enum-drivers > drivers.txt

set "File2Read=drivers.txt"
If Not Exist "%File2Read%" (Goto :Error)

rem This will read a file into an array of variables and populate it 
setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%File2Read%"') do (
    set /a count+=1
    set "Line[!count!]=%%a"
)
For /L %%i in (1,1,%Count%) do (
	echo "!Line[%%i]!" | findstr /C:"!substring_1!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter1+=1
	)
	
	echo "!Line[%%i]!" | findstr /C:"!substring_2!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter2+=1
	)
	
	echo "!Line[%%i]!" | findstr /C:"!substring_3!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter3+=1
	)
	
	echo "!Line[%%i]!" | findstr /C:"!substring_4!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter4+=1
	)
	echo "!Line[%%i]!" | findstr /C:"!substring_5!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter5+=1
	)
	echo "!Line[%%i]!" | findstr /C:"!substring_6!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter6+=1
	)
	echo "!Line[%%i]!" | findstr /C:"!substring_7!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter7+=1
	)
	echo "!Line[%%i]!" | findstr /C:"!substring_8!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter8+=1
	)
	echo "!Line[%%i]!" | findstr /C:"!substring_9!" 1>nul
	if errorlevel 1 (
		rem pattern not found
		rem echo "did not find "!substring_1!" in !Line[%%i]!"
	) ELSE (
		rem got zero found pattern
		call :getOemNum "!Line[%%i]!" "!prev_line!"
		set /a counter9+=1
	)
	set "prev_line=!Line[%%i]!"
)

echo "%substring_1% found and removed: %counter1% times"
echo "%substring_2% found and removed: %counter2% times"
echo "%substring_3% found and removed: %counter3% times"
echo "%substring_4% found and removed: %counter4% times"
echo "%substring_5% found and removed: %counter5% times"
echo "%substring_6% found and removed: %counter6% times"
echo "%substring_7% found and removed: %counter7% times"
echo "%substring_8% found and removed: %counter8% times"
echo "%substring_9% found and removed: %counter9% times"

exit /b 0

:getOemNum
rem echo "proccesing %1, searching for %~2"
for /F "tokens=2 delims=:" %%a in ("%~2%") do ( 
   call :deleteOEM %%a
)
exit /b

:deleteOEM
set strDelete="remove %1"
echo %strDelete%
pnputil -d %1 -u -f
exit /b

:ERROR 
ECHO Uninstall failed, refer to logFile.
echo   The file "%File2Read%" does not exist !
exit /b 1



echo --------------------------------------------------------
echo Done
%windir%\system32\Dism.exe /online /get-drivers /format:table | findstr /i Senary && echo The above infs are still present on the system. || echo All Senary infs removed successfully!
echo Reboot now? [Y/N]
set /p var=
if /i %var% == y (shutdown /r /f /t 0) else exit

pause
