Unable to factory reset after replacing recovery image

Fugazi

New Member
Messages
1
Hi,

Hopefully this is the right place for my problem, if not please accept my apologies.

I have a device that uses the WIMBoot method - https://technet.microsoft.com/en-GB/library/dn594399.aspx
the device has four partitions, a 300MB System partition, 128MB MSR partions, OS Partition and a Recovery Partition.

I have created a DOS command batch program that runs from a WinPE USB, that takes an image of the device and saves it to the USB (no problems with that)

When I then use the Recovery option of my DOS command batch program it does the following;

Code:
REM --- Constants used to calculate free space ---
REM Overhead Ratio: assume 6 MB overhead per 1000 MB size
set /a NTFS_OVERHEAD_RATIO=500/497
REM Per-Partition Overhead: 5 MB per partition
set /a NTFS_OVERHEAD_BASE=5

REM Megabytes-to-Millions Ratio:
REM This ratio converts values from megabytes to millions of bytes, approximately. 
set /a mega_million_ratio=205/215

REM --------- Constants -------------

REM Drive letter of the Windows partition.
set user_volume=C:

REM Drive letter that contains \Images\install.wim. Example: E:
set wimfile_path=%directory%

REM Drive letter that contains \Images\winre.wim. Example: E:
set winre_wim_path=%directory%

for %%A in (%wimfile_path%\install.wim) do ( 
set install_wim_file_bytes=%%~zA
echo install.wim is [%install_wim_file_bytes%] bytes.
)
set /a install_wim_file_MB=%install_wim_file_bytes:~0,-6%+0
set /a install_wim_file_MB=%install_wim_file_MB%*205/215

for %%A in (%winre_wim_path%\winre.wim) do ( 
set winre_wim_file_bytes=%%~zA
echo winre.wim is [%winre_wim_file_bytes%] bytes.
)
set /a winre_wim_file_MB=%winre_wim_file_bytes:~0,-6%
set /a winre_wim_file_MB=%winre_wim_file_MB%*205/215

set /a more_size=500
set /a wim_partition_size_MB=%install_wim_file_MB%
set /a wim_partition_size_MB=%wim_partition_size_MB%+%winre_wim_file_MB%

set /a wim_partition_size_MB=%wim_partition_size_MB%+%more_size%
set /a wim_partition_size_MB=%wim_partition_size_MB%+%NTFS_OVERHEAD_BASE%
set /a wim_partition_size_MB=%wim_partition_size_MB%*500/497
echo Final Images partition size = {%wim_partition_size_MB%} MB

set wim_partition_letter=M:

echo. > %Drive%\DP1.TXT
echo select disk 0 >> %Drive%\DP1.TXT
echo clean >> %Drive%\DP1.TXT
echo convert gpt >> %Drive%\DP1.TXT
rem == 1. System partition (ESP)
echo create partition efi size=100 >> %Drive%\DP1.TXT
echo format quick fs=fat32 label="System"  >> %Drive%\DP1.TXT
rem == 2. Microsoft Reserved (MSR) partition
echo create partition msr size=128 >> %Drive%\DP1.TXT
rem == 3. Windows partition
echo create partition primary >> %Drive%\DP1.TXT
echo shrink minimum=%wim_partition_size_MB% >> %Drive%\DP1.TXT
echo format quick fs=ntfs label="Windows" >> %Drive%\DP1.TXT
echo assign letter=%user_volume% >> %Drive%\DP1.TXT
rem === 4. Images partition
echo create partition primary >> %Drive%\DP1.TXT
echo format quick fs=ntfs label="Images" >> %Drive%\DP1.TXT
echo assign letter=%wim_partition_letter% >> %Drive%\DP1.TXT
echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >> %Drive%\DP1.TXT
echo gpt attributes=0x8000000000000001 >> %Drive%\DP1.TXT
echo exit >> %Drive%\DP1.TXT

diskpart /s %Drive%\DP1.TXT 

DEL %DRIVE%\DP1.TXT
md "%wim_partition_letter%\Windows Images\"
md %wim_partition_letter%\Recovery\WindowsRE

robocopy %wimfile_path%\ "%wim_partition_letter%\Windows Images\ " install.wim /s /copy:datso /dcopy:t
robocopy %winre_wim_path%\ %wim_partition_letter%\Recovery\WindowsRE\ winre.wim /s /copy:datso /dcopy:t
 
rem == Create a scratch directory for DISM operations 
md %user_volume%\Recycler\Scratch
 
rem == Apply the Windows image to the Windows partition == 
Dism /Apply-Image /ImageFile:"%wim_partition_letter%\Windows Images\install.wim" /ApplyDir:%user_volume% /Index:1 /WIMBoot /ScratchDir:%user_volume%\Recycler\Scratch 

rmdir %user_volume%\Recycler\Scratch

rem == Create boot files on the System partition == 
%user_volume%\Windows\System32\bcdboot %user_volume%\Windows

reagentc.exe /DISABLE
reagentc.exe /setreimage /path r:\Recovery\WindowsRE /target c:\Windows
reagentc.exe /ENABLE

Everything seems to have worked correctly, the system boots up .. however when I try to do a factory restore, removing everything it starts and then fails.

Any help would be appreciated.
 

My Computer

System One

  • OS
    Windows 8 with Bing
    Computer type
    Tablet
Because you are missing two files from within "%wim_partition_letter%\Windows Images"

ResetPartitions
Code:
echo. > %Drive%\ResetPartitions.txt
echo convert gpt >> %Drive%\ResetPartitions.txt
rem == 1. System partition (ESP)
echo create partition efi size=100 >> %Drive%\ResetPartitions.txt
echo format quick fs=fat32 label="System"  >> %Drive%\ResetPartitions.txt
rem == 2. Microsoft Reserved (MSR) partition
echo create partition msr size=128 >> %Drive%\ResetPartitions.txt
rem == 3. Windows partition
echo create partition primary >> %Drive%\ResetPartitions.txt
echo shrink minimum=%wim_partition_size_MB% >> %Drive%\ResetPartitions.txt
echo format quick fs=ntfs label="Windows" >> %Drive%\ResetPartitions.txt
echo assign letter=%user_volume% >> %Drive%\ResetPartitions.txt
rem === 4. Images partition
echo create partition primary >> %Drive%\ResetPartitions.txt
echo format quick fs=ntfs label="Images" >> %Drive%\ResetPartitions.txt
echo assign letter=%wim_partition_letter% >> %Drive%\ResetPartitions.txt
echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >> %Drive%\ResetPartitions.txt
echo gpt attributes=0x8000000000000001 >> %Drive%\ResetPartitions.txt
echo exit >> %Drive%\ResetPartitions.txt

ResetConfig.xml
Code:
<?xml version="1.0" [COLOR=#ff0000]e[/COLOR][COLOR=#ff0000]ncoding="utf-8"[/COLOR]?>
<!-- ResetConfig.xml for WIMBoot -->
   <Reset>
      <SystemDisk>
         <WIMBoot>1</WIMBoot>
         <DiskpartScriptPath>ResetPartitions.txt</DiskpartScriptPath>
         <MinSize>12500</MinSize>
         <WindowsREPartition>4</WindowsREPartition>
         <WindowsREPath>Recovery\WindowsRE</WindowsREPath>
         <OSPartition>3</OSPartition>
         <RecoveryImagePartition>4</RecoveryImagePartition>
         <RecoveryImagePath>Windows Images</RecoveryImagePath>
         <RestoreFromIndex>1</RestoreFromIndex>
         <RecoveryImageIndex>1</RecoveryImageIndex>
      </SystemDisk>
   </Reset>

Code:
copy %DRIVE%\ResetPartitions.txt "%wim_partition_letter%\Windows Images\ResetPartitions.txt "
del %DRIVE%\ResetPartitions.txt
copy %DRIVE%\ResetConfig.xml "%wim_partition_letter%\Windows Images\ResetConfig.xml"
del %DRIVE%\Resetconfig.xml

You will have to work out the coding in your batch file to create a ResetConfig.txt file and save as UTF-8 (ResetConfig.xml)
If you'll notice I removed two lines from your DP1.txt to get ResetPartitions.txt

As I usually just copied the files over from WinPE drive
 

My Computer

System One

  • OS
    Windows 3.1 > Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Dell XPS 8700
    CPU
    I7
    Memory
    24 GB
Your edited Batch is the CalculateAndCreateWIMBootPartition.cmd from TechNet

You only need to pre-define the size of install.wim and winre.wim plus 50MB your the recovery partition...
I also prepare all my wimboot images with a product key and drivers..
As touch tablets (best known for using wimboot, because of drive size) require the drivers be integrated into winre.wim

Here is my batch for the process - requires adding Choice.exe to winpe
In my case it uses per-defined partitions and sizes - until you capture and create a custom.wim

Code:
@ECHO OFF
title WIMBOOT PARTITIONS
COLOR 17
Wpeutil updatebootinfo
for /f "tokens=2* delims=  " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
if %Firmware%==0x1 (
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.             INFORMATION!! THIS COMPUTER WAS BOOTED IN "BIOS MODE"
)
if %Firmware%==0x2 (
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.             INFORMATION!! THIS COMPUTER WAS BOOTED IN "UEFI MODE"
)
ECHO.
ECHO ===============================================================================
if %Firmware%==0x1 (
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.             INFORMATION!! THIS COMPUTER WAS BOOTED IN "BIOS MODE"
ECHO.
ECHO.                 WIMBOOT IS NOT SUPPORTED ON A BIOS BOOTED PC
ECHO.
ECHO ===============================================================================
PAUSE
GOTO :EOF
)
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.      IS THIS A WIMBOOT INSTALLATION WITH A KNOWN RECOVERY PARTITION SIZE
ECHO.
ECHO ===============================================================================
choice /c yn /n /m  "(Y)ES or (N)O"
IF %ERRORLEVEL%==1 GOTO :WIMKNOWN
IF %ERRORLEVEL%==2 GOTO :WIMUNKNOWN
:WIMUNKNOWN
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.              (A) CREATE A "UEFI_GPT_WIMBOOT" PARTITION STRUCTURE
ECHO.
ECHO.              (B) APPLY A WIMBOOT IMAGE TO THE WINDOWS PARTITION
ECHO.
ECHO.              (C) CAPTURE THE WINDOWS CUSTOMIZATIONS INTO A CUSTOM.WIM
ECHO.
ECHO.              (D) CALCULATE AND CREATE THE WIMBOOT RECOVERY PARTITION
ECHO.
ECHO.              (X) EXIT THIS WIMBOOT PARTITION AND SETUP
ECHO. 
ECHO ===============================================================================
choice /c ABCDX /n /m  "PLEASE ENTER YOUR SELECTION"
IF %ERRORLEVEL%==1 GOTO :WIMPART
IF %ERRORLEVEL%==2 GOTO :WIMAPPLY
IF %ERRORLEVEL%==3 GOTO :WIMCUSTOM
IF %ERRORLEVEL%==4 GOTO :WIMCALC
IF %ERRORLEVEL%==5 GOTO :EOF
:WIMKNOWN
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.            CREATING THE PARTITIONS AND APPLYING THE WIMBOOT IMAGES 
ECHO.
ECHO ===============================================================================
Diskpart /s %~dp0\scripts\wim\create4partitions.txt
md "M:\Windows Images\"
md W:\Recycler\Scratch
md M:\Recovery\WindowsRE
copy %~dp0\Images\Install-WIMBoot.wim "M:\Windows Images\Install.wim"
copy %~dp0\Images\WinRE-WIMBoot.wim M:\Recovery\WindowsRE\WinRE.wim /h
dism /Apply-Image /ImageFile:"M:\Windows Images\install.wim" /ApplyDir:W: /Index:1 /WIMBoot /ScratchDir:W:\Recycler\Scratch
W:\Windows\System32\bcdboot W:\Windows
W:\Windows\System32\Reagentc /SetREImage /Path M:\Recovery\WindowsRE /Target W:\Windows
rd w:\Recycler /s /q
GOTO :END
:WIMPART
CLS
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.               CREATING A "UEFI_WIMBOOT_GPT" PARTITION STRUCTURE 
ECHO.
ECHO ===============================================================================
Diskpart /s %~dp0\scripts\wim\create3partitions.txt
ECHO ===============================================================================
ECHO.
ECHO.         YOU CAN NOW APPLY THE WIMBOOT IMAGE TO THE WINDOWS PARTITION 
ECHO.
ECHO.                   PRESS ANY KEY TO RETURN TO WIMBOOT MENU
ECHO ===============================================================================
PAUSE
GOTO :WIMUNKNOWN
:WIMAPPLY
CLS
IF NOT EXIST %~dp0\images\*.wim (GOTO :NOMEDIA) ELSE (
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.            APPLYING THE WIMBOOT IMAGE TO THE WINDOWS PARTITION 
ECHO.
ECHO ===============================================================================
)
Diskpart /s %~dp0\scripts\wim\assignletter.txt
md W:\Recycler\WIMs\Recovery
md W:\Recycler\Scratch
xcopy %~dp0\Images\install_wimboot.wim W:\Recycler\WIMs\install.wim
xcopy %~dp0\Images\winre_wimboot.wim W:\Recycler\WIMs\recovery\winre.wim /h
dism /Apply-Image /ImageFile:W:\Recycler\WIMs\install.wim /ApplyDir:W: /Index:1 /WIMBoot /ScratchDir:W:\Recycler\Scratch
W:\Windows\System32\bcdboot W:\Windows
ECHO ===============================================================================
ECHO.
ECHO.     YOU CAN NOW REBOOT, CUSTOMIZE AND CLEAN UP YOUR WINDOWS INSTALLATION 
ECHO.
ECHO.     WHEN YOUR DONE, YOU CAN CAPTURE YOUR CUSTOMIZATIONS INTO A CUSTOM.WIM
ECHO.
ECHO.                              PRESS ANY KEY TO QUIT
ECHO ===============================================================================
PAUSE
GOTO :END
:WIMCUSTOM
CLS
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.             CAPTURING THE CUSTOMIZATIONS INTO A CUSTOM.WIM IMAGE 
ECHO.
ECHO ===============================================================================
Diskpart /s %~dp0\scripts\wim\assignletter.txt
md W:\Recycler\Scratch
dism /Capture-CustomImage /CaptureDir:W: /ScratchDir:W:\Recycler\Scratch
ECHO ===============================================================================
ECHO.
ECHO.        YOU CAN NOW CALCULATE AND CREATE THE WIMBOOT RECOVERY PARTITION 
ECHO.
ECHO.                    PRESS ANY KEY TO RETURN TO WIMBOOT MENU
ECHO ===============================================================================
PAUSE
GOTO :WIMUNKNOWN
:WIMCALC
CLS
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.            CALCULATING AND CREATING THE WIMBOOT RECOVERY PARTITION 
ECHO.
ECHO ===============================================================================
Diskpart /s %~dp0\scripts\wim\assignletter.txt
CALL %~dp0\scripts\wim\CalculateAndCreateWIMBootPartition.cmd W: W:\Recycler\WIMs\ W:\Recycler\WIMs\Recovery 0
rd W:\Recycler /s /q
ECHO ===============================================================================
ECHO.
ECHO.      YOUR ALL DONE, REBOOT INTO WINDOWS AND REMOVE THE "RECYCLER" FOLDER 
ECHO.
ECHO.                              PRESS ANY KEY TO QUIT
ECHO ===============================================================================
PAUSE
GOTO :END
:END
CLS
ECHO.
ECHO ===============================================================================
ECHO.
ECHO.                        WHAT WOULD YOU LIKE TO DO NOW?
ECHO.
ECHO ===============================================================================
choice /c cmrs /n /m  "(C)OMMAND PROMPT, (M)AIN MENU, (R)EBOOT, OR (S)HUTDOWN"
IF %ERRORLEVEL%==1 GOTO :EOF
IF %ERRORLEVEL%==2 GOTO :MENU
IF %ERRORLEVEL%==3 Wpeutil reboot
IF %ERRORLEVEL%==4 Wpeutil shutdown

ImagePrep Batch
Code:
@echo off
color 17
title IMAGE PREP - Version 16.02.19
setlocal EnableDelayedExpansion
set /a count=0
%windir%\system32\reg.exe query "HKU\S-1-5-19" >nul 2>&1 || (
echo.
echo ===============================================================================
echo.                     ADMINISTRATOR PRIVILEGES NOT DETECTED
echo.
echo.        RIGHT CLICK ON THIS SCRIPT AND SELECT 'RUN AS AN ADMINISTRATOR'
echo.
echo ===============================================================================
echo. Press Any Key To Exit..
pause >nul
goto :eof
)
if exist "%~dp0bin\dism\dism.exe" (set "dism=%~dp0bin\dism\dism.exe"
%windir%\system32\reg.exe query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE | find /i "amd64" 1>nul && set "dism=%~dp0bin\DISMx64\dism.exe"
) else (set dism=%systemroot%\system32\dism.exe)
for %%I in (D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist "%%I:\\sources\install.wim" set setupdrv=%%I
if defined setupdrv (
echo.
echo ===============================================================================
echo.  AN INSTALL.WIM WAS FOUND IN DRIVE %setupdrv%:\SOURCES
echo ===============================================================================
) else (
echo.
echo ===============================================================================
echo  No installation media found!
echo  Insert DVD or USB flash drive and run this file once again. 
echo ===============================================================================
echo. Press Any Key To Exit..
pause >nul
goto :eof
)
echo.
echo ===============================================================================
echo.  TYPE A COMPUTER NAME FOR THE PREPARED IMAGE FOLDER
echo ===============================================================================
set /p folder= ^> Enter Computer Name:
echo.
echo ===============================================================================
echo.  ENTER THE PRODUCT ACTIVATION KEY - INCLUDING DASHES
echo.
echo.  JUST LEAVE BLANK ^> TO SKIP PRODUCT ACTIVATION KEY 
echo ===============================================================================
set /p productkey= ^> Enter Your Key:
if exist "%~dp0drivers" goto :check
cls
set userinp=
echo.
echo ===============================================================================
echo.  EXPORT 3RD PARTY SYSTEM DRIVERS FROM THIS HOST PC?
echo.
echo.  Press 0 - DO NOT EXPORT ANY SYSTEM DRIVERS FROM THIS PC
echo.  Press 1 - EXPORT DRIVERS FROM THE ON-LINE WINDOWS SYSTEM 
echo.  Press 2 - EXPORT DRIVERS FROM AN OFF-LINE WINDOWS IMAGE
echo ===============================================================================                  
set /p userinp= ^> Enter Your Option:
set userinp=%userinp:~0,3%
if %userinp%==0 goto :check
if %userinp%==1 (
echo.
echo ===============================================================================
echo.  EXPORTING DRIVERS FROM THE ON-LINE WINDOWS SYSTEM 
echo ===============================================================================
md "%~dp0Drivers"
%dism% /online /Export-Driver /Destination:"%~dp0drivers"
)
if %userinp%==2 (
echo.
echo ===============================================================================
echo.  PLEASE ENTER THE DRIVE LETTER TO THE OFF-LINE WINDOWS IMAGE
echo ===============================================================================
set /p drvlttr= ^> Enter Drive Letter:
echo.
echo ===============================================================================
echo.  EXPORTING DRIVERS FROM THE OFF-LINE WINDOWS IMAGE
echo ===============================================================================
md "%~dp0Drivers"
%dism% /Image:%drvlttr%:\ /Export-Driver /Destination:"%~dp0drivers"
)
:check
if not exist "%~dp0bin\wimlib-imagex.exe" set _index=1&goto :start
set wimfile=%setupdrv%:\sources\install.wim
%~dp0bin\wimlib-imagex.exe info "%wimfile%" 1>nul 2>nul
for /f "tokens=3 delims=: " %%i in ('%~dp0bin\wimlib-imagex.exe info "%wimfile%" ^| findstr /c:"Image Count"') do set images=%%i
for /L %%i in (1, 1, %images%) do call :setcount %%i
echo %wimfile%| findstr /E /I "\.wim" >nul && goto :indexcount
exit
:setcount
set /a count+=1
for /f "tokens=1* delims=: " %%i in ('%~dp0bin\wimlib-imagex.exe info "%wimfile%" %1 ^| findstr /b /c:"Name"') do set name%count%="%%j"
goto :eof
:indexcount
set _index=
if "%images%"=="1" set _index=1&goto :start
echo ===============================================================================
echo.                   The Install.wim contains %images% indexes:
echo.
for /L %%i in (1, 1, %images%) do (
echo.  %%i. !name%%i!
)
echo.
echo ===============================================================================
echo.                    Enter Desired Index Number To Use
echo ===============================================================================
set /p _index= ^> 
if [%_index%]==[] goto :indexcount
if %_index% GTR %images% echo.&echo Selected Index Number is Higher than available indexes&echo.&pause&goto :indexcount
:start
cls
echo.
echo ===============================================================================
echo.  EXPORTING THE SOURCE INSTALL.WIM FOR PROCESSING
echo.  Please Wait.. This will take several minutes..
echo ===============================================================================
md "%~dp0Source"
md "%~dp0Mount"
%dism% /Export-Image /SourceImageFile:%setupdrv%:\sources\install.wim /SourceIndex:%_index% /DestinationImageFile:"%~dp0Source\install.wim" /CheckIntegrity
%dism% /Mount-Image /ImageFile:"%~dp0Source\install.wim" /Index:1 /MountDir:"%~dp0Mount" /CheckIntegrity
echo.
echo ===============================================================================
echo.  ENABLE FEATURE .NET FRAMEWORK 3.5
echo ===============================================================================
%dism% /Image:"%~dp0Mount" /Enable-Feature /FeatureName:NetFx3 /All /Source:%setupdrv%:\sources\sxs /LimitAccess
if not exist "%~dp0drivers\" goto :activekey
cls
set userinp=
echo.
echo ===============================================================================
echo.  WOULD YOU LIKE TO ADD 3RD PARTY DRIVERS TO THE INSTALL.WIM?
echo.
echo.  Press 1 - YES - ADD DRIVERS TO INSTALL.WIM
echo.  Press 2 - NO -- DO NOT ADD DRIVERS TO INSTALL.WIM
echo ===============================================================================                  
set /p userinp= ^> Enter Your Option:
set userinp=%userinp:~0,3%
if %userinp%==2 goto :winre 
if %userinp%==1 (
echo.
echo ===============================================================================
echo.  ADDING THE SYSTEM DRIVERS TO THE WINDOWS INSTALL.WIM 
echo ===============================================================================
%dism% /Image:"%~dp0Mount" /Add-Driver /Driver:"%~dp0drivers" /Recurse
)
:winre
cls
set userinp=
echo.
echo ===============================================================================
echo.  WOULD YOU LIKE TO ADD DRIVERS TO THE WINRE.WIM?
echo.
echo.  Press 1 - YES - ADD DRIVERS TO WINRE.WIM
echo.  Press 2 - NO -- DO NOT ADD DRIVERS TO WINRE.WIM
echo ===============================================================================                  
set /p userinp= ^> Enter Your Option:
set userinp=%userinp:~0,3%
if %userinp%==2 goto :activekey
if %userinp%==1 (
echo.
echo ===============================================================================
echo.  ADDING THE SYSTEM DRIVERS TO THE WINDOWS WINRE.WIM 
echo ===============================================================================
attrib.exe -a -r -s -h "%~dp0Mount\Windows\System32\Recovery\winre.wim"
move "%~dp0Mount\Windows\system32\recovery\winre.wim" "%~dp0Source\Winre.wim"
md "%~dp0MountRE"
%dism% /Mount-Image /ImageFile:"%~dp0Source\Winre.wim" /index:1 /MountDir:"%~dp0MountRE" /CheckIntegrity
%dism% /Image:"%~dp0MountRE" /Add-Driver /Driver:"%~dp0Drivers" /Recurse
%dism% /Unmount-Image /MountDir:"%~dp0MountRE" /Commit
rmdir /s /q "%~dp0MountRE"
)
:activekey
cls
set userinp=
echo.
echo ===============================================================================
echo.  WOULD YOU LIKE TO SET A PRODUCT ACTIVATION KEY FOR THE INSTALL.WIM?
echo.
echo.  Press 1 - YES - ADD PRODUCT ACTIVATION KEY TO INSTALL.WIM
echo.  Press 2 - NO -- SKIP THE PRODUCT ACTIVATION KEY
echo ===============================================================================                  
set /p userinp= ^> Enter Your Option:
set userinp=%userinp:~0,3%
if %userinp%==2 goto :deployprep
if %userinp%==1 (
echo.
echo ===============================================================================
echo.  RESETTING THE PRODUCT KEY TO %PRODUCTKEY%
echo ===============================================================================
%dism% /Image:"%~dp0Mount" /Set-productKey:%productkey%
)
:deployprep
cls
set userinp=
echo.
echo ===============================================================================
echo.  PREPARE THE INSTALL.WIM FOR WINDOWS 8.1 WIMBOOT DEPLOYMENT?
echo.
echo.  Press 1 - PREPARE INSTALL.WIM FOR WINDOWS 8.1 WIMBOOT DEPLOYMENT 
echo.  Press 2 - DO NOT PREPARE INSTALL.WIM FOR WINDOWS 8.1 WIMBOOT DEPLOYMENT
echo ===============================================================================                  
set /p userinp= ^> Enter Your Option:
set userinp=%userinp:~0,3%
if %userinp%==1 goto :wimboot
if %userinp%==2 goto :finalize
:finalize
cls
echo.
echo ===============================================================================
echo.  PROCESSING THE FINAL STEPS FOR THE STANDARD INSTALL.WIM 
echo ===============================================================================
md "%~dp0%Folder%"
if exist "%~dp0Source\winre.wim" (%dism% /Export-Image /SourceImageFile:"%~dp0Source\winre.wim" /SourceIndex:1 /DestinationImageFile:"%~dp0Mount\windows\system32\recovery\winre.wim" /CheckIntegrity)
%dism% /Unmount-Image /MountDir:"%~dp0Mount" /Commit
%dism% /Export-Image /SourceImageFile:"%~dp0Source\install.wim" /SourceIndex:1 /DestinationImageFile:"%~dp0%folder%\Install.wim" /CheckIntegrity
goto :apply
:wimboot
cls
echo.
echo ===============================================================================
echo.  PROCESSING THE FINAL STEPS FOR WINDOWS 8.1 WIMBOOT DEPLOYMENT
echo ===============================================================================
md "%~dp0%Folder%"
if exist "%~dp0Source\winre.wim" (
%dism% /Export-Image /SourceImageFile:"%~dp0Source\winre.wim" /SourceIndex:1 /DestinationImageFile:"%~dp0%folder%\Winre.wim" /CheckIntegrity
) else (
attrib.exe -a -r -s -h "%~dp0Mount\Windows\System32\Recovery\winre.wim"
move "%~dp0Mount\Windows\system32\recovery\winre.wim" "%~dp0%folder%\Winre.wim"
)
%dism% /Optimize-Image /Image:"%~dp0Mount" /WIMBoot
%dism% /Unmount-Image /MountDir:"%~dp0Mount" /Commit
%dism% /Export-Image /WimBoot /SourceImageFile:"%~dp0Source\install.wim" /SourceIndex:1 /DestinationImageFile:"%~dp0%folder%\Install.wim" /CheckIntegrity
goto :done
:apply
cls
set _wimfile="%~dp0%folder%\Install.wim"
set _ltr=
echo ===============================================================================
echo   Enter the Drive Letter to Apply the Image to, ie. ^( F: ^)
echo   Make sure the drive is valid, properly formatted and ready to use
echo.
echo   Hit Enter To Bypass - Applying The Image File
echo ===============================================================================
echo.
set /p _ltr= ^> 
if [%_ltr%]==[] goto :done
echo %_ltr%| findstr /B /E /I "[D-Z]:" >NUL
if errorlevel 1 (echo.&echo ERROR: Destination needs to be a drive letter, e.g F:&echo.&pause&goto :apply)
if not exist "%_ltr%" (echo.&echo ERROR: Destination drive %_ltr% does not exist&echo.&pause&goto :apply)
echo.
echo ===============================================================================
echo   Applying Image file to drive %_ltr%
echo ===============================================================================
echo.
%Dism% /Apply-Image /ImageFile:"%_wimfile%" /Index:1 /ApplyDir:%_ltr%
:done
if exist "%~dp0Source" rmdir /s /q "%~dp0Source"
if exist "%~dp0Mount" rmdir /s /q "%~dp0Mount"
cls
echo.
echo ===============================================================================
echo.  THE PREPARED IMAGE FILES ARE IN - %~dp0%folder%
echo ===============================================================================
echo.
echo.   IMAGE_PREP.CMD
echo.   WRITTEN BY KYHI
echo.   FEBRUARY 19, 2016
echo.
echo.   ENJOY!!
echo.
echo ===============================================================================
timeout /t 5 >nul
exit
 

My Computer

System One

  • OS
    Windows 3.1 > Windows 10
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Dell XPS 8700
    CPU
    I7
    Memory
    24 GB
Back
Top