title "%~dp0"
cd /d "%~dp0"
echo =============== >>C:\Windows\Logs\IMAGE_PROCESS_TIME.log
echo %date%>>C:\Windows\Logs\IMAGE_PROCESS_TIME.log 
echo %time%>>C:\Windows\Logs\IMAGE_PROCESS_TIME.log
echo "%~dp0">>C:\Windows\Logs\IMAGE_PROCESS_TIME.log
echo =============== >>C:\Windows\Logs\IMAGE_PROCESS_TIME.log



@echo off
setlocal enabledelayedexpansion
echo ================================
echo Starting driver installation...
echo ================================

REM === Define HWIDs and driver folders ===
set COUNT=1

set "HWID1=INTELAUDIO\FUNC_01&VEN_10EC&DEV_0245&SUBSYS_14586042"
set "DIR1=Drivers"

set FOUND=0

REM === Loop through HWID list ===
for /L %%i in (1,1,%COUNT%) do (
    call set "CURRENT_HWID=%%HWID%%i%%"
    call set "CURRENT_DIR=%%DIR%%i%%"

    echo Checking for exact match: !CURRENT_HWID! ...
    set /a MATCH=0
    pnputil /enum-devices /connected | find /i "!CURRENT_HWID!" >nul 2>&1

    if !errorlevel! == 0 (
        echo [OK] Found matching device: !CURRENT_HWID!
        echo Installing drivers from: !CURRENT_DIR!
        set  /a MATCH=1
        REM === Install Driver ===
        set INSTALLED=0
        if exist "%~dp0!CURRENT_DIR!\sysnative\pnputil.exe" (
            "%SYSTEMROOT%\sysnative\pnputil.exe" /add-driver "%~dp0*.inf" /subdirs /install
            set INSTALLED=1
            set /A FOUND+=1
        )else (
            "%SYSTEMROOT%\system32\pnputil.exe" /add-driver "%~dp0*.inf" /subdirs /install
            set INSTALLED=1
            set /A FOUND+=1
            )
            
        if !INSTALLED! == 1 (
            echo [INFO] Installed driver from !CURRENT_DIR!
        ) else (
            echo [ERROR] No executable found in !CURRENT_DIR!
        )
        timeout /t 2 >nul
    )
    if !MATCH!==0 (
        echo [SKIP] Device not matched: !CURRENT_HWID!
    )    
         
)     


if %FOUND%==0 (
    echo [RESULT] No matching hardware found. No drivers installed.
) else (
    echo [RESULT] Successfully installed %FOUND% driver.)

echo ================================
timeout /t 3
