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

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

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

echo creating image mountpoint ...
mkdir %IMAGE% 1>nul 2>nul

echo setting write access for install.wim ...
attrib -R %SOURCES%\install.wim 2>nul

echo mounting install.wim to %IMAGE% ...
dism /Mount-IMAGE /IMAGEFile:%SOURCES%\install.wim /Name:"Windows 10 Pro" /MountDir:%IMAGE% || (
  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
)

