@echo off
set SOURCES=%SystemDrive%\TEMP\W10\sources
set BOOT=%SystemDrive%\TEMP\BOOT

rem check for wim file ...
if NOT EXIST %SOURCES%\boot.wim (
  echo ERROR: [ %SOURCES%\boot.wim ] NOT FOUND!
  exit /b
)

rem cleanup ...
rd /S /Q %BOOT% 2>nul

echo creating wim mountpoint for BOOT ...
mkdir %BOOT% 1>nul 2>nul

echo setting write access for boot.wim ...
attrib -R %SOURCES%\boot.wim

echo mounting boot.wim to %BOOT% ...
dism /Mount-Wim /WimFile:%SOURCES%\boot.wim /Name:"Microsoft Windows Setup (x64)" /MountDir:%BOOT% || (
  echo.
  echo ERROR while mounting WIM file! Please unmount orphaned images:
  dism /Get-MountedWimInfo

  echo.
  echo INFO. Use the following command to fix this problem:
  echo "dism /Unmount-Wim /MountDir:<Mount Dir> /Discard"
  exit /b 1
)

