:: clear screen...
cls

@echo.
@echo ============================================================================
@echo                            ndd Medical Technologies
@echo.
@echo                               DRIVER INSTALLATION
@echo.
@echo                         PLEASE DO NOT CLOSE THIS WINDOW !
@echo ============================================================================
@echo.
@echo The following steps will be performed:
@echo.
@echo     Step #1 collects a list with all inf files
@echo     Step #2 scans this list for vendor id "VID_0F00" (ndd)
@echo     Step #3 removes all ndd related drivers
@echo.

@echo off & Setlocal 
::Setlocal

:: defines for different temp files...
set inffiles=rndb_inffiles.txt
set found=rndb_found.txt
set todelete=rndb_todelete.txt
set devcondels=rndb_deleted.txt

:: defines for del command...
rem set deletepar=/p /f
set deletepar=/q /f

:: message if command is not available...
FINDSTR /? >NUL 2>&1 || ECHO DOS Command "FINDSTR" is not available!


:: delete temp files if they exist...
if exist %inffiles% del /q %inffiles%
if exist %found% del /q %found%
if exist %todelete% del /q %todelete%
if exist %devcondels% del /q %devcondels%

:: get all files with extension .inf...
echo.
echo Step #1: collecting a list with all inf files (*.inf)...
@FOR /f "delims=" %%? IN ('dir /b %windir%\inf\*.inf') DO @ECHO/%%~n?>> %inffiles%

echo.
if exist %inffiles% (
  :: scanning inf files...
  echo Step #2: Scanning inf files with references to ndd vendor id VID_0F00...
  FOR /F "tokens=1* delims=;" %%A IN (%inffiles%) DO (
    findstr /c:"VID_0F00" "%windir%\inf\%%A.inf" >> %found% && (echo %windir%\inf\%%A.* >> %todelete%)
  )
) else (
  echo Step #2: no inf files found!
)

:: remove all usb drivers with references to ndd vendor id VID_0F00...
echo.
if exist %todelete% (
  echo Step #3: removing all ndd drivers ...
) else (
  echo Step #3: no ndd drivers could be found!
)

FOR /F "tokens=1 delims=:	 " %%A IN ('DEVCON FindAll ^=USB ^| FIND "USB\VID_0F00"') DO (
  DEVCON Remove "@%%A"
  echo %%A.* >> %devcondels%
)

:: report deleted driver names...
if exist %devcondels% (
  echo. >> %devcondels%
  >> %devcondels% ECHO.%Date%, %Time%
  echo NDD drivers removed by DevCon: >> %devcondels%
  DEVCON FindAll =USB | FIND "USB\VID_0F00" >> %devcondels%
)

:: delete all files found before...
if exist %todelete% (
  @echo Files found:
  FOR /F "tokens=* delims=;" %%B IN (%todelete%) DO (
    echo del %deletepar% "%%B"
    del %deletepar% "%%B"
  )
)

@echo.
@echo script terminated
@echo.
::pause