@echo off
CLS
COLOR 0F
TITLE Rev:1.16.14393.910
set FLASH_BIOS=0
set OnlySingleOS=0
set /a DefinedCSize=0
set DefinedCName=
set CreateDriveD=0
set DefinedDName=UserData
set OneKeyRecovery=1
set OneKeyRecParName=Recovery
set OneKeyRecPath=EFI\Recovery
set OneKeyRecGUID=
set OneKeyRecParSize=
set OneKeyRecLetter=R
set ErrorInfo=Unknown
@echo *****************************************************************
@echo Map drive letter for inside eMMC/SATA
@echo *****************************************************************
@echo.>x:\Disks.txt
@echo list disk >>x:\Disks.txt
@echo exit >>x:\Disks.txt
call diskpart /s x:\Disks.txt>x:\listdisk.txt
if %errorlevel% NEQ 0 set ErrorInfo="Fail to list disk" && goto :Error
for /f "skip=1 tokens=2" %%i in ('type x:\listdisk.txt ^| find "Disk"') do (
@echo select disk %%i >x:\DetailDisk.txt
@echo detail disk >>x:\DetailDisk.txt
@echo exit >>x:\DetailDisk.txt
diskpart /s x:\DetailDisk.txt>x:\DiskInfo.txt
for /f "tokens=3" %%a in ('type x:\DiskInfo.txt ^| find "Type :"') do (
@echo Disk type:%%a
@rem map eMMC disk and first use it
if "%%a"=="SD" (
set Disk=%%i
@rem Exclude MicroSD card
type x:\DiskInfo.txt | find /i "removable" || goto :ShowDisk
type x:\DiskInfo.txt | find /i "sd card" || goto :ShowDisk
)
@rem map ssd disk
if "%%a"=="SATA" set Disk=%%i
)
)
:ShowDisk
set Disk
if %Errorlevel% NEQ 0 set ErrorInfo="NOT found inside disk!" && goto :Error
@echo Using Disk "%Disk%"
@echo.
set WinPEArch=%PROCESSOR_ARCHITECTURE%
if defined WDSSource (
set WinPESource=%WDSSource%
set InstallPath=%WDSImagePath%
) else (
@echo *****************************************************************
@echo Map drive letter for USBKey
@echo *****************************************************************
for /f "tokens=1-2" %%i in ('wmic logicaldisk where "DriveType=2" get DeviceID ^| find ":" ') do (
if exist %%i\BaseOS set WinPESource=%%i
if exist %%i\images set WinPESource=%%i
if exist %%i\images\Public\%WinPEArch%\*.wim set InstallPath=%%i\images\Public\%WinPEArch%
if exist %%i\images\Public\%WinPEArch%\*.swm set InstallPath=%%i\images\Public\%WinPEArch%
if exist %%i\BaseOS\*.wim set SourceImage=TRUE && set InstallPath=%%i\BaseOS
if exist %%i\BaseOS\*.swm set SourceImage=TRUE && set InstallPath=%%i\BaseOS
if exist %%i\images\*.wim set SourceImage=&& set InstallPath=%%i\images
if exist %%i\images\*.swm set SourceImage=&& set InstallPath=%%i\images
)
)
set WinPESource
set InstallPath
if %Errorlevel% NEQ 0 set ErrorInfo="Not found *.wim or *.swm files in BaseOS or images folder" && goto :Error
if defined SourceImage (
@echo *****************************************************************
@echo Map Install.wim or modify.wim from %InstallPath%
@echo *****************************************************************
if exist %InstallPath%\Install.wim set TARGET_IMAGE=Install.wim
if exist %InstallPath%\Install.swm set TARGET_IMAGE=Install.swm && set swmFileX=%InstallPath%\*.swm
if exist %InstallPath%\Modify.wim set TARGET_IMAGE=Modify.wim && set IsModifiedImage=True
if exist %InstallPath%\Modify.swm set TARGET_IMAGE=Modify.swm && set IsModifiedImage=True && set swmFileX=%InstallPath%\*.swm
if not defined TARGET_IMAGE set ErrorInfo="Not found Install.wim(or modify.wim) in %InstallPath%" && goto :error
set RE_FILE=NO
set /a RE_FILE_SIZE=0
goto :GetTargetImageVersion
)
@echo *****************************************************************
@echo Map Winre.wim and *.wim or *.swm from %InstallPath%
@echo *****************************************************************
setlocal enabledelayedexpansion
cd /d %InstallPath%
for /f "delims=" %%i in ('dir /a-d /b') do (
if /i "%%~xi"==".wim" (
if /i "%%~ni"=="winre" (
set TARGET_RE=%%i
set TARGET_RE_SIZE=%%~zi
) else (
set /a wimCount+=1
set TARGET_WIM=%%i
set TARGET_WIM_SIZE=%%~zi
)
if !wimCount!==2 set ErrorInfo="More than 2 *.wim files in %InstallPath%" && goto :error
)
if /i "%%~xi"==".swm" (
set /a swmCount+=1
if !swmCount!==1 set SWM_FILE=%%i
if !swmCount!==2 set SWM_COUNT=OK
)
)
if defined TARGET_RE (
set RE_FILE=%TARGET_RE%
set RE_FILE_SIZE=%TARGET_RE_SIZE:~0,-6%
) else (
set RE_FILE=NO
set /a RE_FILE_SIZE=0
)
if defined TARGET_WIM (
set TARGET_IMAGE=%TARGET_WIM%
set TARGET_IMAGE_SIZE=%TARGET_WIM_SIZE:~0,-6%
) else (
if not defined SWM_FILE set ErrorInfo="Not found valid install.wim or install.swm files in %InstallPath%" && goto :error
if not defined SWM_COUNT set ErrorInfo="SWM file less than 2 in %InstallPath%" && goto :error
set TARGET_IMAGE=%SWM_FILE%
set swmFileX=%InstallPath%\*.swm
)
@echo TargetImageRE:%RE_FILE%
goto :GetTargetImageVersion
:GetTargetImageVersion
@echo TargetImageOS:%TARGET_IMAGE%
Powershell Get-WindowsImage -ImagePath "%InstallPath%\%TARGET_IMAGE%" -index 1 >x:\TargetImageInfo.txt
TYPE x:\TargetImageInfo.txt | find "10.0.14">nul || (
TYPE x:\TargetImageInfo.txt | find "10.0.10">nul || (
TYPE x:\TargetImageInfo.txt | find "6.3.9600">nul || (
set ErrorInfo="Unknown image version!"
goto :error
)
set WIMBOOTOS=Win8.1
set StrArg=/WIMBoot
if %RE_FILE%==NO set ErrorInfo="Not found Winre.wim in %InstallPath%" && goto :error
if defined swmFileX set ErrorInfo="*.swm files don't support Win8.1" && goto :error
set /a RECOVERY_SIZE=%TARGET_IMAGE_SIZE%+%RE_FILE_SIZE%+50
goto :CheckupOS
)
set WINTHXOS=Win10
set StrArg=/Compact
if %RE_FILE_SIZE% LSS 430 set /a RECOVERY_SIZE=480
if %RE_FILE_SIZE% GEQ 430 (
if %RE_FILE_SIZE% LSS 680 set /a RECOVERY_SIZE=%RE_FILE_SIZE%+320
if %RE_FILE_SIZE% GEQ 680 set /a RECOVERY_SIZE=%RE_FILE_SIZE%+1024
)
goto :CheckupOS
)
set WINRS1OS=WinRS1
set StrArg=/Compact /EA
if %RE_FILE_SIZE% LSS 430 set /a RECOVERY_SIZE=480
if %RE_FILE_SIZE% GEQ 430 (
if %RE_FILE_SIZE% LSS 680 set /a RECOVERY_SIZE=%RE_FILE_SIZE%+320
if %RE_FILE_SIZE% GEQ 680 set /a RECOVERY_SIZE=%RE_FILE_SIZE%+1024
)
goto :CheckupOS
:CheckupOS
set /a AndroidParsCount=0
@echo TargetImageVersion:%WIMBOOTOS%%WINTHXOS%%WINRS1OS%
if not defined SourceImage @echo TargetImagePBRSize:%RECOVERY_SIZE%
if /i %WinPEArch%==amd64 set WinPEArch=x64
TYPE x:\TargetImageInfo.txt | find "%WinPEArch%">nul || (
set ErrorInfo="Current WinPE_%WinPEArch% and %TARGET_IMAGE% don't match"
goto :Error
)
if defined SourceImage goto :CreateDiskPartition
@echo *****************************************************************
@echo Checkup SingleOS or DualOS or whether exist windows partiton
@echo *****************************************************************
@rem Get all partitions from inside disk
@echo.>x:\eMMCDisk.txt
@echo select disk %Disk% >>x:\eMMCDisk.txt
@echo list partition >>x:\eMMCDisk.txt
@echo exit >>x:\eMMCDisk.txt
diskpart /s x:\eMMCDisk.txt>x:\eMMCPartitions.txt
if %ERRORLEVEL% NEQ 0 set ErrorInfo="Fail to list inside disk Partitions" && goto :Error
find "Partition 7" x:\eMMCPartitions.txt >nul
if %ERRORLEVEL% NEQ 0 (
@echo SingleOS
set MyOS=Win_SingleOS
goto :CreateDiskPartition
)
@rem IF only install single os ,check the switch
if %OnlySingleOS%==1 (
@echo SingleOS
set MyOS=Win_SingleOS
goto :CreateDiskPartition
)
set MyOS=Win_DualOS
@echo DualOS
@rem Checkup windows partitions and delete them
for /f "tokens=2,3" %%i in ('type x:\eMMCPartitions.txt ^| find "Partition"') do (
@echo.>x:\windowsPartitions.txt
@echo select disk %Disk% >>x:\windowsPartitions.txt
@echo select Partition %%i >>x:\windowsPartitions.txt
@rem Checkup windows MSR partition which not exist volumes, delete them
if "%%j" == "Reserved" (
@echo delete Partition override >>x:\windowsPartitions.txt
) else (
@echo detail partition >>x:\windowsPartitions.txt
)
@echo exit >> x:\windowsPartitions.txt
diskpart /s x:\windowsPartitions.txt>x:\PartitionDetails.txt
if %ERRORLEVEL% NEQ 0 set ErrorInfo="Fail to detail windows partitions" && goto :Error
type x:\PartitionDetails.txt | find "* Volume" >x:\VolPro.txt
for /f "tokens=3" %%b in ('type x:\VolPro.txt ^| find /v "ESP" ^| find /v "RAW" ^| find /v "ANDROIDIA" ^| find /v "ANDROID"') do (
@echo.>x:\DeletedPartitions.txt
@echo select disk %Disk% >>x:\DeletedPartitions.txt
@echo select partition %%i >>x:\DeletedPartitions.txt
@echo delete Partition override >>x:\DeletedPartitions.txt
@echo exit >>x:\DeletedPartitions.txt
diskpart /s x:\DeletedPartitions.txt>nul
@echo Delete windows partition:%%i
)
)
@rem Get android partitions
for /f "tokens=1" %%i in ('wmic diskdrive where "Index=%Disk%" get Partitions /value ^| find "Partitions="') do @set aCount=%%i
set /a AndroidParsCount=%aCount:~11,-1%
@echo AndroidParsCount:%AndroidParsCount%
@echo.
@rem Hide the android volume
@echo.>x:\eMMCDisk.txt
@echo select disk %Disk% >>x:\eMMCDisk.txt
@echo list volume >>x:\eMMCDisk.txt
@echo exit >>x:\eMMCDisk.txt
diskpart /s x:\eMMCDisk.txt>x:\AndroidVolumes.txt
if %ERRORLEVEL% NEQ 0 set ErrorInfo="Fail to list android volumes" && goto :Error
@echo.>x:\HideAndroidVol.txt
@echo select disk %Disk% >>x:\HideAndroidVol.txt
for /f "tokens=2" %%i in ('type x:\AndroidVolumes.txt ^| find "RAW"') do (
@echo Select Volume %%i >>x:\HideAndroidVol.txt
@echo attributes volume set hidden >>x:\HideAndroidVol.txt
)
@echo exit >>x:\HideAndroidVol.txt
diskpart /s x:\HideAndroidVol.txt>nul
if %ERRORLEVEL% NEQ 0 set ErrorInfo="Fail to Hide android volumes" && goto :Error
goto :CreateDiskPartition
:CreateDiskPartition
for /f "tokens=1" %%i in ('wmic bios get Version /value ^| find "Version="') do @set BIOSVendor=%%i
set BIOSVendor=%BIOSVendor:~8,-1%
set BIOSVendor
if /i "%BIOSVendor%"=="INSYDE" set INSYDEBIOS=TRUE
if /i "%BIOSVendor%"=="ALASK" set AMIBIOS=TRUE
@echo *****************************************************************
@echo Create disk partition table
@echo *****************************************************************
if not defined SourceImage goto :CreateReleaseImagePartion
for /f "tokens=2* delims= " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') do @set Firmware=%%B
if %Firmware%==0×1 set LegacyMode=Yes
if %Firmware%==0×2 set UEFImode=Yes
@echo.>x:\winpart.txt
@echo select disk %Disk% >>x:\winpart.txt
@echo clean >>x:\winpart.txt
if defined UEFImode @echo convert gpt >>x:\winpart.txt
@echo create partition efi size=100 >>x:\winpart.txt
if defined LegacyMode @echo active >>x:\winpart.txt
@echo format quick fs=fat32 label="System" >>x:\winpart.txt
@echo assign letter="S" >>x:\winpart.txt
if defined UEFImode @echo create partition msr size=16 >>x:\winpart.txt
@echo create partition primary >>x:\winpart.txt
@echo format quick fs=ntfs label="Windows" >>x:\winpart.txt
@echo assign letter="W" >>x:\winpart.txt
@echo list volume >>x:\winpart.txt
@echo exit >>x:\winpart.txt
diskpart /s x:\winpart.txt
if %ERRORLEVEL% NEQ 0 set ErrorInfo="Fail to create disk partition table" && goto :Error
@echo.
goto :ApplyImageToDisk
:CreateReleaseImagePartion
set /a MySystemParSize=1024 * %DefinedCSize%
@echo.>x:\winpart.txt
@echo select disk %Disk% >>x:\winpart.txt
if %MyOS%==Win_SingleOS (
@echo clean >>x:\winpart.txt
@echo convert gpt >>x:\winpart.txt
)
if defined INSYDEBIOS (
@rem Only set the value:12->android5.1,7->singleOS
if %AndroidParsCount% LSS 7 (
@echo create partition efi size=100 >>x:\winpart.txt
@echo format quick fs=fat32 label="System" >>x:\winpart.txt
@echo assign letter="S" >>x:\winpart.txt
)
) else (
@echo create partition efi size=100 >>x:\winpart.txt
@echo format quick fs=fat32 label="System" >>x:\winpart.txt
@echo assign letter="S" >>x:\winpart.txt
)
if defined WIMBOOTOS @echo create partition msr size=128 >>x:\winpart.txt
if not defined WIMBOOTOS @echo create partition msr size=16 >>x:\winpart.txt
REM Create OEM partitions
if %OneKeyRecovery%==1 (
if defined OneKeyRecGUID (
if defined OneKeyRecParSize @echo create partition primary size=%OneKeyRecParSize% >>x:\winpart.txt
if not defined OneKeyRecParSize @echo create partition primary size=200 >>x:\winpart.txt
if defined OneKeyRecParName @echo format quick fs=ntfs label="%OneKeyRecParName%" >>x:\winpart.txt
if not defined OneKeyRecParName @echo format quick fs=fat32 label="OneKeyRec" >>x:\winpart.txt
@echo gpt attributes=0×8000000000000001 >>x:\winpart.txt
@echo set id="%OneKeyRecGUID%" >>x:\winpart.txt
@echo assign letter="%OneKeyRecLetter%" >>x:\winpart.txt
)
)
if %MySystemParSize%==0 (
@echo create partition primary >>x:\winpart.txt
@echo shrink minimum=%RECOVERY_SIZE% >>x:\winpart.txt
if defined DefinedCName @echo format quick fs=ntfs label="%DefinedCName%" >>x:\winpart.txt
if not defined DefinedCName @echo format quick fs=ntfs >>x:\winpart.txt
@echo assign letter="W" >>x:\winpart.txt
@echo create partition primary >>x:\winpart.txt
) else (
@echo create partition primary size=%MySystemParSize% >>x:\winpart.txt
if defined DefinedCName @echo format quick fs=ntfs label="%DefinedCName%" >>x:\winpart.txt
if not defined DefinedCName @echo format quick fs=ntfs >>x:\winpart.txt
@echo assign letter="W" >>x:\winpart.txt
if %CreateDriveD%==1 (
@echo create partition primary >>x:\winpart.txt
@echo shrink minimum=%RECOVERY_SIZE% >>x:\winpart.txt
if defined DefinedDName @echo format quick fs=ntfs label="%DefinedDName%" >>x:\winpart.txt
if not defined DefinedDName @echo format quick fs=ntfs >>x:\winpart.txt
@echo assign letter="U" >>x:\winpart.txt
@echo create partition primary >>x:\winpart.txt
) else (
@echo create partition primary size=%RECOVERY_SIZE% >>x:\winpart.txt
)
)
if not defined OneKeyRecParName @echo format quick fs=ntfs label="Recovery" >>x:\winpart.txt
if defined OneKeyRecGUID (
@echo format quick fs=ntfs label="Recovery" >>x:\winpart.txt
) else (
if defined OneKeyRecParName @echo format quick fs=ntfs label="%OneKeyRecParName%" >>x:\winpart.txt
)
@echo assign letter="R" >>x:\winpart.txt
@echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac" >>x:\winpart.txt
@echo gpt attributes=0×8000000000000001 >>x:\winpart.txt
@echo list volume >>x:\winpart.txt
@echo exit >>x:\winpart.txt
diskpart /s x:\winpart.txt
if %ERRORLEVEL% NEQ 0 set ErrorInfo="Fail to create disk partition table" && goto :Error
@echo.
goto :ApplyImageToDisk
:ApplyImageToDisk
@echo *****************************************************************
@echo Create temporary folders on EMMC partition
@echo *****************************************************************
@echo md w:\recycler
md w:\recycler
if %errorlevel% NEQ 0 set ErrorInfo="Failed to make w:\recycler directory" && goto :Error
@REM Apply source image
if defined SourceImage (
@echo *****************************************************************
@echo Applying source image from %InstallPath%
@echo *****************************************************************
if not defined swmFileX (
@echo DISM /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /ApplyDir:w:\ /Index:1 /ScratchDir:w:\recycler
%DISM% /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /ApplyDir:w:\ /Index:1 /ScratchDir:w:\recycler
)
if defined swmFileX (
@echo DISM /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /SWMFile:"%swmFileX%" /ApplyDir:w:\ /Index:1 /ScratchDir:w:\recycler
%DISM% /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /SWMFile:"%swmFileX%" /ApplyDir:w:\ /Index:1 /ScratchDir:w:\recycler
)
if %errorlevel% NEQ 0 set ErrorInfo="Fail to apply source image to w:\" && goto :error
goto :SettingEnvironment
)
@REM Apply release image
@echo md R:\recovery\windowsre
md R:\recovery\windowsre
if %errorlevel% NEQ 0 set ErrorInfo="Failed to make R:\recovery\windowsre directory" && goto :Error
@echo.
if defined WIMBOOTOS (
@echo R:\"windows images"
md R:\"windows images"
if %errorlevel% NEQ 0 set ErrorInfo="Failed to make R:\windows images directory" && goto :error
@echo.
@echo *****************************************************************
@echo Backup Install.wim and Winre.wim to R:\
@echo *****************************************************************
@rem xcopy winre.wim
@echo Please waiting …
xcopy %InstallPath%\winre.wim R:\recovery\windowsre /fy
if %errorlevel% NEQ 0 set ErrorInfo="Failed to copy winre.wim to R:\recovery\windowsre" && goto :error
@echo.
rem xcopy install.wim
@echo Please waiting …
echo f|xcopy %InstallPath%\%TARGET_IMAGE% R:\"windows images\install.wim" /fy
if %errorlevel% NEQ 0 set ErrorInfo="Failed to copy install.wim to R:\Windows images" && goto :error
@echo.
@echo *****************************************************************
@echo Applying the WIMboot image from R:\
@echo *****************************************************************
@echo DISM /Apply-Image /ImageFile:"R:\windows images\install.wim" /ApplyDir:w: /Index:1 %StrArg% /ScratchDir:w:\recycler
%DISM% /Apply-Image /ImageFile:"R:\windows images\install.wim" /ApplyDir:w: /Index:1 %StrArg% /ScratchDir:w:\recycler
if %errorlevel% NEQ 0 set ErrorInfo="Failed to apply image to w:" && goto :error
)
if not defined WIMBOOTOS (
@echo *****************************************************************
@echo Applying the image from %InstallPath%
@echo *****************************************************************
if not defined swmFileX (
@echo DISM /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /ApplyDir:w:\ /Index:1 %StrArg% /ScratchDir:w:\recycler
%DISM% /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /ApplyDir:w:\ /Index:1 %StrArg% /ScratchDir:w:\recycler
)
if defined swmFileX (
@echo DISM /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /SWMFile:"%swmFileX%" /ApplyDir:w:\ /Index:1 %StrArg% /ScratchDir:w:\recycler
%DISM% /Apply-Image /ImageFile:"%InstallPath%\%TARGET_IMAGE%" /SWMFile:"%swmFileX%" /ApplyDir:w:\ /Index:1 %StrArg% /ScratchDir:w:\recycler
)
if %errorlevel% NEQ 0 set ErrorInfo="Failed to apply image to w:" && goto :error
@echo.
@rem xcopy winre.wim
@echo *****************************************************************
@echo Backup Winre.wim to R:\recovery\windowsre
@echo *****************************************************************
IF EXIST %InstallPath%\Winre.wim (
@echo Please waiting …
xcopy %InstallPath%\Winre.wim r:\recovery\windowsre /fy
if %errorlevel% NEQ 0 set ErrorInfo="Failed to copy %InstallPath%\winre.wim to r:\recovery\windowsre" && goto :error
)
IF NOT EXIST %InstallPath%\winre.wim (
@echo move w:\Windows\System32\recovery\winre.wim r:\recovery\windowsre
move w:\Windows\System32\recovery\winre.wim r:\recovery\windowsre
if %errorlevel% NEQ 0 set ErrorInfo="Failed to move w:\Windows\System32\recovery\winre.wim to r:\recovery\windowsre" && goto :error
)
)
@echo.
goto :SettingEnvironment
:SettingEnvironment
@echo *****************************************************************
@echo Setting the boot environment
@echo *****************************************************************
if defined INSYDEBIOS (
@rem Android4.4=15partitions,Android5.1=11partitions
if %AndroidParsCount% LSS 7 set BootArgs=W:\WINDOWS /s S: /f all
if %AndroidParsCount% GTR 10 set ShareESP=TRUE && set BootArgs=W:\WINDOWS
)
if not defined INSYDEBIOS set BootArgs=W:\WINDOWS /s S: /f all
@echo call W:\WINDOWS\SYSTEM32\BCDBOOT %BootArgs%
W:\WINDOWS\SYSTEM32\BCDBOOT %BootArgs%
if %errorlevel% NEQ 0 set ErrorInfo="Failed to set BOOT_Environment" && goto :error
if defined SourceImage goto :UpdateFiles
@echo.
@echo *****************************************************************
@echo Setting the recovery environment
@echo *****************************************************************
@echo call W:\WINDOWS\SYSTEM32\REAGENTC /SetREImage /Path R:\recovery\windowsre /target w:\windows
W:\WINDOWS\SYSTEM32\REAGENTC /SetREImage /Path R:\recovery\windowsre /target w:\windows
if %errorlevel% NEQ 0 set ErrorInfo="Failed to set RECOVERY_Environment" && goto :error
set zipTool=7z_%PROCESSOR_ARCHITECTURE%.exe
set zipToolPath="%WinpeSource%\Scripts\%zipTool%"
if not exist %zipToolPath% set zipToolPath="X:\Windows\System32\%zipTool%"
if %OneKeyRecovery%==0 goto :SingleInstance
if %OneKeyRecovery%==1 goto :SettingOneKeyRecoveryEnvironment
:SettingOneKeyRecoveryEnvironment
@echo *****************************************************************
@echo Setting the oneKey recovery environment
@echo *****************************************************************
set BootFile=Boot32.zip
if exist "W:\Program Files (x86)" set BootFile=Boot64.zip
set bootFilePath="%WinpeSource%\Scripts\%BootFile%"
if not exist %bootFilePath% set bootFilePath="X:\Windows\System32\%BootFile%"
if defined OneKeyRecGUID (
REM Create recovery path
@echo md %OneKeyRecLetter%:\%OneKeyRecPath%
md "%OneKeyRecLetter%:\%OneKeyRecPath%"
if %errorlevel% NEQ 0 set ErrorInfo="Failed to make %OneKeyRecLetter%:\%OneKeyRecPath% directory" && goto :error
REM Use Bootxx.zip
@echo Extract %BootFile% to %OneKeyRecLetter%:\%OneKeyRecPath%
%zipToolPath% x %bootFilePath% -o"%OneKeyRecLetter%:\%OneKeyRecPath%\"
if %errorlevel% NEQ 0 set ErrorInfo="Fail to Extract %BootFile% to %OneKeyRecLetter%:\%OneKeyRecPath%" && goto :error
REM create bcd file
set BCDFILE="%OneKeyRecLetter%:\%OneKeyRecPath%\Boot\BCD"
) else (
@echo md S:\%OneKeyRecPath%
mkdir S:\%OneKeyRecPath%
xcopy /e /h S:\EFI\Microsoft\* S:\%OneKeyRecPath%
set BCDFILE="S:\%OneKeyRecPath%\Boot\BCD"
set BCDLOGFILE="S:\%OneKeyRecPath%\Boot\BCD.LOG"
)
if exist %BCDFILE% del %BCDFILE% /f /q
if exist %BCDFILE% del %BCDLOGFILE% /f /q
bcdedit /createstore %BCDFILE%
if %errorlevel% NEQ 0 set ErrorInfo="ERROR0:create BCD file" && goto :error
bcdedit /store %BCDFILE% /create {bootmgr} /d "Windows Boot Manager"
if %errorlevel% NEQ 0 set ErrorInfo="ERROR1:create BCD file" && goto :error
if defined OneKeyRecGUID bcdedit /store %BCDFILE% /set {bootmgr} device partition=%OneKeyRecLetter%:
if not defined OneKeyRecGUID bcdedit /store %BCDFILE% /set {bootmgr} device partition=S:
bcdedit /store %BCDFILE% /set {bootmgr} locale en-US
bcdedit /store %BCDFILE% /set {bootmgr} integrityservices Enable
bcdedit /store %BCDFILE% /create {11111111-1111-1111-1111-111111111111} /d "Windows OneKey Recovery" /device
bcdedit /store %BCDFILE% /set {11111111-1111-1111-1111-111111111111} ramdisksdidevice partition=R:
bcdedit /store %BCDFILE% /set {11111111-1111-1111-1111-111111111111} ramdisksdipath \Recovery\windowsre\boot.sdi
if %errorlevel% NEQ 0 echo ErrorInfo="ERROR2:set ramdisk boot path" && goto :error
bcdedit /store %BCDFILE% /create {22222222-2222-2222-2222-222222222222} /d "Windows Recovery Environment" /application osloader
bcdedit /store %BCDFILE% /set {bootmgr} default {22222222-2222-2222-2222-222222222222}
bcdedit /store %BCDFILE% /set {bootmgr} displayorder {22222222-2222-2222-2222-222222222222}
bcdedit /store %BCDFILE% /set {default} device ramdisk=[R:]\recovery\windowsre\winre.wim,{11111111-1111-1111-1111-111111111111}
bcdedit /store %BCDFILE% /set {default} path \Windows\System32\winload.efi
bcdedit /store %BCDFILE% /set {default} locale en-US
bcdedit /store %BCDFILE% /set {default} displaymessage "Recovery"
bcdedit /store %BCDFILE% /set {default} osdevice ramdisk=[R:]\recovery\windowsre\winre.wim,{11111111-1111-1111-1111-111111111111}
bcdedit /store %BCDFILE% /set {default} systemroot \Windows
bcdedit /store %BCDFILE% /set {default} nx OptIn
bcdedit /store %BCDFILE% /set {default} bootmenupolicy Standard
bcdedit /store %BCDFILE% /set {default} winpe Yes
if not exist %BCDFILE% set ErrorInfo="Fail to create BCD file" && goto :error
@echo.
goto :SingleInstance
:SingleInstance
@REM Just for CompactOS
setlocal enabledelayedexpansion
if defined WINTHXOS (
@echo *****************************************************************
@echo Backup ppkg files and apply SingleInstance
@echo *****************************************************************
IF EXIST %InstallPath%\*.ppkg (
@echo Please waiting…
xcopy %InstallPath%\*.ppkg w:\Recovery\Customizations /fy
)
IF EXIST w:\Recovery\Customizations\usmt.ppkg (
@echo DISM /Apply-CustomDataImage /ImagePath:w:\ /CustomDataImage:w:\Recovery\Customizations\usmt.ppkg /SingleInstance
%DISM% /Apply-CustomDataImage /ImagePath:w:\ /CustomDataImage:w:\Recovery\Customizations\usmt.ppkg /SingleInstance
)
)
if defined WINRS1OS (
@echo *****************************************************************
@echo Backup spp files and apply SiloedPackages
@echo *****************************************************************
IF EXIST %InstallPath%\*.spp (
@echo Please waiting…
xcopy %InstallPath%\*.spp w:\Recovery\Customizations /fy
)
cd /d w:\Recovery\Customizations
for /f "delims=" %%i in ('dir /a-d /b *.spp ^| find /v "usmt"') do (
@echo DISM /Apply-SiloedPackage /ImagePath:w:\ /PackagePath:%%i
%DISM% /Apply-SiloedPackage /ImagePath:w:\ /PackagePath:%%i
)
)
@echo.
goto :UpdateFiles
:UpdateFiles
@echo *****************************************************************
@echo Copying over some files to eMMC
@echo *****************************************************************
if EXIST %WinPESource%\TEST_TOOL.zip set TESTTOOLPATH=%WinPESource%\TEST_TOOL.zip
if EXIST %WinPESource%\Scripts\TEST_TOOL.zip set TESTTOOLPATH=%WinPESource%\Scripts\TEST_TOOL.zip
if EXIST %InstallPath%\TEST_TOOL.zip set TESTTOOLPATH=%InstallPath%\TEST_TOOL.zip
if not defined SourceImage (
@REM ====================================
@REM This code just for release image
@REM ====================================
if EXIST %InstallPath%\Unattend_%WinPEArch%.xml (
xcopy %InstallPath%\Unattend_%WinPEArch%.xml w:\Windows\Panther\Unattend.xml /fy
)
if EXIST %InstallPath%\Audit\Unattend.xml (
xcopy %InstallPath%\Audit\Unattend.xml w:\Windows\Panther\ /fy
)
if EXIST %InstallPath%\DefaultLayouts.xml (
xcopy %InstallPath%\DefaultLayouts.xml w:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /fy
)
if EXIST %InstallPath%\LayoutModification.xml (
xcopy %InstallPath%\LayoutModification.xml w:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /fy
)
if EXIST %InstallPath%\Recovery\* (
xcopy %InstallPath%\Recovery\* w:\Recovery\OEM\ /efy
)
xcopy w:\Recovery\OEM\scripts\oobe\info\oobe.xml w:\Windows\System32\oobe\info\ /fy
if defined TESTTOOLPATH call "%zipToolPath%" x %TESTTOOLPATH% -oW:\
@echo.
@REM If you want to copy other files for release image,add below
@REM
@REM
if %FLASH_BIOS%==1 GOTO :FLASH_BIOS
goto :END
)
@REM ====================================
@REM Bleow code just for source image
@REM ====================================
@REM Factory folder
xcopy %WinPESource%\Scripts\Factory\*.* w:\Factory\ /cherkyi
if %errorlevel% NEQ 0 set ErrorInfo="Fail to copy Factory folder to w:\" && goto :error
@echo.
@REM Unattend.xml
if defined IsModifiedImage (
echo f|xcopy %WinPESource%\Scripts\Unattend_modify.xml w:\Windows\Panther\Unattend.xml /fy
if %errorlevel% NEQ 0 set ErrorInfo="Fail to copy Unattend_modify.xml to w:\Windows\Panther" && goto :error
goto :EOF
)
echo f|xcopy %WinPESource%\Scripts\Unattend_%WinPEArch%.xml w:\Windows\Panther\Unattend.xml /fy
if %errorlevel% NEQ 0 set ErrorInfo="Fail to copy Unattend_%WinPEArch%.xml to w:\Windows\Panther" && goto :error
@REM OemLogo.bmp
if exist "%WinPESource%\Scripts\oemlogo.bmp" (
xcopy "%WinPESource%\Scripts\oemlogo.bmp" w:\Windows\Panther\ /fy
)
@REM Wallpaper
if exist "%WinPESource%\Scripts\*.jpg" (
xcopy "%WinPESource%\Scripts\*.jpg" w:\Windows\web\wallpaper\ /fy
)
@REM Info
if exist "%WinPESource%\Info" (
xcopy "%WinPESource%\Info" w:\Windows\System32\oobe\info\ /ey
)
@REM Microsoft Signature
if exist "%WinPESource%\Scripts\MFG.cmd" (
xcopy "%WinPESource%\Scripts\MFG.cmd" w:\Windows\Panther\ /fy
reg load HKU\Signature w:\users\default\ntuser.dat
reg add "HKU\Signature\Console" /v ScreenColors /t REG_WORD /d 10 /f
reg unload HKU\Signature
)
if exist "%WinPESource%\Scripts\Signature" (
xcopy "%WinPESource%\Scripts\Signature" w:\Windows\web\wallpaper\Signature\ /fey
)
if exist "%WinPESource%\Scripts\Signature.theme" (
xcopy "%WinPESource%\Scripts\Signature.theme" w:\Windows\Resources\Themes\ /fy
)
if exist "%WinPESource%\Scripts\Windows Defender.lnk" (
xcopy "%WinPESource%\Scripts\Windows Defender.lnk" "w:\ProgramData\Microsoft\Windows\Start Menu\Programs\System Tools\" /fy
)
if EXIST "%WinPESource%\Scripts\Create USB Recovery.lnk" (
xcopy "%WinPESource%\Scripts\Create USB Recovery.lnk" "w:\ProgramData\Microsoft\Windows\Start Menu\Programs\System Tools\" /fy
)
@REM If you want to copy other public files for source image,add below
@REM
@REM
@REM Only for win8.1
@REM ====================================
@REM Copy office365 install files to w:\
if defined WIMBOOTOS (
@echo xcopy "%WinPESource%\Office365"\*.* w:\Office365\ /cherky
if exist "%WinPESource%\Office365" xcopy "%WinPESource%\Office365"\*.* w:\Office365\ /cherky
@echo.
@echo Get the image default infomation
DISM /image:w: /get-intl /English
goto :EOF
)
@REM Only for win10
@REM ====================================
@REM OEM folder
xcopy %WinpeSource%\Scripts\OEM\* w:\Recovery\OEM\ /ey
if %errorlevel% NEQ 0 set ErrorInfo="Fail to copy %WinpeSource%\Scripts\OEM\* w:\Recovery\OEM\" && goto :error
attrib +h w:\Recovery
@echo.
@REM Install officeMobile or copy office install files to w:\
if EXIST %WinPESource%\OfficeMobile\InstallOfficeMoblie.cmd (
@echo *****************************************************************
@echo Install Office Moblile
@echo *****************************************************************
if EXIST %WinPESource%\Scripts\OEM\Backup\LayoutModification.xml (
xcopy %WinPESource%\Scripts\OEM\Backup\LayoutModification.xml w:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /fy
if %errorlevel% NEQ 0 set ErrorInfo="Fail to copy LayoutModification.xml to w:\Users\Default\AppData\Local\Microsoft\Windows\Shell" && goto :error
)
@echo Found %WinPESource%\OfficeMobile\InstallOfficeMoblie.cmd,run it
call %WinPESource%\OfficeMobile\InstallOfficeMoblie.cmd
@echo.
) else if EXIST %WinPESource%\Office365 (
@echo *****************************************************************
@echo Copy Office365 to w:\Office365
@echo *****************************************************************
@echo xcopy "%WinPESource%\Office365"\*.* w:\Office365\ /cherky
if exist "%WinPESource%\Office365" xcopy "%WinPESource%\Office365"\*.* w:\Office365\ /cherky
@echo.
)
@REM Copy startlayout files
if EXIST %WinPESource%\Scripts\DefaultLayouts.xml (
xcopy %WinPESource%\Scripts\DefaultLayouts.xml w:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /fy
)
if EXIST %WinPESource%\Scripts\LayoutModification.xml (
xcopy %WinPESource%\Scripts\LayoutModification.xml w:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /fy
)
@REM Only for win10 Z8300 amd64
@REM ====================================
@rem Install CHT3 Base Drivers
if exist "%WinpeSource%\Drivers\CHT3\InstallCHTBaseDrivers.cmd" call "%WinpeSource%\Drivers\CHT3\InstallCHTBaseDrivers.cmd"
@echo.
@REM Just for win others
@REM ====================================
@REM If you want to copy other files for win10 source image,add below
@REM
@REM
@echo Get the image default information
DISM /image:w: /get-intl /English
goto :EOF
:FLASH_BIOS
@echo *****************************************************************
@echo Flash %BIOSVendor% bios
@echo *****************************************************************
@REM Flash Insyde bios : USBKey:\images\BIOS
if defined INSYDEBIOS (
if NOT EXIST %WinPESource%\Scripts\Tools\* set ErrorInfo="Not found flash BIOS tool:%WinPESource%\Scripts\Tools" && goto :error
if EXIST %InstallPath%\BIOS\*.bin (
xcopy %InstallPath%\BIOS\*.bin %WinPESource%\Scripts\Tools\ /fy
if %errorlevel% NEQ 0 set ErrorInfo="Failed to copy bios file" && goto :error
for /r "%WinPESource%\Scripts\Tools" %%i in (*.bin) do ( ren "%%i" "%%~ni.fd" )
set FWFileType=BIN
)
if not defined FWFileType (
if NOT EXIST %InstallPath%\BIOS\*.rom set ErrorInfo="No bios file:%InstallPath%\BIOS" && goto :error
xcopy %InstallPath%\BIOS\*.rom %WinPESource%\Scripts\Tools\ /fy
if %errorlevel% NEQ 0 set ErrorInfo="Failed to copy bios file" && goto :error
for /r "%WinPESource%\Scripts\Tools" %%i in (*.rom) do ( ren "%%i" "%%~ni.fd" )
)
if NOT EXIST %WinPESource%\Scripts\Tools\*.fd set ErrorInfo="Not found BIOS file:%WinPESource%\Scripts\Tools\*.fd" && goto :error
if /i "%WinPEArch%"=="x86" call %WinPESource%\Scripts\Tools\H2OFFT-W.exe
if /i "%WinPEArch%"=="x64" call %WinPESource%\Scripts\Tools\H2OFFT-Wx64.exe
del %WinPESource%\Scripts\Tools\*.fd /f /q
if %errorlevel% NEQ 0 set ErrorInfo="Failed to delete bios file" && goto :error
)
@REM Flash AMI bios : USBKey:\images\BIOS\flashbsn.cmd or USBKey:\BIOS\flashbsn.cmd
if defined AMIBIOS (
if exist %WinPESource%\BIOS\flashbsn.cmd (
cd /d %WinPESource%\BIOS
call flashbsn.cmd
cd \
goto :END
)
if exist %InstallPath%\BIOS\flashbsn.cmd (
cd /d %InstallPath%\BIOS
call flashbsn.cmd
cd \
goto :END
)
)
@echo.
goto :END
:ERROR
COLOR 4B
@echo.
@echo %ErrorInfo%
@echo.
goto :EOF
:END
if exist "w:\recycler" rmdir /s /q w:\recycler
if exist "w:\sources" rmdir /s /q w:\sources
if exist "w:\Logs" rmdir /s /q w:\Logs
if exist %WinpeSource%\lang.txt del %WinpeSource%\lang.txt
if exist %WinpeSource%\Output.txt del %WinpeSource%\Output.txt
if exist %WinpeSource%\BOOTEX.LOG del %WinpeSource%\BOOTEX.LOG
@echo.
@echo ****************************************************************
@echo Deployment image Completed !
@echo ****************************************************************
@rem Get finish time so we can evaluate total WinPE phase time.
call |time>x:\StopTime.txt
@echo.
@rem Now parse both files to display the Start and Finish Time
for /f "tokens=5" %%A in (x:\starttime.txt) do echo Script Start Time is %%A
for /f "tokens=5" %%A in (x:\stoptime.txt) do echo Script Stop Time is %%A
@echo.