@echo off
setlocal enabledelayedexpansion 
set indexcode=0
set e_code=0
set exitcode=0
cd %~dp0

.\devcon.exe driverfiles HUAWEI\OSD_DRIVER > drvlst.txt

set key=

for /f "tokens=4 delims=\[" %%i in ('findstr /r "oem[0-9]*.inf" drvlst.txt') do (
set key=%%i
)
echo key=!key!
if "%key%"=="" goto install

:remove
.\devcon.exe rescan
.\devcon.exe remove HUAWEI\OSD_DRIVER
.\devcon.exe -f dp_delete %key% 

@echo delete service
sc stop Huawei_OSDServer
sc delete Huawei_OSDServer

:install
devcon.exe install osd_driver.inf "HUAWEI\OSD_DRIVER"
devcon rescan

if %ERRORLEVEL% GTR 1 (
    set /a e_code=%ERRORLEVEL%%
    set /a index=1"<<"16
)

:exit
set /a indexcode=%index%
set /a exitcode=%indexcode%+%e_code%
exit /b %exitcode%
