slyfox1186

dism-mount-offline-windows-image.bat

Jun 10th, 2021 (edited)
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.79 KB | None | 0 0
  1. @ECHO OFF
  2. SETLOCAL ENABLEEXTENSIONS
  3. COLOR 0A
  4. TITLE CONVERT AND MOUNT WIM OR ESD FILES
  5.  
  6. :------------------------------------------------------------------------------------------------------------------------
  7.  
  8. REM Created by: SlyFox1186
  9. REM Pastebin: https://pastebin.com/u/slyfox1186
  10.  
  11. REM This batch script will convert a .esd file into a .wim or vice-versa
  12. REM then prompt the user to mount or unmount an offline image of windows
  13. REM thus allowing you to perform offline repairs in the event that the
  14. REM standard method of repairing a corrupted windows image has failed.
  15.  
  16. REM You need to acquire a Windows .iso file and copy the 'install.esd|wim' file
  17. REM inside the sources folder into the same folder as this script.
  18.  
  19. REM Save this using a .bat extension.
  20.  
  21. :------------------------------------------------------------------------------------------------------------------------
  22.  
  23. PUSHD "%~dp0"
  24. IF NOT "%1"=="MAX" START /MAX CMD /D /C %0 MAX & GOTO :EOF
  25.  
  26. :------------------------------------------------------------------------------------------------------------------------
  27.  
  28. ECHO Choose the input file to convert or skip this
  29. ECHO section and go straight to mount/unmount. & ECHO=
  30. ECHO [1] install.esd ^>^> install.wim
  31. ECHO [2] install.wim ^>^> install.esd
  32. ECHO [3] Skip and go to mount/unmount
  33. ECHO [4] Exit & ECHO=
  34.  
  35. CHOICE /C 1234 /N & CLS
  36.  
  37. IF ERRORLEVEL 4 GOTO :EOF
  38. IF ERRORLEVEL 3 GOTO MOUNT_THIS
  39. IF ERRORLEVEL 2 (
  40.     SET FileIn=install.wim
  41.     SET FileOut=install.esd
  42.   ) ELSE (
  43.     SET FileIn=install.esd
  44.     SET FileOut=install.wim
  45. )
  46.  
  47. :------------------------------------------------------------------------------------------------
  48. :GET_INDEX
  49. :------------------------------------------------------------------------------------------------
  50.  
  51. DISM /Get-ImageInfo /ImageFile:%FileIn% & ECHO=
  52.  
  53. SET Index=
  54. SET /P Index=Please select the index number that matches your Windows version: & CLS
  55.  
  56. IF DEFINED Index (
  57.     DISM /Export-Image /SourceImageFile:%FileIn% /SourceIndex:%Index% /DestinationImageFile:%FileOut% /Compress:Max /CheckIntegrity
  58.   ) ELSE (
  59.     ECHO You must enter one of the index numbers that match your Window's version! & ECHO=
  60.     PAUSE
  61.     CLS
  62.     GOTO GET_INDEX
  63. )
  64.  
  65. :------------------------------------------------------------------------------------------------
  66. :MOUNT_THIS
  67. :------------------------------------------------------------------------------------------------
  68.  
  69. CLS
  70. ECHO %FileOut% has been created.
  71. TIMEOUT 4 >NUL
  72. ECHO=
  73. ECHO What next? & ECHO=
  74. ECHO [1] Mount
  75. ECHO [2] Unmount
  76. ECHO [3] Exit & ECHO=
  77.  
  78. CHOICE /C 123 /N & CLS
  79.  
  80. IF ERRORLEVEL 3 GOTO :EOF
  81. IF ERRORLEVEL 2 (
  82.     DISM /Unmount-Image /MountDir:Mount /Discard
  83.     GOTO :EOF
  84. )
  85.  
  86. IF ERRORLEVEL 1 (
  87.     IF NOT EXIST Mount MD Mount >NUL
  88.     DISM /Mount-Image /ImageFile:%FileOut% /Index:1 /MountDir:Mount
  89. )
Advertisement
Add Comment
Please, Sign In to add comment