@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
    pushd "%CD%"
    CD /D "%~dp0"

::***************************************************************************
:: to creat pnp.cmd
echo pnputil.exe -i -a %%1>pnp.cmd
echo echo %%errorlevel%% ^>temp.log>>pnp.cmd
echo echo Installed %%1 ^>^>log.txt>>pnp.cmd
echo echo return code:%%errorlevel%% ^>^>log.txt>>pnp.cmd
echo ping 127.0.0.1 -n ^3>>pnp.cmd
echo exit>>pnp.cmd

ping 127.0.0.1 -n 1

:InstallDriver
del /f /q log.txt

echo.
echo ******************************************************************************
echo *******IMSS Installation [START]*******
echo ******************************************************************************
echo.

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

:Vpro_Install
rem =======================MESW drivers and Components(vPro)======================
echo.
echo.
echo System is vPro...
echo Installing IMSS app...
echo.

DISM /Online /Add-ProvisionedAppxPackage /PackagePath:%~dp0ba91b44b7ae64906b0929ce4c80fa0a5.appxbundle /DependencyPackagePath:%~dp0Microsoft.VCLibs.140.00.UWPDesktop_14.0.33728.0_x64__8wekyb3d8bbwe.appx /LicensePath:%~dp0ba91b44b7ae64906b0929ce4c80fa0a5_License1.xml /Region="ALL"

GOTO END

:noVpro_Install
if "%errorlevel%" == "1" set %errorlevel% = 0

GOTO END


:NO_Temp
del /f /q pnp.cmd
echo No found temp.log....
exit /b 1

:NO_FOUND
del /f /q pnp.cmd
echo No any data in temp.log....
exit /b 1

:NG
del /f /q pnp.cmd
echo Install Fail....
exit /b 1

:end
del /f /q temp.log
del /f /q pnp.cmd
del /f /q log.txt
ping 127.0.0.1 -n 2
