@echo off
@rem This script is called by x:\Windows\System32\Startnet.cmd – WinPE
@echo.
@echo.
@echo.
@echo Running Intel Optimization powercfg for improved imaging times
@echo.
@echo call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
@echo.
@echo.
@rem
@rem This is the default product key being used:
@echo.
@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:\disk.txt
if %errorlevel% NEQ 0 set ErrorInfo="Failed to list disk" && goto :Error
for /f "skip=1 tokens=2" %%i in ('type x:\disk.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) else if /i "%%a"=="NVME" (set Disk=%%i)
)
)
:ShowDisk
@echo.
@echo.
@rem *****************************************************************
@rem Detect if System is booted into UEFI mode or Bios mode
@rem *****************************************************************
for /f "tokens=2* delims= " %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') do set Firmware=%%B
@echo.
if %Firmware%==0×1 goto :Biosmode
if %Firmware%==0×2 goto :UEFImode
Goto :END
:UEFImode
@echo.
@rem ************************
@rem UEFI SECTION
@rem ************************
@echo The PC is booted in UEFI mode
@echo.>x:\winpart.txt
@echo select disk "%Disk%">>x:\winpart.txt
@echo clean>>x:\winpart.txt
@echo convert gpt>>x:\winpart.txt
@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
@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 shrink desired=800>>x:\winpart.txt
echo create partition primary>>x:\winpart.txt
echo format quick fs=ntfs label="Recovery">>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 exit>>x:\WinPart.txt
Goto :WINPARTSECTION
:Biosmode
@rem ************************
@rem BIOS SECTION
@rem ************************
@echo The PC is booted in BIOS mode
@echo The PC is booted in BIOS mode>x:\Bios.txt
@echo.>x:\winpart.txt
@echo select disk "%Disk%">>x:\winpart.txt
@echo clean>>x:\winpart.txt
@echo create partition primary size=100>>x:\winpart.txt
@echo active>>x:\winpart.txt
@echo format quick fs=fat32 label="System">>x:\winpart.txt
@echo assign letter="S">>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 exit>>x:\winpart.txt
@echo.
:WINPARTSECTION
@echo Winpart.txt now contains…..
@echo.
type x:\winpart.txt
@echo.
@echo.
@echo *****************************************************************
@echo Setting up the partition table
@echo *****************************************************************
@echo call diskpart /s x:\winpart.txt
diskpart /s x:\winpart.txt
@echo.
@echo.
@echo *****************************************************************
@rem Map drive letter for Install.wim
@echo *****************************************************************
@echo.>x:\ListVol.txt
@echo List volume>>x:\ListVol.txt
@echo exit>>x:\ListVol.txt
@echo call diskpart /s x:\ListVol.txt
call diskpart /s x:\ListVol.txt>x:\Output.txt
@echo.
@echo.
@rem Go through each drive letter, looking for the images\Install.txt file
for /f "skip=8 tokens=3" %%A in (x:\Output.txt) do (
if exist %%A:\images\install.txt set InstallPath=%%A:\images&& echo "Found device with images folder and install.txt file"
)
@echo.
@echo.
@echo.
@echo Making directories…
md w:\recycler\scratch
if %errorlevel% NEQ 0 echo "Failed to make m:\recovery\windowsre directory" && goto :error
md r:\recovery\windowsre
if %errorlevel% NEQ 0 echo "Failed to make m:\recovery\windowsre directory" && goto :error
@echo.
@echo.
@echo *****************************************************************
@echo Applying the Windows image from the USB
@echo *****************************************************************
if exist %InstallPath%\Install.wim (
@echo call dism /Apply-image /imagefile:"%InstallPath%\install.wim" /ApplyDir:W:\ /Index:1 /ScratchDir:w:\recycler\SCRATCH
call dism /Apply-image /imagefile:"%InstallPath%\install.wim" /ApplyDir:W:\ /Index:1 /ScratchDir:w:\recycler\SCRATCH
) else (
@echo call dism /Apply-image /imagefile:"%InstallPath%\install.swm" /swmfile:"%InstallPath%\install*.swm" /ApplyDir:W:\ /Index:1 /ScratchDir:w:\recycler\SCRATCH
call dism /Apply-image /imagefile:"%InstallPath%\install.swm" /swmfile:"%InstallPath%\install*.swm" /ApplyDir:W:\ /Index:1 /ScratchDir:w:\recycler\SCRATCH
)
if %errorlevel% NEQ 0 echo "Failed to apply image to w:" && goto :error
@echo.
@echo *****************************************************************
@echo Rund SingleInstance
@echo *****************************************************************
@echo.
@echo if EXIST W:\Recovery\Customizations\USMT.PPKG dism /Apply-CustomDataImage /CustomDataImage:W:\Recovery\Customizations\USMT.PPKG /ImagePath:W:\ /SingleInstance
if EXIST W:\Recovery\Customizations\USMT.PPKG dism /Apply-CustomDataImage /CustomDataImage:W:\Recovery\Customizations\USMT.PPKG /ImagePath:W:\ /SingleInstance
if %errorlevel% NEQ 0 echo "Failed to apply ppkg w:\" && goto :error
@echo.
@echo.
@echo.
@echo *****************************************************************
@echo Add default product key
@echo *****************************************************************
@echo call DISM /Image:w: /Set-ProductKey:%productkey%
REM call DISM /Image:w: /Set-ProductKey:%productkey%
REM if %errorlevel% NEQ 0 echo "Failed to set productkey." && goto :error
@echo *****************************************************************
@rem Move WinRE to Recovery Partition
@echo *****************************************************************
@echo.
@echo Modifying attributes of winre.wim so we can move it.
attrib w:\Windows\System32\recovery\winre.wim -s -h -a -r
@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 echo "Failed to move winre.wim to r:\recovery\windowsre" && goto :error
@echo.
@echo reset attributes now
attrib r:\Recovery\Windowsre\winre.wim +s +h +a +r
@echo.
@echo.
@echo.
@echo.
@echo.
@echo.
@echo *****************************************************************
@echo Setting the boot environment
@echo *****************************************************************
@echo call w:\WINDOWS\SYSTEM32\BCDBOOT w:\WINDOWS /s s: /f all
w:\WINDOWS\SYSTEM32\BCDBOOT w:\WINDOWS /s s: /f all
if %errorlevel% NEQ 0 echo "Failed to set boot information" && goto :error
@echo.
@echo *****************************************************************
@echo Setting the recovery winre boot environment for BIOS trigger
@echo *****************************************************************
mkdir S:\EFI\Recovery
xcopy /e /h S:\EFI\Microsoft\* S:\EFI\Recovery\
del /a S:\EFI\Recovery\Boot\BCD
del /a S:\EFI\Recovery\Boot\BCD.LOG
bcdedit /createstore S:\BCD
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
bcdedit /store S:\BCD /create {bootmgr} /d "Windows Boot Manager"
bcdedit /store S:\BCD /set {bootmgr} device partition=S:
bcdedit /store S:\BCD /set {bootmgr} locale en-US
bcdedit /store S:\BCD /set {bootmgr} integrityservices Enable
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
bcdedit /store S:\BCD /create {11111111-1111-1111-1111-111111111111} /d "Windows Recovery" /device
bcdedit /store S:\BCD /set {11111111-1111-1111-1111-111111111111} ramdisksdidevice partition=R:
bcdedit /store S:\BCD /set {11111111-1111-1111-1111-111111111111} ramdisksdipath \Recovery\WindowsRE\boot.sdi
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
bcdedit /store S:\BCD /create {22222222-2222-2222-2222-222222222222} /d "Windows Recovery Environment" /application osloader
bcdedit /store S:\BCD /set {bootmgr} default {22222222-2222-2222-2222-222222222222}
bcdedit /store S:\BCD /set {bootmgr} displayorder {22222222-2222-2222-2222-222222222222}
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
bcdedit /store S:\BCD /set {default} device ramdisk=[R:]\Recovery\WindowsRE\winre.wim,{11111111-1111-1111-1111-111111111111}
bcdedit /store S:\BCD /set {default} path \Windows\System32\winload.efi
bcdedit /store S:\BCD /set {default} locale en-US
bcdedit /store S:\BCD /set {default} displaymessage "Recovery"
bcdedit /store S:\BCD /set {default} osdevice ramdisk=[R:]\Recovery\WindowsRE\winre.wim,{11111111-1111-1111-1111-111111111111}
bcdedit /store S:\BCD /set {default} systemroot \Windows
bcdedit /store S:\BCD /set {default} nx OptIn
bcdedit /store S:\BCD /set {default} bootmenupolicy Standard
bcdedit /store S:\BCD /set {default} winpe Yes
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
xcopy /h S:\BCD* S:\EFI\Recovery\Boot\
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
del /a S:\BCD*
if %errorlevel% NEQ 0 echo "Failed to set recovery information in efi" && goto :error
@echo.
@echo *****************************************************************
@echo Setting the recovery environment
@echo *****************************************************************
@echo 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 echo "Failed to set recovery information" && goto :error
@echo.
@echo.
@echo.
@echo *****************************************************************
@echo Copying over Unattend.xml to use on factory floor if it exists
@echo *****************************************************************
@echo if EXIST %WinPESource%Scripts\Unattend.xml xcopy %WinPESource%Scripts\Unattend.xml w:\Windows\Panther\ /y
if EXIST %WinPESource%Scripts\Unattend.xml xcopy %WinPESource%Scripts\Unattend.xml w:\Windows\Panther\ /y
if %errorlevel% NEQ 0 echo "Failed to copy answer file" && goto :error
@echo.
@echo *****************************************************************
@echo Copying over resetconfig.xml and assets, if they exist.
@echo *****************************************************************
@echo if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\Recovery\*.* w:\Recovery\ /e /H /y
if EXIST %WinPESource%Scripts\Recovery\OEM\resetconfig.xml xcopy %WinPESource%Scripts\Recovery\*.* w:\Recovery\ /e /H /y
if %errorlevel% NEQ 0 echo "Failed to xcopy %WinpeSource%Scripts\Recovery\OEM\ to w:\Recovery\OEM\" && goto :error
echo.
echo ********************************************************************
@echo Extracting Test_TOOL to the root of C:\
@echo.
@echo *******************************************************************
@echo if exist %WinPESource%TEST_TOOL.zip %WinPESource%Scripts\7z.exe x %WinPESource%TEST_TOOL.zip -ow:\ -y
@echo.
REM if exist %WinPESource%TEST_TOOL.zip %WinPESource%Scripts\7z.exe x %WinPESource%TEST_TOOL.zip -ow:\ -y
if exist %WinPESource%TEST_TOOL xcopy %WinPESource%TEST_TOOL w:\TEST_TOOL\ /e /y
if %errorlevel% NEQ 0 echo "Failed to Extract archive.zip with full path to C drive" && goto :error
@echo Copying over oobe to w:\windows\system32\oobe
@echo *******************************************************************
@echo if exist W:\Recovery\OEM\Backup\info xcopy W:\Recovery\OEM\Backup\info W:\Windows\System32\Oobe\Info\ /s /y
if exist W:\Recovery\OEM\Backup\info xcopy W:\Recovery\OEM\Backup\info W:\Windows\system32\oobe\info\ /s /y
if %errorlevel% NEQ 0 echo "Failed to Copy OOBE.xml" && goto :error
@echo if exist w:\Recovery\OEM\Backup\OEMbackground.jpg xcopy w:\Recovery\OEM\Backup\OEMbackground.jpg W:\Windows\Web\Wallpaper\ /y
if exist w:\Recovery\OEM\Backup\OEMbackground.jpg xcopy w:\Recovery\OEM\Backup\OEMbackground.jpg W:\Windows\Web\Wallpaper\ /y
if %errorlevel% NEQ 0 echo "Failed to Copy OEMbackground" && goto :error
@echo.
@echo if exist w:\Recovery\OEM\Backup\logo.bmp xcopy w:\Recovery\OEM\Backup\logo.bmp w:\windows\oem\ /y
if exist w:\Recovery\OEM\Backup\logo.bmp xcopy w:\Recovery\OEM\Backup\logo.bmp w:\windows\oem\ /y
if errorlevel 1 echo "Failed to Copy OEMlogo" && goto :error
@echo.
@echo *******************************************************************
@echo Copying over startlayout to tiles on Desktop
@echo *******************************************************************
@echo if exist W:\Recovery\OEM\Backup\LayoutModification.* xcopy W:\Recovery\OEM\Backup\LayoutModification.* W:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /y
if exist W:\Recovery\OEM\Backup\LayoutModification.* xcopy W:\Recovery\OEM\Backup\LayoutModification.* W:\Users\Default\AppData\Local\Microsoft\Windows\Shell\ /y
if %errorlevel% NEQ 0 echo "Failed to Copy layoutmodification.xml" && goto :error
@echo.
if exist w:\Recovery\OEM\Backup\csup.txt xcopy w:\Recovery\OEM\Backup\csup.txt w:\windows\ /y
if %errorlevel% NEQ 0 echo "Failed to copy csup.txt to w:\windows\" && goto :error
REM **********************************************************************
REM For Win11 go to Audituser Mode first and Stuck in Desktop
REM **********************************************************************
reg load HKLM\sft W:\windows\system32\config\software
for /f "tokens=7 delims=\" %%A in ('reg query "HKLM\sft\Microsoft\Windows NT\CurrentVersion\ProfileList"') do set id=%%A
reg delete "HKLM\sft\Microsoft\Windows NT\CurrentVersion\ProfileList\%id%" /f
reg unload HKLM\sft
attrib +H +R W:\Recovery
rmdir /s /q w:\recycler
@echo.
@echo.
@echo *****************************************************************
@echo Image deployment complete. Type EXIT from Command
@echo Prompt to restart or turn off device.
@echo *****************************************************************
goto :END
:ERROR
color 4
echo.
echo.
echo.
echo oooooooooooo .o. ooooo ooooo
echo `888' `8 .888. `888' `888'
echo 888 .8"888. 888 888
echo 888oooo8 .8' `888. 888 888
echo 888 " .88ooo8888. 888 888
echo 888 .8' `888. 888 888 o
echo o888o o88o o8888o o888o o888ooooood8
echo.
echo.
echo.
echo ========== PRESS ANY KEY TO RESTART ==========
@pause>nul
goto :FINISH
:ListPar
@REM This section is to bring a disk number and use it to List Partitions
@echo.
set TempDisk=%1
diskpart /s x:\Par.txt>x:\ParOutput.txt
for /f "skip=26 tokens=4" %%A in (x:\ParOutput.txt) do (
if /i NOT "%%A"=="Winpe" set Disk=%TempDisk%
)
Goto :EOF
:END
@rem
@rem Get finish time so we can evaluate total WinPE phase time.
@rem
call |time>x:\StopTime.txt
@rem
@rem Now parse both files to display the Start and Finish Time
@rem
@echo.
@echo.
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.
echo.
echo.
echo.
color 2f
echo SSPAPASPA PAS PASSPASSPA PASSPASSPA
echo PASSPAPASPASS PASSPASS PASSPASSPASSP PASSPASSPASSP
echo PASS PASS PASS PASS PASS PASS
echo PASS PASS PASS PASS PASS PASS
echo PASS PASS PASS PASS PASS PASS
echo PASSPAPASPASS PASS PASS PASSPASSPA PASSPASSPA
echo PASSPAPASPA PAASSPASPASSPA PASSPASSPASS PASSPASSPASS
echo PASS PASS PASS PASS PASS
echo PASS PASS PASS PASS PASS
echo PASS PASS PASS PASSPASSPASSP PASSPASSPASSP
echo PASS PASS PASS PASSPASSPA PASSPASSPA
echo **********************************************************************
echo ==========Press any key to tablet will shutdown ==========
echo.
echo Disconnect the USB drive from the reference device.
echo **********************************************************************
REM pause>nul
wpeutil Reboot
:FINISH
exit