Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

363 lines
7.1 KiB

  1. @echo off
  2. REM
  3. REM Builds WinPE images from a professional
  4. REM distribution CD
  5. REM
  6. REM
  7. REM Set required variables
  8. REM
  9. set X86PLATEXT=I386
  10. set IA64PLATEXT=IA64
  11. set PLATEXT=%X86PLATEXT%
  12. set SRCDIR=%1
  13. set DESTDIR=%2
  14. set SHOWUSG=no
  15. set IMAGENAME=
  16. set CREATEIMG=no
  17. set TAGPREFIX=win
  18. set ETFSBOOTSEC=etfsboot.com
  19. set SKIPWINSXS=yes
  20. set VERSION_CHECK=yes
  21. if "%SRCDIR%" == "" (
  22. set SHOWUSG=yes
  23. ) else if "%DESTDIR%" == "" (
  24. set SHOWUSG=yes
  25. ) else if "%SRCDIR%" == "/?" (
  26. set SHOWUSG=yes
  27. )
  28. if /i "%SHOWUSG%" == "yes" (
  29. goto :showusage
  30. )
  31. REM
  32. REM Parse the remaining optional arguments
  33. REM
  34. shift /1
  35. :parseargument
  36. shift
  37. set CURRENTARG=%1
  38. if "%CURRENTARG%" == "" (
  39. goto :donewithargs
  40. )
  41. if /i "%CURRENTARG%" == "/nosxs" (
  42. set SKIPWINSXS=yes
  43. goto :parseargument
  44. ) else if /i "%CURRENTARG%" == "/nover" (
  45. set VERSION_CHECK=no
  46. goto :parseargument
  47. ) else (
  48. set IMAGENAME=%CURRENTARG%
  49. set CREATEIMG=yes
  50. )
  51. :donewithargs
  52. REM
  53. REM echo SRCDIR=%SRCDIR%
  54. REM echo DESTDIR=%DESTDIR%
  55. REM echo SKIPWINSXS=%SKIPWINSXS%
  56. REM echo VERSION_CHECK=%VERSION_CHECK%
  57. REM echo IMAGENAME=%IMAGENAME%
  58. REM echo CREATEIMG=%CREATEIMG%
  59. REM
  60. REM
  61. REM Validate source directory
  62. REM
  63. if not EXIST %SRCDIR% (
  64. goto :showusage
  65. )
  66. set X86DIR=%SRCDIR%\I386
  67. set IA64DIR=%SRCDIR%\IA64
  68. if exist %IA64DIR% (
  69. set PLATEXT=IA64
  70. ) else if not exist %X86DIR% (
  71. goto :showusage
  72. )
  73. set WINPEOPTDIR=%CD%
  74. set WINPESRCDIR=%SRCDIR%\%PLATEXT%
  75. set WINPEDESTDIR=%DESTDIR%
  76. set OPTDIROK=yes
  77. set WINPEEXTRAFILE=%WINPEOPTDIR%\extra.inf
  78. if not exist %WINPEEXTRAFILE% (
  79. set OPTDIROK=no
  80. echo Cannot find %WINPEEXTRAFILE% file
  81. )
  82. REM
  83. REM Don't look for these files on IA64 bld machines
  84. REM
  85. if /i not "%_BuildArch%" == "ia64" (
  86. if not exist %WINPEOPTDIR%\oemmint.exe (
  87. set OPTDIROK=no
  88. echo Cannot find %WINPEOPTDIR%\oemmint.exe
  89. ) else if not exist %WINPEOPTDIR%\bldhives.exe (
  90. set OPTDIROK=no
  91. echo Cannot find %WINPEOPTDIR%\bldhives.exe
  92. )
  93. )
  94. if /i not "%OPTDIROK%" == "yes" (
  95. goto :missingoptdir
  96. )
  97. REM
  98. REM Change to optdir where we have the tools
  99. REM
  100. cd /d %WINPEOPTDIR%
  101. REM
  102. REM Make sure we have the correct version of the media
  103. REM
  104. if /i not "%VERSION_CHECK%" == "no" (
  105. echo Verifying media ...
  106. oemmint.exe /s:%SRCDIR% /#u:checkversion 2>1>nul
  107. if ERRORLEVEL 1 (
  108. echo.
  109. echo ERROR: Version mismatch, Please verify that you are using the
  110. echo correct version of Windows Professional CD to create WinPE image.
  111. echo.
  112. goto :end
  113. )
  114. )
  115. REM
  116. REM Copy over the setupreg.hiv
  117. REM
  118. echo Building hives ...
  119. copy %WINPESRCDIR%\setupreg.hiv 2>1>nul
  120. if ERRORLEVEL 1 (
  121. echo Failed to copy setupreg.hiv file from CD
  122. goto :end
  123. )
  124. REM
  125. REM Copy over the required registry hive files
  126. REM
  127. copy %WINPESRCDIR%\hive*.inf 2>1>nul
  128. if ERRORLEVEL 1 (
  129. echo Failed to copy registry hive INF files
  130. goto :end
  131. )
  132. REM
  133. REM Copy over the intl.inf
  134. REM
  135. copy %WINPESRCDIR%\intl.inf 2>1>nul
  136. if ERRORLEVEL 1 (
  137. echo Failed to copy intl.inf
  138. goto :end
  139. )
  140. REM
  141. REM Copy over the font.inf
  142. REM
  143. expand -r %WINPESRCDIR%\font.in_ %WINPEOPTDIR%\ 2>1>nul
  144. if ERRORLEVEL 1 (
  145. echo Failed to copy font.inf
  146. goto :end
  147. )
  148. REM
  149. REM Build the binary hives from INF files
  150. REM
  151. bldhives.exe .\config.inf 2>1>nul
  152. if ERRORLEVEL 1 (
  153. echo Failed to build hives from INF files
  154. goto :end
  155. )
  156. REM
  157. REM Start copying the required files
  158. REM
  159. echo Copying files ...
  160. rd %WINPEDESTDIR%\. /s /q 2>1>nul
  161. mkdir %WINPEDESTDIR%\%PLATEXT% 2>1>nul
  162. REM
  163. REM Copy the tag files from the root of the CD
  164. REM to the destination root first
  165. REM
  166. copy %SRCDIR%\%TAGPREFIX%* %WINPEDESTDIR% 2>1>nul
  167. REM
  168. REM Copy the bootfont.bin to root of the destination
  169. REM if one exists in i386 or IA64 directory
  170. REM
  171. if exist %SRCDIR%\%PLATEXT%\bootfont.bin (
  172. copy %SRCDIR%\%PLATEXT%\bootfont.bin %WINPEDESTDIR% 2>1>nul
  173. )
  174. REM
  175. REM Ok, now lets do the actual work
  176. REM echo srcdir=%SRCDIR% destdir=%winpedestdir% optdir=%winpeoptdir% extra=%winpeextrafile%
  177. REM
  178. oemmint.exe /v /s:%SRCDIR% /d:%WINPEDESTDIR%\%PLATEXT% /m:%WINPEOPTDIR% /e:%WINPEEXTRAFILE% 2>nul
  179. if ERRORLEVEL 1 (
  180. echo Failed to copy all the required files for WinPE
  181. ) else (
  182. echo Successfully created WinPE directory in %WINPEDESTDIR%
  183. )
  184. REM
  185. REM Copy the WinSxS directory also (for the time being)
  186. REM
  187. set WINSXSDIR=%WINDIR%\WinSxS
  188. if /i "%SKIPWINSXS%" == "no" (
  189. if exist %WINSXSDIR% (
  190. echo Copying WinSxS files ...
  191. mkdir %WINPEDESTDIR%\%PLATEXT%\WinSxS 2>1>nul
  192. xcopy %WINSXSDIR% %WINPEDESTDIR%\%PLATEXT%\WinSxS /s /e /h 2>1>nul
  193. if ERRORLEVEL 1 (
  194. echo Error in copying WinSxS directory to %WINPEDESTDIR%
  195. rd %WINPEDESTDIR%\%PLATEXT%\WinSxS /s /q 2>1>nul
  196. ) else (
  197. echo Successfully copied WinSxS directory to %WINPEDESTDIR%
  198. )
  199. attrib -s -h -r %WINPEDESTDIR%\%PLATEXT%\WinSxS
  200. attrib -s -h -r %WINPEDESTDIR%\%PLATEXT%\WinSxS\* /s
  201. ) else (
  202. echo Error in copying WinSxS directory to %WINPEDESTDIR%
  203. )
  204. )
  205. REM
  206. REM Copy some more required files
  207. REM
  208. copy %WINPEDESTDIR%\%PLATEXT%\winbom.ini %WINPEDESTDIR% 2>1>nul
  209. REM
  210. REM Check if we need to create a image
  211. REM
  212. if /i "%CREATEIMG%" == "no" (
  213. goto :end
  214. )
  215. echo Creating WinPE CD image ...
  216. REM
  217. REM Image the created install also
  218. REM
  219. set CDIMG_OPTS=-n
  220. if "%PLATEXT%" == "%X86PLATEXT%" (
  221. REM
  222. REM On X86 we need to user eftsboot.com
  223. REM
  224. set CDIMG_OPTS=%CDIMG_OPTS% -b%ETFSBOOTSEC%
  225. ) else (
  226. REM
  227. REM On ia64 we need to copy setupldr.efi to floppy
  228. REM and image it and user that as the boot image
  229. REM
  230. echo Copying setupldr.efi to A:\ ...
  231. copy %WINPEDESTDIR%\%PLATEXT%\setupldr.efi a:\ 2>1>nul
  232. if ERRORLEVEL 1 (
  233. echo Failed to copy setupldr.efi to floppy drive to create boot image
  234. goto :end
  235. )
  236. REM
  237. REM Image the floppy containing setupldr.efi
  238. REM
  239. echo Creating image of the floppy drive A:\ ...
  240. dskimage.exe a: efisys.bin 2>1>nul
  241. if not EXIST efisys.bin (
  242. echo Failed to image the floppy containing setupldr.efi for boot image.
  243. goto :end
  244. )
  245. set CDIMG_OPTS=%CDIMG_OPTS% -befisys.bin
  246. )
  247. REM
  248. REM Create the ISO image file now
  249. REM
  250. REM oscdimg.exe %CDIMG_OPTS% %WINPEDESTDIR% %IMAGENAME%
  251. REM
  252. echo Creating %IMAGENAME% image ...
  253. oscdimg.exe %CDIMG_OPTS% %WINPEDESTDIR% %IMAGENAME% 2>1>nul
  254. if ERRORLEVEL 1 (
  255. echo Failed to create the WinPE image in %IMAGENAME%
  256. goto :end
  257. ) else (
  258. echo Successfully created WinPE image in %IMAGENAME%
  259. )
  260. goto :end
  261. :missingoptdir
  262. echo Your current directory is not WinPE directory.
  263. echo Install the WinPE from OPK CD to a directory, then
  264. echo change to that directory and then execute this
  265. echo mkimg.cmd from that directory
  266. goto :end
  267. :showusage
  268. echo Usage: mkimg.cmd [/?] SourceDir DestinationDir [ImageName]
  269. echo.
  270. echo SourceDir - Drive letter to the Windows XP Professional CD-ROM
  271. echo or network path to a share pointing to the root of
  272. echo a Windows XP Professional CD-ROM.
  273. echo.
  274. echo DestinationDir - Path where WinPE directory would to created
  275. echo before creating a CD image.
  276. echo.
  277. echo ImageName - Optional parameter, specifies the file name which
  278. echo will contain the WinPE ISO CD image.
  279. echo.
  280. echo.
  281. echo Example : mkimg.cmd F: c:\winpe c:\winpecd.img
  282. echo.
  283. echo In this example, F: is the drive letter for the CD-ROM drive which
  284. echo contains Windows XP Professional CD-ROM. This example will create a
  285. echo directory called "c:\winpe" containing WinPE files. It will also create
  286. echo a file named "c:\winpecd.img" which can be used for creating a bootable
  287. echo WinPE CD.
  288. echo.
  289. :end
  290. if /i not "%_NTPOSTBLD%" == "" (
  291. seterror.exe %errorlevel%
  292. )