@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    CD /D "%~dp0"

echo.
echo ******************************************************************************
echo *******Intel Management Engine Sofware Driver Installation [START]*******
echo ******************************************************************************
echo.

rem =============================Check for vPro=============================
echo Installing MEI(HECI) driver...
pnputil /add-driver "%~dp0MEI_SOL_Drivers\MEI\win10\heci.inf" /install

("%~dp0MEInfoWin64.exe" -feat "Current sku type") ^| find /i "Corporate"
if "%errorlevel%" == "0" GOTO Vpro_Install
rem =============================Check for vPro=============================

:NonvPro_Install
rem =======================MESW drivers and Components(non-vPro)======================
echo.
echo.
echo System is non-vPro...
echo.
echo.
echo Installing ME Software Components(JHI and WMIProvider INFs)...
echo.

pnputil /add-driver "%~dp0MESW_Components\JHI\win10\DAL.inf" /install
pnputil /add-driver "%~dp0MESW_Components\WMIProvider\MEWMIProv.inf" /install

GOTO END

:Vpro_Install
rem =======================MESW drivers and Components(vPro)======================
echo.
echo.
echo System is vPro...
echo Installing SOL drivers...
echo.
pnputil /add-driver "%~dp0MEI_SOL_Drivers\SOL\mesrl.inf" /install

echo.
echo.
echo Installing ME Software Components(IMSS_HSA_EXTENSION, JHI, LMS, SOL_LMS_Extension, WiMAN, wiman_wlan_extension and WMIProvider INFs)...
echo.

pnputil /add-driver "%~dp0MESW_Components\JHI\win10\DAL.inf" /install
pnputil /add-driver "%~dp0MESW_Components\LMS\LMS.inf" /install

pnputil /add-driver "%~dp0MESW_Components\wiman_wlan_extension\wiman_wlan_extension.inf" /install
pnputil /add-driver "%~dp0MESW_Components\SOL_LMS_Extension\SOLLMSExtension.inf" /install
pnputil /add-driver "%~dp0MESW_Components\WiMan\WiMan.inf" /install
pnputil /add-driver "%~dp0MESW_Components\IMSS_HSA_EXTENSION\ImssHsaExtension.inf" /install
pnputil /add-driver "%~dp0MESW_Components\WMIProvider\MEWMIProv.inf" /install

:END

echo.
echo ******************************************************************************
echo ********Intel Management Engine Sofware Driver Installation [END]********
echo ******************************************************************************
echo.


