Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. @echo off
  2. @rem This script is called by x:WindowsSystem32Startnet.cmd - WinPE
  3. @echo.
  4. @echo.
  5. @echo.
  6. @echo.
  7. @echo Running Intel Optimization powercfg for improved imaging times
  8. @echo.
  9. @echo call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
  10. call powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
  11. @echo.
  12. @echo.
  13. @echo.
  14. @rem *****************************************************************
  15. @rem List all the disks, then search the volumes of each one to see
  16. @rem which disks may have "Winpe" in the label. We will ignore that
  17. @rem disk and use the first disk without the Winpe label that we find.
  18. @rem *****************************************************************
  19. @echo.>x:Listdisk.txt
  20. @echo list disk>>x:Listdisk.txt
  21. @echo exit>>x:Listdisk.txt
  22. @echo call diskpart /s x:Listdisk.txt
  23. call diskpart /s x:Listdisk.txt>x:Disks.txt
  24. @echo.
  25. @rem Set Disk equal to blank to start
  26. set disk=
  27. @echo.
  28. @rem
  29. @rem This line will write a diskpart script to select the disk and detail it's contents.
  30. @rem We use this output to find a disk that does NOT have Winpe as the volume label.
  31. @rem That disk will have the OS installed to it. This way you can exclude USB from diskpart.
  32. @rem
  33. @rem This works around the issue where the USB key is sometimes enumerated as disk 0 and the
  34. @rem SSD is disk 1.
  35. @rem
  36. for /f "skip=8 tokens=2" %%A in (x:Disks.txt) do (
  37. @echo sel disk %%A>x:Par.txt
  38. @echo det disk>>x:Par.txt
  39. @echo exit>>x:Par.txt
  40. if NOT "%%A"=="DiskPart..." call :ListPar %%A
  41. )
  42. if %Disk%=="" echo No disk found without a volume label of "Winpe"&& set disk=0
  43. @echo Using Disk "%Disk%"
  44. @echo.
  45. @echo *****************************************************************
  46. @rem Map drive letter for Install.wim and Winre.wim
  47. @echo *****************************************************************
  48. @rem Create an output file containing all the drive letters
  49. @echo.>x:listVol.txt
  50. @echo list volume>>x:listVol.txt
  51. @echo exit>>x:listVol.txt
  52. @echo call diskpart /s x:listVol.txt
  53. call diskpart /s x:Listdisk.txt>x:Output.txt
  54. @echo call diskpart /s x:listVol.txt>x:Output.txt
  55. diskpart /s x:listVol.txt>x:Output.txt
  56. @echo.
  57. @rem Go through each drive letter, looking for the imagesInstall.txt file
  58. for /f "skip=8 tokens=3" %%A in (x:Output.txt) do (
  59. if exist %%A:imagesinstall.txt set InstallPath=%%A:images&& echo "Found device with images folder and install.txt file"
  60. )
  61. @echo.
  62. @echo.
  63. @echo.
  64. @echo.
  65. @rem ************************
  66. @rem UEFI SECTION
  67. @rem ************************
  68. @echo The PC is booted in UEFI mode
  69. @echo.>x:winpart.txt
  70. @echo select disk "%Disk%">>x:winpart.txt
  71. @echo clean>>x:winpart.txt
  72. @echo convert gpt>>x:winpart.txt
  73. @echo create partition efi size=100>>x:winpart.txt
  74. @echo format quick fs=fat32 label="System">>x:winpart.txt
  75. @echo assign letter="S">>x:winpart.txt
  76. @echo create partition msr size=16>>x:winpart.txt
  77. @echo create partition primary>>x:winpart.txt
  78. @echo format quick fs=ntfs label="Windows">>x:winpart.txt
  79. @echo assign letter="W">>x:winpart.txt
  80. @echo shrink desired=450>>x:winpart.txt
  81. @echo create partition primary>>x:winpart.txt
  82. @echo format quick fs=ntfs label="Recovery">>x:winpart.txt
  83. @echo assign letter="R">>x:winpart.txt
  84. @echo set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac">>x:winpart.txt
  85. @echo gpt attributes=0x8000000000000001>>x:winpart.txt
  86. @echo exit>>x:WinPart.txt
  87. @echo Winpart.txt now contains.....
  88. @echo.
  89. type x:winpart.txt
  90. @echo.
  91. @echo.
  92. @echo *****************************************************************
  93. @echo Setting up the partition table
  94. @echo *****************************************************************
  95. @echo call diskpart /s x:winpart.txt
  96. diskpart /s x:winpart.txt
  97. @echo.
  98. @echo.
  99. @echo.
  100. @echo.
  101. @rem Check InstallPath was found and there are images in it.
  102. if NOT EXIST %InstallPath%Install.swm echo "Install.swm Hassen Test NOT found." && goto :Error
  103. @echo Install.swm FOUND at %InstallPath%install.swm
  104. @echo.
  105. @echo.
  106. @echo.
  107. @echo *****************************************************************
  108. @rem Switches to the USB disk
  109. @rem Create folders on local (eMMC) disk and copy files from USB disk
  110. @echo *****************************************************************
  111. @echo.
  112. @echo Making directories...
  113. md w:recyclerscratch
  114. if %errorlevel% NEQ 0 echo "Failed to make w:recyclerscratch directory" && goto :error
  115. @echo.
  116. md r:recoverywindowsre
  117. if %errorlevel% NEQ 0 echo "Failed to make m:recoverywindowsre directory" && goto :error
  118. @echo.
  119. @echo.
  120. @echo *****************************************************************
  121. @echo Applying the Windows image from the USB
  122. @echo *****************************************************************
  123. @echo call dism /apply-image /imagefile:"%InstallPath%Install.swm" /swmfile:"%InstallPath%install*.swm" /index:1 /applydir:w: /compact /scratchdir:"w:recyclerSCRATCH
  124. call dism /apply-image /imagefile:"%InstallPath%Install.swm" /swmfile:"%InstallPath%install*.swm" /index:1 /applydir:w: /compact /scratchdir:"w:recyclerSCRATCH
  125. if %errorlevel% NEQ 0 echo "Failed to apply image to w:" && goto :error
  126. call dism.exe /Apply-CustomDataImage /CustomDataImage:"w:RecoveryCustomizationsusmt.ppkg" /ImagePath:w: /SingleInstance
  127. if %errorlevel% NEQ 0 echo "Failed to apply image to w:" && goto :error
  128. @echo.
  129. @echo *****************************************************************
  130. @rem Move WinRE to Recovery Partition
  131. @echo *****************************************************************
  132. @echo.
  133. @echo copy %InstallPath%RecoveryWinre.wim" "r:recoverywindowsre
  134. copy "%InstallPath%RecoveryWinre.wim" "r:recoverywindowsre"
  135. if %errorlevel% NEQ 0 echo "Failed to copy winre.wim to r:recoverywindowsre" && goto :error
  136. @echo.
  137. @echo reset attributes now
  138. attrib r:RecoveryWindowsrewinre.wim +s +h +a +r
  139. @echo.
  140. @echo.
  141. @echo *****************************************************************
  142. @echo Setting the boot environment
  143. @echo *****************************************************************
  144. @echo call w:WINDOWSSYSTEM32BCDBOOT w:WINDOWS /s s: /f all
  145. w:WINDOWSSYSTEM32BCDBOOT w:WINDOWS /s s: /f all
  146. if %errorlevel% NEQ 0 echo "Failed to set boot information" && goto :error
  147. @echo.
  148. @echo.
  149. @echo.
  150. @echo *****************************************************************
  151. @echo Setting the recovery environment
  152. @echo *****************************************************************
  153. @echo %InstallPath%reagentcreagentc /SetREImage /Path "r:RECOVERYWINDOWSRE" /target w:windows
  154. %InstallPath%reagentcreagentc /SetREImage /Path "r:RECOVERYWINDOWSRE" /target w:windows
  155. if %errorlevel% NEQ 0 echo "Failed to set recovery information" && goto :error
  156. @echo.
  157. @echo.
  158. @echo.
  159. attrib +H +R W:Recovery
  160. rmdir /s /q w:recycler
  161. @echo *****************************************************************
  162. @echo WIMboot image deployment COMPLETE. Type EXIT from Command
  163. @echo Prompt to restart or turn off device.
  164. @echo *****************************************************************
  165. color 2f
  166. Goto :END
  167.  
  168. :ERROR
  169. @echo.
  170. @echo An error has been detected.
  171. color 4f
  172. @echo.
  173. goto :END
  174.  
  175. :ListPar
  176. @REM This section is to bring a disk number and use it to List Partitions
  177. @echo.
  178. set TempDisk=%1
  179. diskpart /s x:Par.txt>x:ParOutput.txt
  180. for /f "skip=24 tokens=3" %%A in (x:ParOutput.txt) do (
  181. if /i "%%A"=="no" set Disk=%TempDisk%
  182. )
  183. for /f "skip=26 tokens=4" %%A in (x:ParOutput.txt) do (
  184. if /i NOT "%%A"=="Winpe" set Disk=%TempDisk%
  185. )
  186. Goto :EOF
  187.  
  188. :END
  189. @rem
  190. @rem Get finish time so we can evaluate total WinPE phase time.
  191. @rem
  192. call |time>x:StopTime.txt
  193. @rem
  194. @rem Now parse both files to display the Start and Finish Time
  195. @rem
  196. @echo.
  197. @echo.
  198. for /f "tokens=5" %%A in (x:starttime.txt) do echo Script Start Time is %%A
  199. for /f "tokens=5" %%A in (x:stoptime.txt) do echo Script Stop Time is %%A
  200. @echo.`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement