Boot to WinPE and Capture Image - Guide & Script
This batch script guides you through booting into WinPE and capturing an image using sysprep. It modifies the BCD store to create a WinPE entry, configures the WinPE environment, and executes Sysprep for image capture.
Code Explanation:
@ECHO Boot To Winpe And Capture Image @ECHO. @ECHO Checking for Boot.wim IF NOT EXIST %SystemDrive%\Scanstate\Manufacturer\boot.wim ECHO boot.wim NOT found && GOTO Error @ECHO %SystemDrive%\Scanstate\Manufacturer\boot.wim located. @ECHO. @ECHO End sysprep Program @ECHO taskkill.exe /F /IM sysprep.exe taskkill.exe /F /IM sysprep.exe @ECHO. @ECHO Modify BCD Store... @ECHO bcdedit.exe /create {ramdiskoptions} /d 'WinPE' bcdedit.exe /create {ramdiskoptions} /d 'WinPE' @ECHO bcdedit.exe /set {ramdiskoptions} ramdisksdidevice partition=%SystemDrive% bcdedit.exe /set {ramdiskoptions} ramdisksdidevice partition=%SystemDrive% @ECHO bcdedit.exe /set {ramdiskoptions} ramdisksdipath \Scanstate\Manufacturer\boot.sdi bcdedit.exe /set {ramdiskoptions} ramdisksdipath \Scanstate\Manufacturer\boot.sdi @ECHO FOR /F "usebackq delims={} tokens=2" %%d IN (`bcdedit.exe /create /d "WinPE" /application osloader`) DO @set GUID={%%d} FOR /F "usebackq delims={} tokens=2" %%d IN (`bcdedit.exe /create /d "WinPE" /application osloader`) DO @set GUID={%%d} @ECHO bcdedit.exe /set %GUID% device ramdisk=[%SystemDrive%]\Scanstate\Manufacturer\boot.wim,{ramdiskoptions} bcdedit.exe /set %GUID% device ramdisk=[%SystemDrive%]\Scanstate\Manufacturer\boot.wim,{ramdiskoptions} @ECHO bcdedit.exe /set %GUID% path \Windows\System32\winload.efi bcdedit.exe /set %GUID% path \Windows\System32\winload.efi @ECHO bcdedit.exe /set %GUID% osdevice ramdisk=[%SystemDrive%]\Scanstate\Manufacturer\boot.wim,{ramdiskoptions} bcdedit.exe /set %GUID% osdevice ramdisk=[%SystemDrive%]\Scanstate\Manufacturer\boot.wim,{ramdiskoptions} @ECHO bcdedit.exe /set %GUID% systemroot \Windows bcdedit.exe /set %GUID% systemroot \Windows @ECHO bcdedit.exe /set %GUID% winpe yes bcdedit.exe /set %GUID% winpe yes @ECHO bcdedit.exe /set %GUID% detecthal yes bcdedit.exe /set %GUID% detecthal yes @ECHO bcdedit.exe /bootsequence %GUID% /addfirst bcdedit.exe /bootsequence %GUID% /addfirst @ECHO. @ECHO bcdedit.exe /enum %GUID% bcdedit.exe /enum %GUID% @ECHO. @ECHO Launch Sysprep /Generalize /Audit /Reboot @ECHO %SystemRoot%\System32\Sysprep\Sysprep.exe /Generalize /Audit /Reboot %SystemRoot%\System32\Sysprep\Sysprep.exe /Generalize /Audit /Reboot IF %ERRORLEVEL% NEQ 0 ECHO Sysprep failed. && GOTO Error @ECHO. EXIT
Steps:
- Check for boot.wim: The script first verifies the existence of the 'boot.wim' file, essential for booting into WinPE. It will report an error if the file is not found.
- Terminate sysprep.exe: The script gracefully ends any running sysprep.exe process to avoid conflicts.
- Modify BCD Store: The script manipulates the BCD (Boot Configuration Data) store to create a new entry for booting into WinPE.
- It creates a 'WinPE' entry and sets its RAM disk options.
- It defines the RAM disk device and path, pointing to the 'boot.wim' and 'boot.sdi' files.
- It creates an 'osloader' entry for WinPE and stores its GUID in the 'GUID' variable.
- It configures the WinPE entry's device, path, OS device, system root, WinPE, and detecthal settings.
- Finally, it adds the WinPE entry to the boot sequence.
- Launch Sysprep: After configuring the BCD store, the script launches Sysprep to prepare the system for image capture. It uses the
/Generalizeoption to generalize the system for deployment, the/Auditoption to enable auditing, and the/Rebootoption to reboot the system after Sysprep completes.
Note:
- This script is a basic guide and may need customization based on your specific environment and requirements. Ensure the paths to the 'boot.wim' and 'boot.sdi' files are correct.
- You can modify the script to customize the Sysprep options and add more settings.
- This script is intended for use by experienced users familiar with system administration and image capture processes. It is crucial to back up your data and understand the potential risks involved in modifying system files.
原文地址: https://www.cveoy.top/t/topic/bONr 著作权归作者所有。请勿转载和采集!